2021-03-03 18:58:03 +00:00
|
|
|
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
2021-03-02 03:09:34 +00:00
|
|
|
/**
|
|
|
|
* Includes the Class to handle the WYSIWYG-Buttons.
|
|
|
|
*
|
|
|
|
* @filesource
|
2021-03-03 18:58:03 +00:00
|
|
|
* @package footnotes
|
|
|
|
* @since 1.5.0
|
2021-03-02 03:09:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-03-03 18:58:03 +00:00
|
|
|
* Handles the WSYIWYG-Buttons.
|
2021-03-02 03:09:34 +00:00
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*/
|
|
|
|
class MCI_Footnotes_WYSIWYG {
|
|
|
|
|
2021-03-03 18:58:03 +00:00
|
|
|
/**
|
|
|
|
* Registers Button hooks.
|
2021-02-23 16:44:18 +00:00
|
|
|
*
|
2021-04-01 06:48:43 +00:00
|
|
|
* @since 1.5.0
|
2021-04-10 19:02:10 +00:00
|
|
|
*
|
2021-04-01 06:48:43 +00:00
|
|
|
* - 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.
|
2021-04-10 19:02:10 +00:00
|
|
|
*
|
2021-04-01 06:48:43 +00:00
|
|
|
* @reporter @gova
|
|
|
|
* @link https://wordpress.org/support/topic/back-end-footnotes-not-working-400-bad-erro/
|
2021-03-03 18:58:03 +00:00
|
|
|
*
|
2021-04-01 06:48:43 +00:00
|
|
|
* @since 2.6.5
|
2021-03-03 18:58:03 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function register_hooks() {
|
|
|
|
add_filter( 'mce_buttons', array( 'MCI_Footnotes_WYSIWYG', 'new_visual_editor_button' ) );
|
|
|
|
add_action( 'admin_print_footer_scripts', array( 'MCI_Footnotes_WYSIWYG', 'new_plain_text_editor_button' ) );
|
2021-03-02 03:09:34 +00:00
|
|
|
|
2021-03-03 18:58:03 +00:00
|
|
|
add_filter( 'mce_external_plugins', array( 'MCI_Footnotes_WYSIWYG', 'include_scripts' ) );
|
2021-03-02 03:09:34 +00:00
|
|
|
|
2021-04-01 06:48:43 +00:00
|
|
|
// 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( 'MCI_Footnotes_WYSIWYG', 'ajax_callback' ) );
|
|
|
|
add_action( 'wp_ajax_footnotes_getTags', array( 'MCI_Footnotes_WYSIWYG', 'ajax_callback' ) );
|
|
|
|
// phpcs:enable
|
2021-03-02 03:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append a new Button to the WYSIWYG editor of Posts and Pages.
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
2021-03-03 18:58:03 +00:00
|
|
|
* @param array $p_arr_buttons pre defined Buttons from WordPress.
|
2021-03-02 03:09:34 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2021-03-03 18:58:03 +00:00
|
|
|
public static function new_visual_editor_button( $p_arr_buttons ) {
|
|
|
|
array_push( $p_arr_buttons, MCI_Footnotes_Config::C_STR_PLUGIN_NAME );
|
|
|
|
return $p_arr_buttons;
|
2021-03-02 03:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new button to the plain text editor.
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*/
|
2021-03-03 18:58:03 +00:00
|
|
|
public static function new_plain_text_editor_button() {
|
|
|
|
$l_obj_template = new MCI_Footnotes_Template( MCI_Footnotes_Template::C_STR_DASHBOARD, 'editor-button' );
|
|
|
|
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
|
|
echo $l_obj_template->get_content();
|
|
|
|
// phpcs:enable
|
2021-03-02 03:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Includes the Plugins WYSIWYG editor script.
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
2021-03-03 18:58:03 +00:00
|
|
|
* @param array $p_arr_plugins Scripts to be included to the editor.
|
2021-03-02 03:09:34 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2021-03-03 18:58:03 +00:00
|
|
|
public static function include_scripts( $p_arr_plugins ) {
|
|
|
|
$p_arr_plugins[ MCI_Footnotes_Config::C_STR_PLUGIN_NAME ] = plugins_url( '/../js/wysiwyg-editor.js', __FILE__ );
|
|
|
|
return $p_arr_plugins;
|
2021-03-02 03:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AJAX Callback function when the Footnotes Button is clicked. Either in the Plain text or Visual editor.
|
|
|
|
* Returns an JSON encoded array with the Footnotes start and end short code.
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*/
|
2021-03-03 18:58:03 +00:00
|
|
|
public static function ajax_callback() {
|
|
|
|
// Get start and end tag for the footnotes short code.
|
|
|
|
$l_str_starting_tag = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START );
|
|
|
|
$l_str_ending_tag = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END );
|
|
|
|
if ( 'userdefined' === $l_str_starting_tag || 'userdefined' === $l_str_ending_tag ) {
|
|
|
|
$l_str_starting_tag = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START_USER_DEFINED );
|
|
|
|
$l_str_ending_tag = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END_USER_DEFINED );
|
2021-03-02 03:09:34 +00:00
|
|
|
}
|
2021-04-01 06:48:43 +00:00
|
|
|
echo json_encode(
|
2021-03-03 18:58:03 +00:00
|
|
|
array(
|
|
|
|
'start' => htmlspecialchars( $l_str_starting_tag ),
|
|
|
|
'end' => htmlspecialchars( $l_str_ending_tag ),
|
|
|
|
)
|
|
|
|
);
|
2021-03-02 03:09:34 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|