Created
October 30, 2015 07:47
-
-
Save hemusyl/97b6af6e5d9cde2e42c9 to your computer and use it in GitHub Desktop.
TinyMCE by Hk
This file contains hidden or 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
http://www.wpexplorer.com/wordpress-tinymce-tweaks/ | |
//tinymce-domain.php | |
<?php | |
// Hooks your functions into the correct filters | |
function desparate_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', 'hktuts_add_tinymce_plugin' ); | |
add_filter( 'mce_buttons', 'my_register_mce_button' ); | |
} | |
} | |
add_action('admin_head', 'desparate_add_mce_button'); | |
// Declare script for new button | |
function hktuts_add_tinymce_plugin( $plugin_array ) { | |
$plugin_array['desparate_mce_button'] = get_template_directory_uri() .'/js/desparate-button.js'; | |
return $plugin_array; | |
} | |
// Register new button in the editor | |
function my_register_mce_button( $buttons ) { | |
array_push( $buttons, 'desparate_mce_button' ); | |
return $buttons; | |
} | |
----------------------------------------------------------------------- | |
Ex1 | |
//desparate-button.js | |
(function() { | |
tinymce.PluginManager.add('desparate_mce_button', function( editor, url ) { | |
editor.addButton('desparate_mce_button', { | |
text: 'HK Button', | |
icon: 'iconname', | |
type: 'menubutton', | |
menu: [ | |
{ | |
text: 'Sub Item 1', | |
onclick: function() { | |
editor.insertContent('[fvideo id="Add your ID"]'); | |
} | |
}, | |
{ | |
text: 'Sub Item 2', | |
onclick: function() { | |
editor.insertContent('WPExplorer.com is awesome!'); | |
} | |
} | |
] | |
}); | |
}); | |
})(); | |
------------------------------------------------------------------ | |
Ex2 | |
(function() { | |
tinymce.PluginManager.add('desparate_mce_button', function( editor, url ) { | |
editor.addButton('desparate_mce_button', { | |
text: 'HK Button', | |
icon: false, | |
type: 'menubutton', | |
menu: [ | |
{ | |
text: 'Sub Item 1', | |
onclick: function() { | |
editor.insertContent('[fvideo id="Add your ID"]'); | |
} | |
}, | |
{ | |
text: 'Pop-Up', | |
onclick: function() { | |
editor.windowManager.open( { | |
title: 'Insert Random Shortcode', | |
body: [ | |
{ | |
type: 'textbox', | |
name: 'textboxName', | |
label: 'Text Box', | |
value: '30' | |
}, | |
], | |
onsubmit: function( e ) { | |
editor.insertContent('[fvideo id="Add your ID"]'); | |
} | |
}); | |
} | |
} | |
] | |
}); | |
}); | |
})(); | |
------------------------------------------------------- | |
Ex 3 | |
(function() { | |
tinymce.PluginManager.add('desparate_mce_button', function( editor, url ) { | |
editor.addButton('desparate_mce_button', { | |
text: 'HK Button', | |
icon:'iconname', | |
type: 'menubutton', | |
menu: [ | |
{ | |
text: 'Item 1', | |
onclick: function() { | |
editor.insertContent('[fvideo id="Add your ID"]'); | |
}, | |
}, | |
{ | |
text: 'Item 2', | |
onclick: function() { | |
editor.insertContent('[fvideo id="Add your ID"]'); | |
}, | |
}, | |
{ | |
text: 'Pop-Up', | |
onclick: function() { | |
editor.windowManager.open( { | |
title: 'Insert Random Shortcode', | |
body: [ | |
{ | |
type: 'textbox', | |
name: 'textboxName', | |
label: 'Text Box', | |
value: '30' | |
}, | |
], | |
onsubmit: function( e ) { | |
editor.insertContent('[fvideo id="Add your ID"]'); | |
} | |
}); | |
}, | |
}, | |
{ | |
text: 'Item 1', | |
menu: [ | |
{ | |
text: 'Sub Item 1', | |
onclick: function() { | |
editor.insertContent('WPExplorer.com is awesome!'); | |
} | |
}, | |
{ | |
text: 'Sub Item 2', | |
onclick: function() { | |
editor.insertContent('WPExplorer.com is awesome!'); | |
} | |
} | |
] | |
}, | |
] | |
}); | |
}); | |
})(); | |
----------------------------------------- | |
Ex4 | |
(function() { | |
tinymce.PluginManager.add('my_mce_button', function( editor, url ) { | |
editor.addButton( 'my_mce_button', { | |
text: 'Sample Dropdown', | |
icon: 'iconname', | |
type: 'menubutton', | |
menu: [ | |
{ | |
text: 'Item 1', | |
menu: [ | |
{ | |
text: 'Pop-Up', | |
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 + '"]'); | |
} | |
}); | |
} | |
} | |
] | |
} | |
] | |
}); | |
}); | |
})(); | |
----------------------------------------------------------------- | |
EX5 | |
(function() { | |
tinymce.PluginManager.add('my_mce_button', function( editor, url ) { | |
editor.addButton( 'my_mce_button', { | |
text: 'Sample Dropdown', | |
icon: 'iconname', | |
type: 'menubutton', | |
menu: [ | |
{ | |
text: 'Item 1', | |
menu: [ | |
{ | |
text: 'Sub Item 1', | |
onclick: function() { | |
editor.insertContent('WPExplorer.com is awesome!'); | |
} | |
}, | |
{ | |
text: 'Sub Item 2', | |
onclick: function() { | |
editor.insertContent('WPExplorer.com is awesome!'); | |
} | |
} | |
] | |
}, | |
{ | |
text: 'Item 2', | |
menu: [ | |
{ | |
text: 'Sub Item 1', | |
onclick: function() { | |
editor.insertContent('WPExplorer.com is awesome!'); | |
} | |
}, | |
{ | |
text: 'Sub Item 2', | |
onclick: function() { | |
editor.insertContent('WPExplorer.com is awesome!'); | |
} | |
} | |
] | |
} | |
] | |
}); | |
}); | |
})(); | |
-------------------------------------------------------------------------------------------------- | |
/** | |
* TinyMCE CSS support | |
* | |
**/ | |
function desparate_shortcodes_mce_css() { | |
wp_enqueue_style('desparatemce', get_template_directory_uri() .'/css/desparate-mce-style.css', array(), '1.0', 'all' ); | |
} | |
add_action( 'admin_enqueue_scripts', 'desparate_shortcodes_mce_css' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment