Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitignore
Empty file.
24 changes: 21 additions & 3 deletions edsdk-n1ed.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public function __construct()
$this->plugin_url = plugins_url('', __FILE__);
add_action('admin_menu', [$this, 'add_settings_page']);
add_filter('plugin_action_links', [$this, 'add_settings_link'], 10, 2);

add_filter(
'wp_editor_settings',
[$this, 'n1ed_replace_tinymce'],
10,
2
);
add_action(
'admin_enqueue_scripts',
[$this, 'edsdk_enqueue_editor'],
Expand Down Expand Up @@ -81,6 +86,21 @@ public function tiny_mce_plugins()
return [];
}

public function n1ed_replace_tinymce($settings, $editor_id)
{
if (
$editor_id === 'content' &&
(get_current_screen()->post_type === 'post' ||
get_current_screen()->post_type === 'page')
) {
$settings['tinymce'] = false;
$settings['quicktags'] = false;
$settings['media_buttons'] = false;
}

return $settings;
}

public function edsdk_enqueue_editor($hook)
{
global $post;
Expand All @@ -99,13 +119,11 @@ public function edsdk_enqueue_editor($hook)
$apiKey = 'N1WPDFLT';
update_option('n1edApiKey', $apiKey);
}
$defaultUploadDir = '/uploads/2021/02';

wp_localize_script('n1ed', 'n1ed_ajax_object', [
'apiKey' => $apiKey,
'token' => get_option('n1edToken'),
'urlFiles' => wp_upload_dir()['baseurl'],
'defaultUploadDir' => $defaultUploadDir,
]);
}
}
Expand Down
27 changes: 9 additions & 18 deletions js/n1edLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,12 @@ function includeJS(urlJS, doc, callback) {
}
}

document.querySelector(".wp-editor-tabs").style.display = "none";
document.querySelector("#wp-content-media-buttons").style.display = "none";
// document.querySelector(".wp-editor-tabs").style.display = "none";
// document.querySelector("#wp-content-media-buttons").style.display = "none";

var apiKey = n1ed_ajax_object.apiKey;
var token = n1ed_ajax_object.token;
var urlFiles = n1ed_ajax_object.urlFiles;
// var defaultUploadDir = n1ed_ajax_object.defaultUploadDir;
var defaultUploadDir = "/uploads/2021/02";

function deleteInclude() {
var id = tinymce.editors[0].id;
tinymce.get(id).remove();
delete window.tinymce;
includeJS(
"https://cloud.n1ed.com/cdn/" + apiKey + "/n1tinymce.js",
document,
function () {
waitForEditor(false, id);
}
);
}

function setupNow(editor_id) {
tinymce.init({
Expand Down Expand Up @@ -93,4 +78,10 @@ function waitForEditor(di, editor_id) {
}
}

waitForEditor(true, "");
includeJS(
"https://cloud.n1ed.com/cdn/" + apiKey + "/n1tinymce.js",
document,
function () {
waitForEditor(false, "content");
}
);