diff --git a/assets/js/tinymce-buttons.js b/assets/js/tinymce-buttons.js new file mode 100644 index 0000000..7da82e1 --- /dev/null +++ b/assets/js/tinymce-buttons.js @@ -0,0 +1,19 @@ +/** + * TinyMCE buttons for custom shortcodes + */ +( function() { + tinymce.create( 'tinymce.plugins.Bookdata', { + init: function( ed, url ) { + ed.addButton( 'bookdata', { + title: 'Bookdata', + /** image: url + '/img/tinymce-sample.png', */ + onclick: function() { + title = prompt( "Enter title", "" ); + ed.execCommand( 'mceInsertContent', false, '[bookdata title="' + title + '"]' ); + } + }); + }, + createControl: function( n, cm ) { return null; }, + }); + tinymce.PluginManager.add( 'bookdata', tinymce.plugins.PilauSample ); +})(); \ No newline at end of file diff --git a/book-template.php b/book-template.php index b90ffc4..b28fda8 100644 --- a/book-template.php +++ b/book-template.php @@ -2,7 +2,7 @@ /* Plugin Name: Book Template Description: Plugin che aggiunge uno shortcode per la creazione di un box con i dati editoriali di un libro o di un fumetto. -Version: 2020.0813 +Version: 2020.0814.dev Author: Gianluigi Filippelli Author URI: http://dropseaofulaula.blogspot.it/ Plugin URI: https://ulaulaman.github.io/book-template/ @@ -116,5 +116,37 @@ add_shortcode( 'bookdata', 'bookdata' ); return $text; } +/** + * Add TinyMCE buttons for shortcode + */ + +add_action( 'init', 'bookdata_tinymce_shortcode_buttons' ); + +add_filter( 'tiny_mce_version', 'bookdata_refresh_tinymce' ); +function pilau_tinymce_shortcode_buttons() { + // Don't bother doing this stuff if the current user lacks permissions + if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) + return; + // Add only in Rich Editor mode + //if ( get_user_option( 'rich_editing' ) == 'true' ) { + // add_filter( 'mce_external_plugins', 'pilau_tinymce_plugins' ); + // add_filter( 'mce_buttons', 'pilau_register_tinymce_shortcode_buttons' ); + //} +} + +function bookdata_register_tinymce_shortcode_buttons( $buttons ) { + array_push( $buttons, "|", "bookdata" ); + return $buttons; +} +function bookdata_tinymce_plugins( $plugin_array ) { + $plugin_array['bookdata'] = get_template_directory_uri() . '/assets/js/tinymce-buttons.js'; + return $plugin_array; +} + +function bookdata_refresh_tinymce( $ver ) { + $ver += 3; + return $ver; +} + /* ------------------------------------------------------ */ ?>