diff --git a/src/admin/class-footnotes-admin.php b/src/admin/class-footnotes-admin.php index b242f39..174c1e3 100644 --- a/src/admin/class-footnotes-admin.php +++ b/src/admin/class-footnotes-admin.php @@ -36,6 +36,14 @@ class Footnotes_Admin { * @var string $version The current version of this plugin. */ private $version; + + /** + * The WYSIWYG editor integration object. + * + * @since 2.8.0 + * @var Footnotes_WYSIWYG $wysiwyg The WYSIWYG editor integration object. + */ + public $wysiwyg; /** * Initialize the class and set its properties. @@ -71,6 +79,8 @@ class Footnotes_Admin { */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-footnotes-wysiwyg.php'; + $this->wysiwyg = new Footnotes_WYSIWYG($this->plugin_name); + /** * The class responsible for constructing the plugin dashboard page(s). */ diff --git a/src/admin/class-footnotes-wysiwyg.php b/src/admin/class-footnotes-wysiwyg.php index 50b9643..0907759 100644 --- a/src/admin/class-footnotes-wysiwyg.php +++ b/src/admin/class-footnotes-wysiwyg.php @@ -16,33 +16,26 @@ class Footnotes_WYSIWYG { /** - * Registers Button hooks. + * The ID of this plugin. * - * @since 1.5.0 - * - * - Bugfix: Editor buttons: debug button by reverting name change in PHP file while JS file and HTML template remained unsynced, thanks to @gova bug report. - * - * @reporter @gova - * @link https://wordpress.org/support/topic/back-end-footnotes-not-working-400-bad-erro/ - * - * @since 2.6.5 - * @return void + * @since 2.8.0 + * @access private + * @var string $plugin_name The ID of this plugin. */ - public static function register_hooks() { - add_filter( 'mce_buttons', array( 'Footnotes_WYSIWYG', 'new_visual_editor_button' ) ); - add_action( 'admin_print_footer_scripts', array( 'Footnotes_WYSIWYG', 'new_plain_text_editor_button' ) ); + private $plugin_name; + + /** + * Initialize the class and set its properties. + * + * @since 2.8.0 + * @param string $plugin_name The name of this plugin. + */ + public function __construct( $plugin_name ) { - add_filter( 'mce_external_plugins', array( 'Footnotes_WYSIWYG', 'include_scripts' ) ); + $this->plugin_name = $plugin_name; - // phpcs:disable - // 'footnotes_getTags' must match its instance in wysiwyg-editor.js. - // 'footnotes_getTags' must match its instance in editor-button.html. - add_action( 'wp_ajax_nopriv_footnotes_getTags', array( 'Footnotes_WYSIWYG', 'ajax_callback' ) ); - add_action( 'wp_ajax_footnotes_getTags', array( 'Footnotes_WYSIWYG', 'ajax_callback' ) ); - // phpcs:enable } - /** * Append a new Button to the WYSIWYG editor of Posts and Pages. * diff --git a/src/includes/class-footnotes.php b/src/includes/class-footnotes.php index 9c59cf0..c122fb1 100644 --- a/src/includes/class-footnotes.php +++ b/src/includes/class-footnotes.php @@ -155,8 +155,9 @@ class Footnotes { * Register all of the hooks related to the admin area functionality * of the plugin. * - * @since 2.8.0 - * @access private + * @since 1.5.0 + * @since 2.8.0 Moved registrating from various classes into `Footnotes_Admin`. + * @access private */ private function define_admin_hooks() { @@ -166,6 +167,18 @@ class Footnotes { $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_filter( 'plugin_action_links_footnotes/footnotes.php', $plugin_admin, 'footnotes_action_links' ); + + $this->loader->add_filter( 'mce_buttons', $plugin_admin->wysiwyg, 'new_visual_editor_button' ); + $this->loader->add_action( 'admin_print_footer_scripts', $plugin_admin->wysiwyg, 'new_plain_text_editor_button' ); + + $this->loader->add_filter( 'mce_external_plugins', $plugin_admin->wysiwyg, 'include_scripts' ); + + // phpcs:disable + // 'footnotes_getTags' must match its instance in wysiwyg-editor.js. + // 'footnotes_getTags' must match its instance in editor-button.html. + $this->loader->add_action( 'wp_ajax_nopriv_footnotes_getTags', $plugin_admin->wysiwyg, 'ajax_callback' ); + $this->loader->add_action( 'wp_ajax_footnotes_getTags', $plugin_admin->wysiwyg, 'ajax_callback' ); + // phpcs:enable } /**