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