PluginProbe
Snippet Shortcodes / trunk
Snippet Shortcodes vtrunk
5.2.1 5.2 5.1.8 5.1.6 5.1.7 5.1.5 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 2.0 2.0.1 All 74 releases
shortcode-variables / includes / tinymce.php

tinymce.php in Snippet Shortcodes trunk, at includes/tinymce.php

108 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') or die("Jog on!");
4
5 /**
6 * Include Tinymce button
7 */
8 function sh_cd_tinymce_button_add() {
9
10 // Ensure user can edit pages before bringing in libraries
11 if ( false === current_user_can('edit_posts') || false === current_user_can('edit_pages') ) {
12 return;
13 }
14
15 // Ensure WYSIWYG is enabled
16 if ( 'true' === get_user_option( 'rich_editing' ) ) {
17
18 add_filter( 'mce_external_plugins', 'sh_cd_tinymce_button_plugin_js' );
19 add_filter( 'mce_buttons', 'sh_cd_tinymce_button_register' );
20
21 sh_cd_tinymce_js_variables();
22 }
23 }
24 add_action( 'admin_head', 'sh_cd_tinymce_button_add' );
25
26 /**
27 * Output Js config
28 */
29 function sh_cd_tinymce_js_variables() {
30
31 $config = [
32 'button-text' => 'Snippet Shortcodes: Insert one of your own shortcodes or select a premade shortcode. ',
33 'button-image' => plugins_url( '../assets/images/snippet-shortcodes.svg', __FILE__ ),
34 'select-text' => 'Premade Variables',
35 'dialog-title' => 'Select a shortcode',
36 'dialog-label' => 'Shortcode',
37 'values-your' => sh_cd_tinymce_js_varables_shortcodes( 'your' ),
38 'values-premade' => sh_cd_tinymce_js_varables_shortcodes( 'premade' )
39 ];
40
41 printf( '<script type="text/javascript">var sh_cd_tinymce = %s;</script>', json_encode( $config ) );
42
43 }
44
45 /**
46 * Fetch options for shortcode selects
47 *
48 * @param $mode
49 *
50 * @return array
51 */
52 function sh_cd_tinymce_js_varables_shortcodes( $mode ) {
53
54 $data = [];
55
56 if ( 'premade' === $mode ) {
57
58 $options = sh_cd_presets_both_lists();
59 $options = array_keys( $options );
60
61 } else {
62
63 $options = sh_cd_db_shortcodes_all_enabled();
64 $options = wp_list_pluck( $options, 'slug' );
65 }
66
67 $formatted = [];
68
69 foreach ( $options as $option ) {
70
71 $formatted[] = [
72 'value' => sprintf( '[sv slug="%s"]', $option ),
73 'text' => $option
74 ];
75
76
77 }
78
79 return $formatted ;
80 }
81
82 /**
83 * Add JS to TinyMCE plugins
84 *
85 * @param $plugins
86 *
87 * @return mixed
88 */
89 function sh_cd_tinymce_button_plugin_js( $plugins ) {
90
91 $plugins[ 'sh_cd_tinymce_button' ] = plugins_url( '../assets/js/tinymce.js', __FILE__ );
92 return $plugins;
93 }
94
95 /**
96 * Register TinyMCE button
97 *
98 * @param $buttons
99 *
100 * @return mixed
101 */
102 function sh_cd_tinymce_button_register( $buttons ) {
103
104 array_push( $buttons, 'sh_cd_tinymce_button' );
105
106 return $buttons;
107 }
108