PluginProbe
Snippet Shortcodes / 5.1.1
Snippet Shortcodes v5.1.1
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 5.1.1, at includes/tinymce.php

115 lines 2.5 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 'premium' => sh_cd_is_premium(),
36 'upgrade-url' => sh_cd_license_upgrade_link(),
37 'upgrade-text' => 'This is a premium feature. Would you like to upgrade Snippet Shortcodes?',
38 'dialog-title' => 'Select a shortcode',
39 'dialog-label' => 'Shortcode',
40 'values-your' => sh_cd_tinymce_js_varables_shortcodes( 'your' ),
41 'values-premade' => sh_cd_tinymce_js_varables_shortcodes( 'premade' )
42 ];
43
44 printf( '<script type="text/javascript">var sh_cd_tinymce = %s;</script>', json_encode( $config ) );
45
46 }
47
48 /**
49 * Fetch options for shortcode selects
50 *
51 * @param $mode
52 *
53 * @return array
54 */
55 function sh_cd_tinymce_js_varables_shortcodes( $mode ) {
56
57 $data = [];
58
59 if ( false === sh_cd_is_premium() ) {
60 return [];
61 }
62
63 if ( 'premade' === $mode ) {
64
65 $options = sh_cd_presets_both_lists();
66 $options = array_keys( $options );
67
68 } else {
69
70 $options = sh_cd_db_shortcodes_all_enabled();
71 $options = wp_list_pluck( $options, 'slug' );
72 }
73
74 $formatted = [];
75
76 foreach ( $options as $option ) {
77
78 $formatted[] = [
79 'value' => sprintf( '[sv slug="%s"]', $option ),
80 'text' => $option
81 ];
82
83
84 }
85
86 return $formatted ;
87 }
88
89 /**
90 * Add JS to TinyMCE plugins
91 *
92 * @param $plugins
93 *
94 * @return mixed
95 */
96 function sh_cd_tinymce_button_plugin_js( $plugins ) {
97
98 $plugins[ 'sh_cd_tinymce_button' ] = plugins_url( '../assets/js/tinymce.js', __FILE__ );
99 return $plugins;
100 }
101
102 /**
103 * Register TinyMCE button
104 *
105 * @param $buttons
106 *
107 * @return mixed
108 */
109 function sh_cd_tinymce_button_register( $buttons ) {
110
111 array_push( $buttons, 'sh_cd_tinymce_button' );
112
113 return $buttons;
114 }
115