Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * The following code will add the Code Sample plugin (https://www.tiny.cloud/docs-4x/plugins/codesample/)
- * to the WordPress TinyMCE editor. But first, WordPress does not include the plugin
- * by default, so you need to download it (http://download.tiny.cloud/tinymce/community/tinymce_4.8.0.zip)
- * and upload it to your site - in the ZIP file, it's placed in js/tinymce/plugins/.
- * Note: You should upload the entire "codesample" folder and not just the plugin.min.js or plugin.js file.
- *
- * You can get a custom Prism JS and CSS files via http://prismjs.com/download.html.
- *
- * Tried and tested working on WordPress 5.0.3 with TinyMCE 4.8.0 and wpForo 1.5.5.
- */
- ?>
- <?php
- // Enqueue Prism CSS for use on the front-end. (not in the TinyMCE editor)
- add_action( 'wp_enqueue_styles', function(){
- wp_enqueue_style( 'prism-custom', 'URL to the Prism CSS file', [], null );
- } );
- // Enqueue Prism JS for use on the front-end. (not in the TinyMCE editor)
- add_action( 'wp_enqueue_scripts', function(){
- wp_enqueue_script( 'prism-custom', 'URL to the Prism JS file', [], null );
- } );
- // Add the external codesample TinyMCE plugin.
- add_filter( 'mce_external_plugins', function( $plugins ){
- $plugins['codesample'] = 'URL to the TinyMCE codesample/plugin.min.js';
- return $plugins;
- }, 16 ); // the priority should be at least 16 for the code to work with wpForo
- // Add the codesample button to TinyMCE - mce_buttons doesn't work with wpForo.
- add_filter( 'wp_editor_settings', function( $settings ){
- if ( empty( $settings['tinymce'] ) || ! is_array( $settings['tinymce'] ) )
- $settings['tinymce'] = [];
- if ( isset( $settings['tinymce']['toolbar1'] ) )
- $settings['tinymce']['toolbar1'] .= ',codesample';
- else
- $settings['tinymce']['toolbar1'] = 'codesample';
- return $settings;
- } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement