Answer the question
In order to leave comments, you need to log in
Why is the button not being added to the editor in Wordpress?
PHP:
<?php
class BlockHider {
public static function init() {
add_action('admin_head', array(__CLASS__, 'addEditorButton'));
}
// Кнопка для добавления шорткода в редакторе
public static function addEditorButton() {
if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
return;
}
if( ! in_array( $typenow, array( 'post', 'page' ) ) )
return;
if ( 'true' == get_user_option( 'rich_editing' ) ) {
add_filter('mce_external_plugins', array(__CLASS__, 'addEditorScript'));
add_filter('mce_buttons', array(__CLASS__, 'registerEditorButton'));
}
}
public static function addEditorScript($plugin_array) {
$plugin_array['hiddenblockButton'] = plugins_url('/js/editor_button.js', __FILE__);
return $plugin_array;
}
public static function registerEditorButton($buttons) {
array_push($buttons, 'hiddenblockButton');
return $buttons;
}
}
add_action('plugins_loaded', array('BlockHider', 'init'));
(function() {
tinymce.PluginManager.add('hiddenblockButton', function( editor, url ) {
editor.addButton('hiddenblockButton', {
text: 'Скрыть блок',
title: 'Скрывает выбранный участок от поисковых систем',
//icon: 'icon dashicons-hidden',
icon: false,
onclick: function() {
selection.setContent('[hiddenblock]' + ed.selection.getContent() + '[/hiddenblock]');
}
});
});
})();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question