Instantly share code, notes, and snippets.
Created
May 2, 2017 05:51
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save AnatoliyAkhmatov/21924529cafdd28d1c9ddaa003a947c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function.php | |
function ex_add_tinymce_plugin($plugin_array) { | |
$plugin_array['ex_first_button'] = get_template_directory_uri()."/js/btn.js"; // Укажите имя ВАШЕГО файла | |
return $plugin_array; | |
} | |
function ex_register_my_first_button($buttons) { | |
array_push($buttons, "ex_first_button"); | |
return $buttons; | |
} | |
function ex_add_my_first_button() { | |
global $typenow; | |
// проверяем права доступа | |
if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) { | |
return; | |
} | |
// проверяем тип поста | |
if( ! in_array( $typenow, array( 'post', 'page' ) ) ) | |
return; | |
// проверяем что WYSIWYG включен | |
if ( get_user_option('rich_editing') == 'true') { | |
add_filter("mce_external_plugins", "ex_add_tinymce_plugin"); | |
add_filter('mce_buttons', 'ex_register_my_first_button'); | |
} | |
} | |
add_action('admin_head', 'ex_add_my_first_button'); | |
//patch to theme /js/btn.js | |
(function() { | |
tinymce.PluginManager.add('ex_first_button', function( editor, url ) { | |
editor.addButton( 'ex_first_button', { | |
// text: 'Тестовая кнопка', | |
title: 'Текстовая кнопка', | |
// image: 'part-to-img', // img as icon | |
icon: 'dashicon dashicons-editor-code', // false | |
// type: 'menubutton', // выпадающий список | |
// menu: [ // выпадающий список | |
// { | |
// text: 'Сказать привет мир', | |
// value: 'Привет мир!', | |
// onclick: function() { | |
// editor.insertContent(this.value()); | |
// } | |
// }, | |
// { | |
// text: 'Элемент меню II', | |
// value: 'Текст из второго элемента', | |
// onclick: function() { | |
// editor.insertContent(this.value()); | |
// }, | |
// menu: [ | |
// { | |
// text: 'Первый элемент меню', | |
// value: 'Текст из подменю', | |
// onclick: function(e) { | |
// e.stopPropagation(); | |
// editor.insertContent(this.value()); | |
// } | |
// }, | |
// { | |
// text: 'Второй элемент меню', | |
// value: 'Текст из подменю', | |
// onclick: function(e) { | |
// e.stopPropagation(); | |
// editor.insertContent(this.value()); | |
// } | |
// } | |
// ] | |
// }, | |
// { | |
// text: 'Элемент меню III', | |
// value: 'Текст из подменю', | |
// onclick: function() { | |
// editor.insertContent(this.value()); | |
// } | |
// } | |
// ] | |
// onclick: function() { // всплывающее окно | |
// editor.windowManager.open( { | |
// title: 'Вставить заголовок', | |
// body: [{ | |
// type: 'textbox', | |
// name: 'title', | |
// label: 'Ваш заголовок' | |
// }, | |
// { | |
// type: 'textbox', | |
// name: 'id', | |
// label: 'Анкор' | |
// }, | |
// { | |
// type: 'listbox', | |
// name: 'level', | |
// label: 'Уровень заголовка', | |
// 'values': [ | |
// {text: '<h3>', value: '3'}, | |
// {text: '<h4>', value: '4'}, | |
// {text: '<h5>', value: '5'}, | |
// {text: '<h6>', value: '6'} | |
// ] | |
// }], | |
// onsubmit: function( e ) { | |
// editor.insertContent( '<h' + e.data.level + ' id="' + e.data.id + '">' + e.data.title + '</h' + e.data.level + '>'); | |
// } | |
// }); | |
// } | |
onclick: function() { // всплывающее окно | |
editor.windowManager.open( { | |
title: 'Название части', | |
body: [ | |
{ | |
type: 'textbox', | |
name: 'name', | |
label: 'Название части' | |
} | |
], | |
onsubmit: function( e ) { | |
editor.focus(); | |
editor.selection.setContent( | |
'<code>' + | |
'---------------' + | |
e.data.name + | |
'---------------/' + | |
'<br>' + | |
editor.selection.getContent() + | |
'<br>' + | |
'</code>' | |
); | |
} | |
}); | |
} | |
// onclick: function() { | |
// editor.focus(); | |
// editor.selection.setContent('<code>' + editor.selection.getContent() + '</code>'); | |
// } | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment