Created
January 23, 2015 13:13
-
-
Save webhasan/050e57490d5e0bf63763 to your computer and use it in GitHub Desktop.
TinyMCE Dummy Content Generator
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
add_action('admin_head', function(){ | |
global $typenow; | |
//only post type post and page | |
if(! in_array($typenow, array('post','page'))) { | |
return; | |
} | |
add_filter('mce_external_plugins', function( $plugin_array){ | |
$plugin_array['dummytext_plugin'] = plugins_url( '/js/tinymce-plugin.js', __FILE__ ); | |
return $plugin_array; | |
}); | |
add_filter('mce_buttons', function($buttons){ | |
array_push( $buttons, 'dummytext_button' ); | |
return $buttons; | |
}); | |
}); |
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
( function() { | |
dummyContent = '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>'; | |
tinymce.PluginManager.add( 'dummytext_plugin', function( editor, url ) { | |
// Add a button that opens a window | |
editor.addButton( 'dummytext_button', { | |
text: 'Dummy Text Generator', | |
icon: false, | |
onclick: function() { | |
// Open window | |
editor.windowManager.open( { | |
title: 'Dummy Text Generator', | |
body: [{ | |
type: 'textbox', | |
name: 'number', | |
label: 'Number of Paragraphs' | |
}], | |
onsubmit: function( e ) { | |
if(isNaN(e.data.number)) { alert('Please enter a valid number'); return;} | |
// Insert content when the window form is submitted | |
for (var i = 0; i < e.data.number; i++) { | |
editor.insertContent( dummyContent ); | |
} | |
} | |
} ); | |
} | |
} ); | |
} ); | |
} )(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment