Advertisement
xpeed

t!nymce button

Sep 2nd, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //copy bellow code and paste into your functions.php file
  2.  
  3.  
  4. // Hooks your functions into the correct filters
  5. function my_add_mce_button() {
  6.         // check user permissions
  7.         if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
  8.                 return;
  9.         }
  10.         // check if WYSIWYG is enabled
  11.         if ( 'true' == get_user_option( 'rich_editing' ) ) {
  12.                 add_filter( 'mce_external_plugins', 'my_add_tinymce_plugin' );
  13.                 add_filter( 'mce_buttons', 'my_register_mce_button' );
  14.         }
  15. }
  16. add_action('admin_head', 'my_add_mce_button');
  17.  
  18. // Declare script for new button
  19. function my_add_tinymce_plugin( $plugin_array ) {
  20.         $plugin_array['my_mce_button'] = get_template_directory_uri() .'/js/mce-button.js';
  21.         return $plugin_array;
  22. }
  23.  
  24. // Register new button in the editor
  25. function my_register_mce_button( $buttons ) {
  26.         array_push( $buttons, 'my_mce_button' );
  27.         return $buttons;
  28. }
  29.  
  30. //endddddddddddddddddddddddddddddddddddddddddddddddd
  31.  
  32.  
  33. //copy bellow code and paste into your js file.
  34.  
  35.  
  36.  
  37.  
  38. (function() {
  39.         tinymce.PluginManager.add('my_mce_button', function( editor, url ) {
  40.                 editor.addButton( 'my_mce_button', {
  41.                         text: 'Button',
  42.                                 onclick: function() {
  43.                                         editor.windowManager.open( {
  44.                                                 title: 'Insert Random Shortcode',
  45.                                                 body: [
  46.                                                         {
  47.                                                                 type: 'textbox',
  48.                                                                 name: 'textboxName',
  49.                                                                 label: 'Text Box',
  50.                                                                 value: '30'
  51.                                                         },
  52.                                                         {
  53.                                                                 type: 'textbox',
  54.                                                                 name: 'multilineName',
  55.                                                                 label: 'Multiline Text Box',
  56.                                                                 value: 'You can say a lot of stuff in here',
  57.                                                                 multiline: true,
  58.                                                                 minWidth: 300,
  59.                                                                 minHeight: 100
  60.                                                         },
  61.                                                         {
  62.                                                                 type: 'listbox',
  63.                                                                 name: 'listboxName',
  64.                                                                 label: 'List Box',
  65.                                                                 'values': [
  66.                                                                         {text: 'Option 1', value: '1'},
  67.                                                                         {text: 'Option 2', value: '2'},
  68.                                                                         {text: 'Option 3', value: '3'}
  69.                                                                 ]
  70.                                                         }
  71.                                                 ],
  72.                                                 onsubmit: function( e ) {
  73.                                                         editor.insertContent( '[random_shortcode textbox="' + e.data.textboxName + '" multiline="' + e.data.multilineName + '" listbox="' + e.data.listboxName + '"]');
  74.                                                 }
  75.                                         });
  76.                                 }
  77.                 });
  78.         });
  79. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement