wpXtreme / wpdk

WordPress Development Kit
http://wpxtreme.github.io/wpdk/
Other
78 stars 19 forks source link

Shortcodes #30

Open gfazioli opened 10 years ago

gfazioli commented 10 years ago
<?php
add_filter( 'mce_external_plugins', array($this, 'add_plugin' ) );  
add_filter( 'mce_buttons_2', array($this, 'register_button' ) );  

...

function add_plugin( $plugin_array ){
  $plugin_array['shortcodes'] = get_template_directory_uri() . '/js/shortcodes.js';
  return $plugin_array; 
}

function register_button( $buttons ){
  array_push( $buttons, "separator", "warning", "error", "notice", "important", "separator", "pullquote");
  return $buttons;
}

Javascript side

/* Handles the theme's shortcode buttons in the TinyMCE editor */
(function() {  
  tinyMCE.create('tinyMCE.plugins.ShortCodes', {  
    init : function(ed, url) {  
      ed.addButton('warning', {  
        title : ed.getLang('buttons.warning_title'),
    image : url+'/buttons/warning.png',  
    onclick : function() {  
           ed.selection.setContent('[warning]' + ed.selection.getContent() + '[/warning]');  
        }  
    });
},  
  createControl : function(n, cm) {  
    return null;  
  }  
});  

tinyMCE.PluginManager.add('shortcodes', tinyMCE.plugins.ShortCodes);  

})();