From c1e686831cce34e6f6c75cf6ae4c3449bbe9ef8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Mon, 27 May 2019 14:10:39 +0200 Subject: [PATCH] Unload WP editor loaded by another plugin [MAILPOET-2105] --- lib/Util/ConflictResolver.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/Util/ConflictResolver.php b/lib/Util/ConflictResolver.php index 9051a42333..0b4e8fe43e 100644 --- a/lib/Util/ConflictResolver.php +++ b/lib/Util/ConflictResolver.php @@ -51,6 +51,13 @@ class ConflictResolver { 'resolveScriptsConflict', ] ); + WPFunctions::get()->addAction( + 'mailpoet_conflict_resolver_scripts', + [ + $this, + 'resolveEditorConflict', + ] + ); } function resolveRouterUrlQueryParametersConflict() { @@ -117,4 +124,30 @@ class ConflictResolver { WPFunctions::get()->addAction('admin_print_scripts', $dequeue_scripts, $execute_first); WPFunctions::get()->addAction('admin_print_footer_scripts', $dequeue_scripts, $execute_first); } + + function resolveEditorConflict() { + + // mark editor as already enqueued to prevent loading its assets + // when wp_enqueue_editor() used by some other plugin + global $wp_actions; + $wp_actions['wp_enqueue_editor'] = 1; + + // prevent editor loading when used wp_editor() used by some other plugin + WPFunctions::get()->addFilter('wp_editor_settings', function () { + ob_start(); + return [ + 'tinymce' => false, + 'quicktags' => false, + ]; + }); + + WPFunctions::get()->addFilter('the_editor', function () { + return ''; + }); + + WPFunctions::get()->addFilter('the_editor_content', function () { + ob_end_clean(); + return ''; + }); + } }