diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/edsdk-n1ed.php b/edsdk-n1ed.php index acc65e7..084a120 100644 --- a/edsdk-n1ed.php +++ b/edsdk-n1ed.php @@ -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'], @@ -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; @@ -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, ]); } } diff --git a/js/n1edLoader.js b/js/n1edLoader.js index 55465d4..e3fb289 100644 --- a/js/n1edLoader.js +++ b/js/n1edLoader.js @@ -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({ @@ -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"); + } +);