Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //copy bellow code and paste into your functions.php file
- // Hooks your functions into the correct filters
- function my_add_mce_button() {
- // check user permissions
- if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
- return;
- }
- // check if WYSIWYG is enabled
- if ( 'true' == get_user_option( 'rich_editing' ) ) {
- add_filter( 'mce_external_plugins', 'my_add_tinymce_plugin' );
- add_filter( 'mce_buttons', 'my_register_mce_button' );
- }
- }
- add_action('admin_head', 'my_add_mce_button');
- // Declare script for new button
- function my_add_tinymce_plugin( $plugin_array ) {
- $plugin_array['my_mce_button'] = get_template_directory_uri() .'/js/mce-button.js';
- return $plugin_array;
- }
- // Register new button in the editor
- function my_register_mce_button( $buttons ) {
- array_push( $buttons, 'my_mce_button' );
- return $buttons;
- }
- //endddddddddddddddddddddddddddddddddddddddddddddddd
- //copy bellow code and paste into your js file.
- (function() {
- tinymce.PluginManager.add('my_mce_button', function( editor, url ) {
- editor.addButton( 'my_mce_button', {
- text: 'Button',
- onclick: function() {
- editor.windowManager.open( {
- title: 'Insert Random Shortcode',
- body: [
- {
- type: 'textbox',
- name: 'textboxName',
- label: 'Text Box',
- value: '30'
- },
- {
- type: 'textbox',
- name: 'multilineName',
- label: 'Multiline Text Box',
- value: 'You can say a lot of stuff in here',
- multiline: true,
- minWidth: 300,
- minHeight: 100
- },
- {
- type: 'listbox',
- name: 'listboxName',
- label: 'List Box',
- 'values': [
- {text: 'Option 1', value: '1'},
- {text: 'Option 2', value: '2'},
- {text: 'Option 3', value: '3'}
- ]
- }
- ],
- onsubmit: function( e ) {
- editor.insertContent( '[random_shortcode textbox="' + e.data.textboxName + '" multiline="' + e.data.multilineName + '" listbox="' + e.data.listboxName + '"]');
- }
- });
- }
- });
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement