Created
March 9, 2015 14:40
-
-
Save shahadat014/c0c924a958493029ed46 to your computer and use it in GitHub Desktop.
Tiny MCE botton add
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
//This code call,function php | |
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; | |
} | |
//this code call css file | |
function alpha_shortcode_botton() { | |
wp_register_style( 'shortcode-icons', get_template_directory_uri() . '/css/shortcode.css', array(), '1.0', 'all' ); | |
wp_enqueue_style('shortcode-icons'); | |
} | |
add_action( 'admin_enqueue_scripts', 'alpha_shortcode_botton' ); | |
// then call image in the images file | |
// then call js | |
(function() { | |
tinymce.PluginManager.add('my_mce_button', function( editor, url ) { | |
editor.addButton('my_mce_button', { | |
text: '', | |
icon: true, | |
type: 'menubutton', | |
menu:[ | |
{ | |
text:'Button', | |
onclick: function() { | |
editor.windowManager.open( { | |
title: 'Insert Random Shortcode', | |
body: [ | |
{ | |
type: 'textbox', | |
name: 'buttonText', | |
label: 'Button Text', | |
value: '' | |
}, | |
{ | |
type: 'textbox', | |
name: 'buttonLink', | |
label: 'Button Link', | |
value: '', | |
}, | |
{ | |
type: 'textbox', | |
name: 'buttonType', | |
label: 'button type', | |
value: '', | |
}, | |
{ | |
type: 'textbox', | |
name: 'buttonIcon', | |
label: 'Button Icon', | |
value: '', | |
}, | |
], | |
onsubmit: function( e ) { | |
editor.insertContent( '[btn link="' + e.data.buttonLink + '" text="' + e.data.buttonText + '" type="' + e.data.buttonType + '" icon="' + e.data.buttonIcon + '"]'); | |
} | |
}); | |
} | |
}, | |
{ | |
text:'Progress Bar', | |
onclick: function() { | |
editor.windowManager.open( { | |
title: 'your shortcode text', | |
body: [ | |
{ | |
type: 'textbox', | |
name: 'progressbarType', | |
label: 'Progressbar Type', | |
value: '' | |
}, | |
{ | |
type: 'textbox', | |
name: 'progressbarText', | |
label: 'progressbar Text', | |
value: '', | |
}, | |
{ | |
type: 'textbox', | |
name: 'progressbarValue', | |
label: 'progressbar Value', | |
value: '', | |
}, | |
], | |
onsubmit: function( e ) { | |
editor.insertContent( '[bar type="' + e.data.progressbarType + '" text="' + e.data.progressbarText + '" value="' + e.data.progressbarValue + '"]'); | |
} | |
}); | |
} | |
}, | |
{ | |
text:'pricing', | |
onclick: function() { | |
editor.windowManager.open( { | |
title: 'your shortcode text', | |
body: [ | |
{ | |
type: 'textbox', | |
name: 'pricingColumn', | |
label: 'Pricing Column', | |
value: '', | |
}, | |
{ | |
type: 'textbox', | |
name: 'pricingText1', | |
label: 'Pricing Text1', | |
value: '', | |
}, | |
{ | |
type: 'textbox', | |
name: 'pricingText2', | |
label: 'pricing Text2', | |
value: '', | |
}, | |
{ | |
type: 'textbox', | |
name: 'pricingPrice', | |
label: 'Pricing Price', | |
value: '', | |
}, | |
{ | |
type: 'textbox', | |
name: 'pricingText', | |
label: 'Pricing Text', | |
value: '', | |
}, | |
{ | |
type: 'textbox', | |
name: 'pricingType', | |
label: 'Pricing Type', | |
value: '', | |
}, | |
{ | |
type: 'textbox', | |
name: 'pricingLink', | |
label: 'Pricing Link', | |
value: '', | |
}, | |
{ | |
type: 'textbox', | |
name: 'pricingIcon', | |
label: 'Pricing Icon', | |
value: '', | |
}, | |
], | |
onsubmit: function( e ) { | |
editor.insertContent( '[pricing heading_1="' + e.data.pricingText1 + '" heading_2="' + e.data.pricingText2 + '" price="' + e.data.pricingPrice + '" link="' + e.data.pricingLink + '" type="' + e.data.pricingType + '" icon="' + e.data.pricingIcon + '" text="' + e.data.pricingText + '" column="' + e.data.pricingColumn + '"]'); | |
} | |
}); | |
} | |
}, | |
{ | |
text:'title', | |
onclick: function() { | |
editor.windowManager.open( { | |
title: 'your shortcode text', | |
body: [ | |
{ | |
type: 'textbox', | |
name: 'title', | |
label: 'Title', | |
value: '', | |
}, | |
], | |
onsubmit: function( e ) { | |
editor.insertContent( '[title title="' + e.data.title + '"]'); | |
} | |
}); | |
} | |
}, | |
{ | |
text:'google map', | |
onclick: function() { | |
editor.windowManager.open( { | |
title: 'your shortcode text', | |
body: [ | |
{ | |
type: 'textbox', | |
name: 'googleMap', | |
label: 'Google Map', | |
value: '', | |
}, | |
], | |
onsubmit: function( e ) { | |
editor.insertContent( '[map map_link="' + e.data.googleMap + '"]'); | |
} | |
}); | |
} | |
}, | |
] | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment