Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /***********************************************/
- // tiny mc call this codes into your functions.php
- // 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/tiny-mc.js'; // change here your js file location
- return $plugin_array;
- }
- // Register new button in the editor
- function my_register_mce_button( $buttons ) {
- array_push( $buttons, 'my_mce_button' );
- return $buttons;
- }
- /***********************************************/
- // call this codes into your js file
- (function() {
- tinymce.PluginManager.add('my_mce_button', function( editor, url ) {
- editor.addButton( 'my_mce_button', {
- text: 'Add Shortcodes',
- icon: false,
- type: 'menubutton',
- menu:[
- // contact number
- {
- text:'contact number',
- onClick: function(){
- editor.insertContent('[contact-number]');
- }
- },
- //menu
- {
- text:'menu',
- onClick: function(){
- editor.insertContent('[menu name="Left Side Menu"]');
- }
- },
- //blog-post
- {
- text:'blog-post',
- onClick: function(){
- editor.insertContent('[blog-post]');
- }
- },
- // TwentySlider
- {
- text:'TwentySlider',
- onClick: function(){
- editor.insertContent('[twentyslider]');
- }
- },
- // latest-post
- {
- text:'latest-post',
- onClick: function(){
- editor.insertContent('[latest-post]');
- }
- },
- //Blog Post Start
- {
- text:'Blog Post',
- onClick: function() {
- editor.windowManager.open( {
- title: 'Insert Blog Post Shortcode',
- body: [
- {
- type: 'textbox',
- name: 'titleName',
- label: 'Blog Post Title', // Display Name
- },
- {
- type: 'textbox',
- name: 'descriptionName',
- label: 'Descriptions', // Display Name
- multiline: true,
- minWidth: 300,
- minHeight: 100
- },
- {
- type: 'textbox',
- name: 'categoryName',
- label: 'Category', // Display Name
- },
- {
- type: 'textbox',
- name: 'subtitleName',
- label: 'Subtitle', // Display Name
- },
- {
- type: 'textbox',
- name: 'postpageName',
- label: 'Post Per Page', // Display Name
- },
- ],
- // [blog-post textbox="ooo" multiline="ppp" listbox="undefined"]
- onsubmit: function( e ) {
- editor.insertContent( '[blog-post Title="' + e.data.titleName + '" Des="' + e.data.descriptionName + '" Category="' + e.data.categoryName + '" Subtitle="' + e.data.subtitleName + '" Post Per Page="' + e.data.postpageName + '"]');
- }
- });
- }
- }, // Blog Post End
- //TwentySlider Start
- {
- text:'Twenty Slider',
- onClick: function() {
- editor.windowManager.open( {
- title: 'Insert Twenty Slider Shortcode',
- body: [
- {
- type: 'textbox',
- name: 'twentyName',
- label: 'TwentySlider Title', // Display Name
- },
- {
- type: 'textbox',
- name: 'twentydesName',
- label: 'Descriptions', // Display Name
- multiline: true,
- minWidth: 300,
- minHeight: 100
- },
- {
- type: 'textbox',
- name: 'twentysubtitleName',
- label: 'Subtitle', // Display Name
- },
- ],
- // [blog-post textbox="ooo" multiline="ppp" listbox="undefined"]
- onsubmit: function( e ) {
- editor.insertContent( '[twentyslider Title="' + e.data.twentyName + '" Des="' + e.data.twentydesName + '" Subtitle="' + e.data.twentysubtitleName + '"]');
- }
- });
- }
- }, //TwentySlider End
- // add another shortcode
- ]
- });
- });
- })();
- ?>
- // source link:http://www.wpexplorer.com/wordpress-tinymce-tweaks/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement