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 -107 trunk3.0.2 View file →
@@ -1,107 +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 - '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 - }
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 + }