@@ -12,7 +12,7 @@ |
||
12 | 12 | */ |
13 | 13 | public function inflectPackageVars($vars) |
14 | 14 | { |
15 | - $vars['name'] = preg_replace_callback('/(?:^|_|-)(.?)/', function ($matches) { |
|
15 | + $vars['name'] = preg_replace_callback('/(?:^|_|-)(.?)/', function($matches) { |
|
16 | 16 | return strtoupper($matches[1]); |
17 | 17 | }, $vars['name']); |
18 | 18 |
@@ -215,7 +215,7 @@ |
||
215 | 215 | $pattern = $locations ? '(' . implode('|', $locations) . ')' : false; |
216 | 216 | } |
217 | 217 | |
218 | - return $pattern ? : '(\w+)'; |
|
218 | + return $pattern ?: '(\w+)'; |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -26,9 +26,9 @@ |
||
26 | 26 | class BitrixInstaller extends BaseInstaller |
27 | 27 | { |
28 | 28 | protected $locations = array( |
29 | - 'module' => '{$bitrix_dir}/modules/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) |
|
29 | + 'module' => '{$bitrix_dir}/modules/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) |
|
30 | 30 | 'component' => '{$bitrix_dir}/components/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) |
31 | - 'theme' => '{$bitrix_dir}/templates/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) |
|
31 | + 'theme' => '{$bitrix_dir}/templates/{$name}/', // deprecated, remove on the major release (Backward compatibility will be broken) |
|
32 | 32 | 'd7-module' => '{$bitrix_dir}/modules/{$vendor}.{$name}/', |
33 | 33 | 'd7-component' => '{$bitrix_dir}/components/{$vendor}/{$name}/', |
34 | 34 | 'd7-template' => '{$bitrix_dir}/templates/{$vendor}_{$name}/', |
@@ -17,7 +17,7 @@ |
||
17 | 17 | */ |
18 | 18 | public function inflectPackageVars($vars) |
19 | 19 | { |
20 | - $vars['name'] = preg_replace_callback('/(-[a-z])/', function ($matches) { |
|
20 | + $vars['name'] = preg_replace_callback('/(-[a-z])/', function($matches) { |
|
21 | 21 | return strtoupper($matches[0][1]); |
22 | 22 | }, $vars['name']); |
23 | 23 |
@@ -10,7 +10,7 @@ |
||
10 | 10 | 'library' => 'libraries/{$name}/', |
11 | 11 | 'profile' => 'profiles/{$name}/', |
12 | 12 | 'drush' => 'drush/{$name}/', |
13 | - 'custom-theme' => 'themes/custom/{$name}/', |
|
14 | - 'custom-module' => 'modules/custom/{$name}/', |
|
13 | + 'custom-theme' => 'themes/custom/{$name}/', |
|
14 | + 'custom-module' => 'modules/custom/{$name}/', |
|
15 | 15 | ); |
16 | 16 | } |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | */ |
36 | 36 | protected function inflectModuleVars($vars) |
37 | 37 | { |
38 | - $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
39 | - $vars['name'] = str_replace('module-', '', $vars['name']); // strip out module- |
|
40 | - $vars['name'] = preg_replace('/-module$/', '', $vars['name']); // strip out -module |
|
41 | - $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
42 | - $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
38 | + $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
39 | + $vars['name'] = str_replace('module-', '', $vars['name']); // strip out module- |
|
40 | + $vars['name'] = preg_replace('/-module$/', '', $vars['name']); // strip out -module |
|
41 | + $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
42 | + $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
43 | 43 | |
44 | 44 | return $vars; |
45 | 45 | } |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | */ |
53 | 53 | protected function inflectThemeVars($vars) |
54 | 54 | { |
55 | - $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
56 | - $vars['name'] = str_replace('theme-', '', $vars['name']); // strip out theme- |
|
57 | - $vars['name'] = preg_replace('/-theme$/', '', $vars['name']); // strip out -theme |
|
58 | - $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
59 | - $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
55 | + $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
56 | + $vars['name'] = str_replace('theme-', '', $vars['name']); // strip out theme- |
|
57 | + $vars['name'] = preg_replace('/-theme$/', '', $vars['name']); // strip out -theme |
|
58 | + $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
59 | + $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
60 | 60 | |
61 | 61 | return $vars; |
62 | 62 | } |
@@ -37,7 +37,7 @@ |
||
37 | 37 | */ |
38 | 38 | private function correctPluginName($vars) |
39 | 39 | { |
40 | - $camelCasedName = preg_replace_callback('/(-[a-z])/', function ($matches) { |
|
40 | + $camelCasedName = preg_replace_callback('/(-[a-z])/', function($matches) { |
|
41 | 41 | return strtoupper($matches[0][1]); |
42 | 42 | }, $vars['name']); |
43 | 43 |
@@ -6,8 +6,8 @@ |
||
6 | 6 | } |
7 | 7 | } |
8 | 8 | if ((!$loader = includeIfExists(__DIR__ . '/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__ . '/../../../autoload.php'))) { |
9 | - die('You must set up the project dependencies, run the following commands:'.PHP_EOL. |
|
10 | - 'curl -s http://getcomposer.org/installer | php'.PHP_EOL. |
|
11 | - 'php composer.phar install'.PHP_EOL); |
|
9 | + die('You must set up the project dependencies, run the following commands:' . PHP_EOL . |
|
10 | + 'curl -s http://getcomposer.org/installer | php' . PHP_EOL . |
|
11 | + 'php composer.phar install' . PHP_EOL); |
|
12 | 12 | } |
13 | 13 | return $loader; |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * @param string $id |
269 | 269 | * @param string $search_for_id |
270 | 270 | * |
271 | - * @return mixed |
|
271 | + * @return string |
|
272 | 272 | */ |
273 | 273 | public static function shortcode_button( $id = '', $search_for_id = '' ) { |
274 | 274 | ob_start(); |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * Makes SD work with the siteOrigin page builder. |
299 | 299 | * |
300 | 300 | * @since 1.0.6 |
301 | - * @return mixed |
|
301 | + * @return string |
|
302 | 302 | */ |
303 | 303 | public static function siteorigin_js() { |
304 | 304 | ob_start(); |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | /** |
858 | 858 | * Gets some CSS for the widgets screen. |
859 | 859 | * |
860 | - * @return mixed |
|
860 | + * @return string |
|
861 | 861 | */ |
862 | 862 | public function widget_css() { |
863 | 863 | ob_start(); |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | /** |
898 | 898 | * Gets some JS for the widgets screen. |
899 | 899 | * |
900 | - * @return mixed |
|
900 | + * @return string |
|
901 | 901 | */ |
902 | 902 | public function widget_js() { |
903 | 903 | ob_start(); |
@@ -1347,7 +1347,7 @@ discard block |
||
1347 | 1347 | * |
1348 | 1348 | * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
1349 | 1349 | * @since 1.0.9 Save numbers as numbers and not strings. |
1350 | - * @return mixed |
|
1350 | + * @return string |
|
1351 | 1351 | */ |
1352 | 1352 | public function block() { |
1353 | 1353 | ob_start(); |
@@ -1,149 +1,149 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | if ( ! class_exists( 'WP_Super_Duper' ) ) { |
7 | 7 | |
8 | 8 | |
9 | - /** |
|
10 | - * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress. |
|
11 | - * |
|
12 | - * Should not be called direct but extended instead. |
|
13 | - * |
|
14 | - * Class WP_Super_Duper |
|
15 | - * @since 1.0.3 is_block_content_call() method added. |
|
16 | - * @since 1.0.3 Placeholder text will be shown for widget that return no block content. |
|
17 | - * @since 1.0.4 is_elementor_widget_output() method added. |
|
18 | - * @since 1.0.4 is_elementor_preview() method added. |
|
19 | - * @since 1.0.5 Block checkbox options are set as true by default even when set as false - FIXED |
|
20 | - * @since 1.0.6 Some refactoring for page builders - CHANGED |
|
21 | - * @since 1.0.7 Some refactoring for page builders - CHANGED |
|
22 | - * @since 1.0.8 Some refactoring for page builders ( cornerstone builder now supported ) - CHANGED |
|
23 | - * @since 1.0.9 Numbers saving as strings and not numbers which can cause block render issues on refresh - FIXED |
|
24 | - * @since 1.0.10 Some refactoring for page builders ( Avia builder for Enfold theme now supported ) - CHANGED |
|
25 | - * @since 1.0.11 Some refactoring for page builders - CHANGED |
|
26 | - * @since 1.0.12 A checkbox default value can make a argument true even when unchecked - FIXED |
|
27 | - * @ver 1.0.12 |
|
28 | - */ |
|
29 | - class WP_Super_Duper extends WP_Widget { |
|
30 | - |
|
31 | - public $version = "1.0.12"; |
|
32 | - public $block_code; |
|
33 | - public $options; |
|
34 | - public $base_id; |
|
35 | - public $arguments = array(); |
|
36 | - public $instance = array(); |
|
37 | - private $class_name; |
|
38 | - |
|
39 | - /** |
|
40 | - * Take the array options and use them to build. |
|
41 | - */ |
|
42 | - public function __construct( $options ) { |
|
43 | - global $sd_widgets; |
|
44 | - |
|
45 | - $sd_widgets[ $options['base_id'] ] = array( |
|
46 | - 'name' => $options['name'], |
|
47 | - 'class_name' => $options['class_name'] |
|
48 | - ); |
|
49 | - $this->base_id = $options['base_id']; |
|
50 | - // lets filter the options before we do anything |
|
51 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
52 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
53 | - $options = $this->add_name_from_key( $options ); |
|
54 | - $this->options = $options; |
|
55 | - |
|
56 | - $this->base_id = $options['base_id']; |
|
57 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
58 | - |
|
59 | - // init parent |
|
60 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
61 | - |
|
62 | - if ( isset( $options['class_name'] ) ) { |
|
63 | - // register widget |
|
64 | - $this->class_name = $options['class_name']; |
|
65 | - |
|
66 | - // register shortcode |
|
67 | - $this->register_shortcode(); |
|
68 | - |
|
69 | - // register block |
|
70 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
71 | - } |
|
72 | - |
|
73 | - // add the CSS and JS we need ONCE |
|
74 | - global $sd_widget_scripts; |
|
75 | - |
|
76 | - if ( ! $sd_widget_scripts ) { |
|
77 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
78 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
79 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
80 | - |
|
81 | - $sd_widget_scripts = true; |
|
82 | - |
|
83 | - // add shortcode insert button once |
|
84 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
85 | - if ( $this->is_preview() ) { |
|
86 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
87 | - // this makes the insert button work for elementor |
|
88 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
89 | - $this, |
|
90 | - 'shortcode_insert_button_script' |
|
91 | - ) ); // for elementor |
|
92 | - } |
|
93 | - // this makes the insert button work for cornerstone |
|
94 | - add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
95 | - |
|
96 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
97 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
98 | - |
|
99 | - // add generator text to admin head |
|
100 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
101 | - } |
|
102 | - |
|
103 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
108 | - */ |
|
109 | - public static function maybe_cornerstone_builder(){ |
|
110 | - if(did_action('cornerstone_before_boot_app')){ |
|
111 | - self::shortcode_insert_button_script(); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * A function to ge the shortcode builder picker html. |
|
117 | - * |
|
118 | - * @param string $editor_id |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public static function get_picker( $editor_id = '' ) { |
|
123 | - |
|
124 | - ob_start(); |
|
125 | - if ( isset( $_POST['editor_id'] ) ) { |
|
126 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
127 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
128 | - $editor_id = 'main_content_content_vb_tiny_mce'; |
|
129 | - } |
|
130 | - |
|
131 | - global $sd_widgets; |
|
132 | - ?> |
|
9 | + /** |
|
10 | + * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress. |
|
11 | + * |
|
12 | + * Should not be called direct but extended instead. |
|
13 | + * |
|
14 | + * Class WP_Super_Duper |
|
15 | + * @since 1.0.3 is_block_content_call() method added. |
|
16 | + * @since 1.0.3 Placeholder text will be shown for widget that return no block content. |
|
17 | + * @since 1.0.4 is_elementor_widget_output() method added. |
|
18 | + * @since 1.0.4 is_elementor_preview() method added. |
|
19 | + * @since 1.0.5 Block checkbox options are set as true by default even when set as false - FIXED |
|
20 | + * @since 1.0.6 Some refactoring for page builders - CHANGED |
|
21 | + * @since 1.0.7 Some refactoring for page builders - CHANGED |
|
22 | + * @since 1.0.8 Some refactoring for page builders ( cornerstone builder now supported ) - CHANGED |
|
23 | + * @since 1.0.9 Numbers saving as strings and not numbers which can cause block render issues on refresh - FIXED |
|
24 | + * @since 1.0.10 Some refactoring for page builders ( Avia builder for Enfold theme now supported ) - CHANGED |
|
25 | + * @since 1.0.11 Some refactoring for page builders - CHANGED |
|
26 | + * @since 1.0.12 A checkbox default value can make a argument true even when unchecked - FIXED |
|
27 | + * @ver 1.0.12 |
|
28 | + */ |
|
29 | + class WP_Super_Duper extends WP_Widget { |
|
30 | + |
|
31 | + public $version = "1.0.12"; |
|
32 | + public $block_code; |
|
33 | + public $options; |
|
34 | + public $base_id; |
|
35 | + public $arguments = array(); |
|
36 | + public $instance = array(); |
|
37 | + private $class_name; |
|
38 | + |
|
39 | + /** |
|
40 | + * Take the array options and use them to build. |
|
41 | + */ |
|
42 | + public function __construct( $options ) { |
|
43 | + global $sd_widgets; |
|
44 | + |
|
45 | + $sd_widgets[ $options['base_id'] ] = array( |
|
46 | + 'name' => $options['name'], |
|
47 | + 'class_name' => $options['class_name'] |
|
48 | + ); |
|
49 | + $this->base_id = $options['base_id']; |
|
50 | + // lets filter the options before we do anything |
|
51 | + $options = apply_filters( "wp_super_duper_options", $options ); |
|
52 | + $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
53 | + $options = $this->add_name_from_key( $options ); |
|
54 | + $this->options = $options; |
|
55 | + |
|
56 | + $this->base_id = $options['base_id']; |
|
57 | + $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
58 | + |
|
59 | + // init parent |
|
60 | + parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
61 | + |
|
62 | + if ( isset( $options['class_name'] ) ) { |
|
63 | + // register widget |
|
64 | + $this->class_name = $options['class_name']; |
|
65 | + |
|
66 | + // register shortcode |
|
67 | + $this->register_shortcode(); |
|
68 | + |
|
69 | + // register block |
|
70 | + add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
71 | + } |
|
72 | + |
|
73 | + // add the CSS and JS we need ONCE |
|
74 | + global $sd_widget_scripts; |
|
75 | + |
|
76 | + if ( ! $sd_widget_scripts ) { |
|
77 | + wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
78 | + wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
79 | + wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
80 | + |
|
81 | + $sd_widget_scripts = true; |
|
82 | + |
|
83 | + // add shortcode insert button once |
|
84 | + add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
85 | + if ( $this->is_preview() ) { |
|
86 | + add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
87 | + // this makes the insert button work for elementor |
|
88 | + add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
89 | + $this, |
|
90 | + 'shortcode_insert_button_script' |
|
91 | + ) ); // for elementor |
|
92 | + } |
|
93 | + // this makes the insert button work for cornerstone |
|
94 | + add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
95 | + |
|
96 | + add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
97 | + add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
98 | + |
|
99 | + // add generator text to admin head |
|
100 | + add_action( 'admin_head', array( $this, 'generator' ) ); |
|
101 | + } |
|
102 | + |
|
103 | + do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
108 | + */ |
|
109 | + public static function maybe_cornerstone_builder(){ |
|
110 | + if(did_action('cornerstone_before_boot_app')){ |
|
111 | + self::shortcode_insert_button_script(); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * A function to ge the shortcode builder picker html. |
|
117 | + * |
|
118 | + * @param string $editor_id |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public static function get_picker( $editor_id = '' ) { |
|
123 | + |
|
124 | + ob_start(); |
|
125 | + if ( isset( $_POST['editor_id'] ) ) { |
|
126 | + $editor_id = esc_attr( $_POST['editor_id'] ); |
|
127 | + } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
128 | + $editor_id = 'main_content_content_vb_tiny_mce'; |
|
129 | + } |
|
130 | + |
|
131 | + global $sd_widgets; |
|
132 | + ?> |
|
133 | 133 | |
134 | 134 | <div class="sd-shortcode-left-wrap"> |
135 | 135 | <?php |
136 | - asort( $sd_widgets ); |
|
137 | - if ( ! empty( $sd_widgets ) ) { |
|
138 | - echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
139 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
140 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
141 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
142 | - } |
|
143 | - echo "</select>"; |
|
144 | - |
|
145 | - } |
|
146 | - ?> |
|
136 | + asort( $sd_widgets ); |
|
137 | + if ( ! empty( $sd_widgets ) ) { |
|
138 | + echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
139 | + echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
140 | + foreach ( $sd_widgets as $shortcode => $class ) { |
|
141 | + echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
142 | + } |
|
143 | + echo "</select>"; |
|
144 | + |
|
145 | + } |
|
146 | + ?> |
|
147 | 147 | <div class="sd-shortcode-settings"></div> |
148 | 148 | |
149 | 149 | </div> |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | <?php if ( $editor_id != '' ) { ?> |
155 | 155 | <button class="button sd-insert-shortcode-button" |
156 | 156 | onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
157 | - echo "'" . $editor_id . "'"; |
|
158 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
157 | + echo "'" . $editor_id . "'"; |
|
158 | + } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
159 | 159 | <?php } ?> |
160 | 160 | <button class="button" |
161 | 161 | onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
@@ -163,129 +163,129 @@ discard block |
||
163 | 163 | </div> |
164 | 164 | <?php |
165 | 165 | |
166 | - $html = ob_get_clean(); |
|
167 | - |
|
168 | - if ( wp_doing_ajax() ) { |
|
169 | - echo $html; |
|
170 | - $should_die = true; |
|
171 | - |
|
172 | - // some builder get the editor via ajax so we should not die on those ocasions |
|
173 | - $dont_die = array( |
|
174 | - 'parent_tag',// WP Bakery |
|
175 | - 'avia_request' // enfold |
|
176 | - ); |
|
177 | - |
|
178 | - foreach ( $dont_die as $request ) { |
|
179 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
180 | - $should_die = false; |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - if ( $should_die ) { |
|
185 | - wp_die(); |
|
186 | - } |
|
187 | - |
|
188 | - } else { |
|
189 | - return $html; |
|
190 | - } |
|
191 | - |
|
192 | - return ''; |
|
193 | - |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Output the version in the admin header. |
|
198 | - */ |
|
199 | - public function generator() { |
|
200 | - echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Get widget settings. |
|
205 | - * |
|
206 | - * @since 1.0.0 |
|
207 | - */ |
|
208 | - public static function get_widget_settings() { |
|
209 | - global $sd_widgets; |
|
210 | - |
|
211 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
212 | - if ( ! $shortcode ) { |
|
213 | - wp_die(); |
|
214 | - } |
|
215 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
216 | - if ( ! $widget_args ) { |
|
217 | - wp_die(); |
|
218 | - } |
|
219 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
220 | - if ( ! $class_name ) { |
|
221 | - wp_die(); |
|
222 | - } |
|
223 | - |
|
224 | - // invoke an instance method |
|
225 | - $widget = new $class_name; |
|
226 | - |
|
227 | - ob_start(); |
|
228 | - $widget->form( array() ); |
|
229 | - $form = ob_get_clean(); |
|
230 | - echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
231 | - echo "<style>" . $widget->widget_css() . "</style>"; |
|
232 | - echo "<script>" . $widget->widget_js() . "</script>"; |
|
233 | - ?> |
|
166 | + $html = ob_get_clean(); |
|
167 | + |
|
168 | + if ( wp_doing_ajax() ) { |
|
169 | + echo $html; |
|
170 | + $should_die = true; |
|
171 | + |
|
172 | + // some builder get the editor via ajax so we should not die on those ocasions |
|
173 | + $dont_die = array( |
|
174 | + 'parent_tag',// WP Bakery |
|
175 | + 'avia_request' // enfold |
|
176 | + ); |
|
177 | + |
|
178 | + foreach ( $dont_die as $request ) { |
|
179 | + if ( isset( $_REQUEST[ $request ] ) ) { |
|
180 | + $should_die = false; |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + if ( $should_die ) { |
|
185 | + wp_die(); |
|
186 | + } |
|
187 | + |
|
188 | + } else { |
|
189 | + return $html; |
|
190 | + } |
|
191 | + |
|
192 | + return ''; |
|
193 | + |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Output the version in the admin header. |
|
198 | + */ |
|
199 | + public function generator() { |
|
200 | + echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Get widget settings. |
|
205 | + * |
|
206 | + * @since 1.0.0 |
|
207 | + */ |
|
208 | + public static function get_widget_settings() { |
|
209 | + global $sd_widgets; |
|
210 | + |
|
211 | + $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
212 | + if ( ! $shortcode ) { |
|
213 | + wp_die(); |
|
214 | + } |
|
215 | + $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
216 | + if ( ! $widget_args ) { |
|
217 | + wp_die(); |
|
218 | + } |
|
219 | + $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
220 | + if ( ! $class_name ) { |
|
221 | + wp_die(); |
|
222 | + } |
|
223 | + |
|
224 | + // invoke an instance method |
|
225 | + $widget = new $class_name; |
|
226 | + |
|
227 | + ob_start(); |
|
228 | + $widget->form( array() ); |
|
229 | + $form = ob_get_clean(); |
|
230 | + echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
231 | + echo "<style>" . $widget->widget_css() . "</style>"; |
|
232 | + echo "<script>" . $widget->widget_js() . "</script>"; |
|
233 | + ?> |
|
234 | 234 | <?php |
235 | - wp_die(); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
240 | - * |
|
241 | - * @since 1.0.0 |
|
242 | - * |
|
243 | - * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
244 | - * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
245 | - */ |
|
246 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
247 | - global $sd_widgets, $shortcode_insert_button_once; |
|
248 | - if ( $shortcode_insert_button_once ) { |
|
249 | - return; |
|
250 | - } |
|
251 | - add_thickbox(); |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Cornerstone makes us play dirty tricks :/ |
|
256 | - * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
|
257 | - */ |
|
258 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
259 | - echo '<span id="insert-media-button">'; |
|
260 | - } |
|
261 | - |
|
262 | - echo self::shortcode_button( 'this', 'true' ); |
|
263 | - |
|
264 | - // see opening note |
|
265 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
266 | - echo '</span>'; // end #insert-media-button |
|
267 | - } |
|
268 | - |
|
269 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
270 | - $shortcode_insert_button_once = true; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Gets the shortcode insert button html. |
|
275 | - * |
|
276 | - * @param string $id |
|
277 | - * @param string $search_for_id |
|
278 | - * |
|
279 | - * @return mixed |
|
280 | - */ |
|
281 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
282 | - ob_start(); |
|
283 | - ?> |
|
235 | + wp_die(); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
240 | + * |
|
241 | + * @since 1.0.0 |
|
242 | + * |
|
243 | + * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
244 | + * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
245 | + */ |
|
246 | + public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
247 | + global $sd_widgets, $shortcode_insert_button_once; |
|
248 | + if ( $shortcode_insert_button_once ) { |
|
249 | + return; |
|
250 | + } |
|
251 | + add_thickbox(); |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Cornerstone makes us play dirty tricks :/ |
|
256 | + * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
|
257 | + */ |
|
258 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
259 | + echo '<span id="insert-media-button">'; |
|
260 | + } |
|
261 | + |
|
262 | + echo self::shortcode_button( 'this', 'true' ); |
|
263 | + |
|
264 | + // see opening note |
|
265 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
266 | + echo '</span>'; // end #insert-media-button |
|
267 | + } |
|
268 | + |
|
269 | + self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
270 | + $shortcode_insert_button_once = true; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Gets the shortcode insert button html. |
|
275 | + * |
|
276 | + * @param string $id |
|
277 | + * @param string $search_for_id |
|
278 | + * |
|
279 | + * @return mixed |
|
280 | + */ |
|
281 | + public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
282 | + ob_start(); |
|
283 | + ?> |
|
284 | 284 | <span class="sd-lable-shortcode-inserter"> |
285 | 285 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
286 | - if ( $search_for_id ) { |
|
287 | - echo "," . $search_for_id; |
|
288 | - } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
286 | + if ( $search_for_id ) { |
|
287 | + echo "," . $search_for_id; |
|
288 | + } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
289 | 289 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
290 | 290 | <span style="vertical-align: middle;line-height: 18px;font-size: 20px;" |
291 | 291 | class="dashicons dashicons-screenoptions"></span> |
@@ -296,21 +296,21 @@ discard block |
||
296 | 296 | </span> |
297 | 297 | |
298 | 298 | <?php |
299 | - $html = ob_get_clean(); |
|
300 | - |
|
301 | - // remove line breaks so we can use it in js |
|
302 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Makes SD work with the siteOrigin page builder. |
|
307 | - * |
|
308 | - * @since 1.0.6 |
|
309 | - * @return mixed |
|
310 | - */ |
|
311 | - public static function siteorigin_js() { |
|
312 | - ob_start(); |
|
313 | - ?> |
|
299 | + $html = ob_get_clean(); |
|
300 | + |
|
301 | + // remove line breaks so we can use it in js |
|
302 | + return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Makes SD work with the siteOrigin page builder. |
|
307 | + * |
|
308 | + * @since 1.0.6 |
|
309 | + * @return mixed |
|
310 | + */ |
|
311 | + public static function siteorigin_js() { |
|
312 | + ob_start(); |
|
313 | + ?> |
|
314 | 314 | <script> |
315 | 315 | /** |
316 | 316 | * Check a form to see what items shoudl be shown or hidden. |
@@ -388,28 +388,28 @@ discard block |
||
388 | 388 | }); |
389 | 389 | </script> |
390 | 390 | <?php |
391 | - $output = ob_get_clean(); |
|
391 | + $output = ob_get_clean(); |
|
392 | 392 | |
393 | - /* |
|
393 | + /* |
|
394 | 394 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
395 | 395 | */ |
396 | 396 | |
397 | - return str_replace( array( |
|
398 | - '<script>', |
|
399 | - '</script>' |
|
400 | - ), '', $output ); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Output the JS and CSS for the shortcode insert button. |
|
405 | - * |
|
406 | - * @since 1.0.6 |
|
407 | - * |
|
408 | - * @param string $editor_id |
|
409 | - * @param string $insert_shortcode_function |
|
410 | - */ |
|
411 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
412 | - ?> |
|
397 | + return str_replace( array( |
|
398 | + '<script>', |
|
399 | + '</script>' |
|
400 | + ), '', $output ); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Output the JS and CSS for the shortcode insert button. |
|
405 | + * |
|
406 | + * @since 1.0.6 |
|
407 | + * |
|
408 | + * @param string $editor_id |
|
409 | + * @param string $insert_shortcode_function |
|
410 | + */ |
|
411 | + public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
412 | + ?> |
|
413 | 413 | <style> |
414 | 414 | .sd-shortcode-left-wrap { |
415 | 415 | float: left; |
@@ -528,22 +528,22 @@ discard block |
||
528 | 528 | } |
529 | 529 | </style> |
530 | 530 | <?php |
531 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
532 | - echo "<script>" . self::siteorigin_js() . "</script>"; |
|
533 | - } |
|
534 | - ?> |
|
531 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
532 | + echo "<script>" . self::siteorigin_js() . "</script>"; |
|
533 | + } |
|
534 | + ?> |
|
535 | 535 | <script> |
536 | 536 | <?php |
537 | - if(! empty( $insert_shortcode_function )){ |
|
538 | - echo $insert_shortcode_function; |
|
539 | - }else{ |
|
540 | - |
|
541 | - /** |
|
542 | - * Function for super duper insert shortcode. |
|
543 | - * |
|
544 | - * @since 1.0.0 |
|
545 | - */ |
|
546 | - ?> |
|
537 | + if(! empty( $insert_shortcode_function )){ |
|
538 | + echo $insert_shortcode_function; |
|
539 | + }else{ |
|
540 | + |
|
541 | + /** |
|
542 | + * Function for super duper insert shortcode. |
|
543 | + * |
|
544 | + * @since 1.0.0 |
|
545 | + */ |
|
546 | + ?> |
|
547 | 547 | function sd_insert_shortcode($editor_id) { |
548 | 548 | $shortcode = jQuery('#TB_ajaxContent #sd-shortcode-output').val(); |
549 | 549 | if ($shortcode) { |
@@ -551,14 +551,14 @@ discard block |
||
551 | 551 | if (!$editor_id) { |
552 | 552 | |
553 | 553 | <?php |
554 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
555 | - echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
556 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
557 | - echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
558 | - } else { |
|
559 | - echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
560 | - } |
|
561 | - ?> |
|
554 | + if ( isset( $_REQUEST['et_fb'] ) ) { |
|
555 | + echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
556 | + } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
557 | + echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
558 | + } else { |
|
559 | + echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
560 | + } |
|
561 | + ?> |
|
562 | 562 | } else { |
563 | 563 | $editor_id = '#' + $editor_id; |
564 | 564 | } |
@@ -868,16 +868,16 @@ discard block |
||
868 | 868 | |
869 | 869 | </script> |
870 | 870 | <?php |
871 | - } |
|
872 | - |
|
873 | - /** |
|
874 | - * Gets some CSS for the widgets screen. |
|
875 | - * |
|
876 | - * @return mixed |
|
877 | - */ |
|
878 | - public function widget_css() { |
|
879 | - ob_start(); |
|
880 | - ?> |
|
871 | + } |
|
872 | + |
|
873 | + /** |
|
874 | + * Gets some CSS for the widgets screen. |
|
875 | + * |
|
876 | + * @return mixed |
|
877 | + */ |
|
878 | + public function widget_css() { |
|
879 | + ob_start(); |
|
880 | + ?> |
|
881 | 881 | <style> |
882 | 882 | .sd-advanced-setting { |
883 | 883 | display: none; |
@@ -898,26 +898,26 @@ discard block |
||
898 | 898 | } |
899 | 899 | </style> |
900 | 900 | <?php |
901 | - $output = ob_get_clean(); |
|
901 | + $output = ob_get_clean(); |
|
902 | 902 | |
903 | - /* |
|
903 | + /* |
|
904 | 904 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
905 | 905 | */ |
906 | 906 | |
907 | - return str_replace( array( |
|
908 | - '<style>', |
|
909 | - '</style>' |
|
910 | - ), '', $output ); |
|
911 | - } |
|
912 | - |
|
913 | - /** |
|
914 | - * Gets some JS for the widgets screen. |
|
915 | - * |
|
916 | - * @return mixed |
|
917 | - */ |
|
918 | - public function widget_js() { |
|
919 | - ob_start(); |
|
920 | - ?> |
|
907 | + return str_replace( array( |
|
908 | + '<style>', |
|
909 | + '</style>' |
|
910 | + ), '', $output ); |
|
911 | + } |
|
912 | + |
|
913 | + /** |
|
914 | + * Gets some JS for the widgets screen. |
|
915 | + * |
|
916 | + * @return mixed |
|
917 | + */ |
|
918 | + public function widget_js() { |
|
919 | + ob_start(); |
|
920 | + ?> |
|
921 | 921 | <script> |
922 | 922 | |
923 | 923 | /** |
@@ -1072,307 +1072,307 @@ discard block |
||
1072 | 1072 | <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
1073 | 1073 | </script> |
1074 | 1074 | <?php |
1075 | - $output = ob_get_clean(); |
|
1075 | + $output = ob_get_clean(); |
|
1076 | 1076 | |
1077 | - /* |
|
1077 | + /* |
|
1078 | 1078 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1079 | 1079 | */ |
1080 | 1080 | |
1081 | - return str_replace( array( |
|
1082 | - '<script>', |
|
1083 | - '</script>' |
|
1084 | - ), '', $output ); |
|
1085 | - } |
|
1086 | - |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * Set the name from the argument key. |
|
1090 | - * |
|
1091 | - * @param $options |
|
1092 | - * |
|
1093 | - * @return mixed |
|
1094 | - */ |
|
1095 | - private function add_name_from_key( $options, $arguments = false ) { |
|
1096 | - if ( ! empty( $options['arguments'] ) ) { |
|
1097 | - foreach ( $options['arguments'] as $key => $val ) { |
|
1098 | - $options['arguments'][ $key ]['name'] = $key; |
|
1099 | - } |
|
1100 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
1101 | - foreach ( $options as $key => $val ) { |
|
1102 | - $options[ $key ]['name'] = $key; |
|
1103 | - } |
|
1104 | - } |
|
1105 | - |
|
1106 | - return $options; |
|
1107 | - } |
|
1108 | - |
|
1109 | - /** |
|
1110 | - * Register the parent shortcode. |
|
1111 | - * |
|
1112 | - * @since 1.0.0 |
|
1113 | - */ |
|
1114 | - public function register_shortcode() { |
|
1115 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
1116 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
1117 | - } |
|
1118 | - |
|
1119 | - /** |
|
1120 | - * Render the shortcode via ajax so we can return it to Gutenberg. |
|
1121 | - * |
|
1122 | - * @since 1.0.0 |
|
1123 | - */ |
|
1124 | - public static function render_shortcode() { |
|
1125 | - |
|
1126 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
1127 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1128 | - wp_die(); |
|
1129 | - } |
|
1130 | - |
|
1131 | - // we might need the $post value here so lets set it. |
|
1132 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
1133 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
1134 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
1135 | - global $post; |
|
1136 | - $post = $post_obj; |
|
1137 | - } |
|
1138 | - } |
|
1139 | - |
|
1140 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
1141 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
1142 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
1143 | - $attributes = ''; |
|
1144 | - if ( ! empty( $attributes_array ) ) { |
|
1145 | - foreach ( $attributes_array as $key => $value ) { |
|
1146 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
1147 | - } |
|
1148 | - } |
|
1149 | - |
|
1150 | - $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
1151 | - |
|
1152 | - echo do_shortcode( $shortcode ); |
|
1153 | - |
|
1154 | - } |
|
1155 | - wp_die(); |
|
1156 | - } |
|
1157 | - |
|
1158 | - /** |
|
1159 | - * Output the shortcode. |
|
1160 | - * |
|
1161 | - * @param array $args |
|
1162 | - * @param string $content |
|
1163 | - * |
|
1164 | - * @return string |
|
1165 | - */ |
|
1166 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
1167 | - $args = self::argument_values( $args ); |
|
1168 | - |
|
1169 | - // add extra argument so we know its a output to gutenberg |
|
1170 | - //$args |
|
1171 | - $args = $this->string_to_bool( $args ); |
|
1172 | - |
|
1173 | - |
|
1174 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
1175 | - |
|
1176 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
1177 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
1178 | - |
|
1179 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
1180 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
1181 | - |
|
1182 | - $shortcode_args = array(); |
|
1183 | - $output = ''; |
|
1184 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
1185 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
1186 | - if ( $main_content && ! $no_wrap ) { |
|
1187 | - // wrap the shortcode in a dive with the same class as the widget |
|
1188 | - $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
1189 | - if ( ! empty( $args['title'] ) ) { |
|
1190 | - // if its a shortcode and there is a title try to grab the title wrappers |
|
1191 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
1192 | - if ( empty( $instance ) ) { |
|
1193 | - global $wp_registered_sidebars; |
|
1194 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
1195 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
1196 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
1197 | - $shortcode_args['before_title'] = $sidebar['before_title']; |
|
1198 | - $shortcode_args['after_title'] = $sidebar['after_title']; |
|
1199 | - break; |
|
1200 | - } |
|
1201 | - } |
|
1202 | - } |
|
1203 | - } |
|
1204 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
1205 | - } |
|
1206 | - $output .= $main_content; |
|
1207 | - $output .= '</div>'; |
|
1208 | - } elseif ( $main_content && $no_wrap ) { |
|
1209 | - $output .= $main_content; |
|
1210 | - } |
|
1211 | - |
|
1212 | - // if preview show a placeholder if empty |
|
1213 | - if ( $this->is_preview() && $output == '' ) { |
|
1214 | - $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
1215 | - } |
|
1216 | - |
|
1217 | - return $output; |
|
1218 | - } |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
1222 | - * |
|
1223 | - * @param string $name |
|
1224 | - * |
|
1225 | - * @return string |
|
1226 | - */ |
|
1227 | - public function preview_placeholder_text( $name = '' ) { |
|
1228 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
1229 | - } |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * Sometimes booleans values can be turned to strings, so we fix that. |
|
1233 | - * |
|
1234 | - * @param $options |
|
1235 | - * |
|
1236 | - * @return mixed |
|
1237 | - */ |
|
1238 | - public function string_to_bool( $options ) { |
|
1239 | - // convert bool strings to booleans |
|
1240 | - foreach ( $options as $key => $val ) { |
|
1241 | - if ( $val == 'false' ) { |
|
1242 | - $options[ $key ] = false; |
|
1243 | - } elseif ( $val == 'true' ) { |
|
1244 | - $options[ $key ] = true; |
|
1245 | - } |
|
1246 | - } |
|
1247 | - |
|
1248 | - return $options; |
|
1249 | - } |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * Get the argument values that are also filterable. |
|
1253 | - * |
|
1254 | - * @param $instance |
|
1255 | - * |
|
1256 | - * @since 1.0.12 Don't set checkbox default value if the value is empty. |
|
1257 | - * |
|
1258 | - * @return array |
|
1259 | - */ |
|
1260 | - public function argument_values( $instance ) { |
|
1261 | - $argument_values = array(); |
|
1262 | - |
|
1263 | - // set widget instance |
|
1264 | - $this->instance = $instance; |
|
1265 | - |
|
1266 | - if ( empty( $this->arguments ) ) { |
|
1267 | - $this->arguments = $this->get_arguments(); |
|
1268 | - } |
|
1269 | - |
|
1270 | - if ( ! empty( $this->arguments ) ) { |
|
1271 | - foreach ( $this->arguments as $key => $args ) { |
|
1272 | - // set the input name from the key |
|
1273 | - $args['name'] = $key; |
|
1274 | - // |
|
1275 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
1276 | - if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
1277 | - // don't set default for an empty checkbox |
|
1278 | - } |
|
1279 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1280 | - $argument_values[ $key ] = $args['default']; |
|
1281 | - } |
|
1282 | - } |
|
1283 | - } |
|
1284 | - |
|
1285 | - return $argument_values; |
|
1286 | - } |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * Set arguments in super duper. |
|
1290 | - * |
|
1291 | - * @since 1.0.0 |
|
1292 | - * |
|
1293 | - * @return array Set arguments. |
|
1294 | - */ |
|
1295 | - public function set_arguments() { |
|
1296 | - return $this->arguments; |
|
1297 | - } |
|
1298 | - |
|
1299 | - /** |
|
1300 | - * Get arguments in super duper. |
|
1301 | - * |
|
1302 | - * @since 1.0.0 |
|
1303 | - * |
|
1304 | - * @return array Get arguments. |
|
1305 | - */ |
|
1306 | - public function get_arguments() { |
|
1307 | - if ( empty( $this->arguments ) ) { |
|
1308 | - $this->arguments = $this->set_arguments(); |
|
1309 | - } |
|
1310 | - |
|
1311 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
1312 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
1313 | - |
|
1314 | - return $this->arguments; |
|
1315 | - } |
|
1316 | - |
|
1317 | - /** |
|
1318 | - * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
1319 | - * |
|
1320 | - * @param array $args |
|
1321 | - * @param array $widget_args |
|
1322 | - * @param string $content |
|
1323 | - */ |
|
1324 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
1325 | - |
|
1326 | - } |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Add the dynamic block code inline when the wp-block in enqueued. |
|
1330 | - */ |
|
1331 | - public function register_block() { |
|
1332 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
1333 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
1334 | - |
|
1335 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
1336 | - |
|
1337 | - } |
|
1338 | - } |
|
1339 | - |
|
1340 | - /** |
|
1341 | - * Check if we need to show advanced options. |
|
1342 | - * |
|
1343 | - * @return bool |
|
1344 | - */ |
|
1345 | - public function block_show_advanced() { |
|
1346 | - |
|
1347 | - $show = false; |
|
1348 | - $arguments = $this->arguments; |
|
1349 | - |
|
1350 | - if ( empty( $arguments ) ) { |
|
1351 | - $arguments = $this->get_arguments(); |
|
1352 | - } |
|
1353 | - |
|
1354 | - if ( ! empty( $arguments ) ) { |
|
1355 | - foreach ( $arguments as $argument ) { |
|
1356 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
1357 | - $show = true; |
|
1358 | - } |
|
1359 | - } |
|
1360 | - } |
|
1361 | - |
|
1362 | - return $show; |
|
1363 | - } |
|
1364 | - |
|
1365 | - |
|
1366 | - /** |
|
1367 | - * Output the JS for building the dynamic Guntenberg block. |
|
1368 | - * |
|
1369 | - * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
|
1370 | - * @since 1.0.9 Save numbers as numbers and not strings. |
|
1371 | - * @return mixed |
|
1372 | - */ |
|
1373 | - public function block() { |
|
1374 | - ob_start(); |
|
1375 | - ?> |
|
1081 | + return str_replace( array( |
|
1082 | + '<script>', |
|
1083 | + '</script>' |
|
1084 | + ), '', $output ); |
|
1085 | + } |
|
1086 | + |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * Set the name from the argument key. |
|
1090 | + * |
|
1091 | + * @param $options |
|
1092 | + * |
|
1093 | + * @return mixed |
|
1094 | + */ |
|
1095 | + private function add_name_from_key( $options, $arguments = false ) { |
|
1096 | + if ( ! empty( $options['arguments'] ) ) { |
|
1097 | + foreach ( $options['arguments'] as $key => $val ) { |
|
1098 | + $options['arguments'][ $key ]['name'] = $key; |
|
1099 | + } |
|
1100 | + } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
1101 | + foreach ( $options as $key => $val ) { |
|
1102 | + $options[ $key ]['name'] = $key; |
|
1103 | + } |
|
1104 | + } |
|
1105 | + |
|
1106 | + return $options; |
|
1107 | + } |
|
1108 | + |
|
1109 | + /** |
|
1110 | + * Register the parent shortcode. |
|
1111 | + * |
|
1112 | + * @since 1.0.0 |
|
1113 | + */ |
|
1114 | + public function register_shortcode() { |
|
1115 | + add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
1116 | + add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
1117 | + } |
|
1118 | + |
|
1119 | + /** |
|
1120 | + * Render the shortcode via ajax so we can return it to Gutenberg. |
|
1121 | + * |
|
1122 | + * @since 1.0.0 |
|
1123 | + */ |
|
1124 | + public static function render_shortcode() { |
|
1125 | + |
|
1126 | + check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
1127 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
1128 | + wp_die(); |
|
1129 | + } |
|
1130 | + |
|
1131 | + // we might need the $post value here so lets set it. |
|
1132 | + if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
1133 | + $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
1134 | + if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
1135 | + global $post; |
|
1136 | + $post = $post_obj; |
|
1137 | + } |
|
1138 | + } |
|
1139 | + |
|
1140 | + if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
1141 | + $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
1142 | + $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
1143 | + $attributes = ''; |
|
1144 | + if ( ! empty( $attributes_array ) ) { |
|
1145 | + foreach ( $attributes_array as $key => $value ) { |
|
1146 | + $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
1147 | + } |
|
1148 | + } |
|
1149 | + |
|
1150 | + $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
1151 | + |
|
1152 | + echo do_shortcode( $shortcode ); |
|
1153 | + |
|
1154 | + } |
|
1155 | + wp_die(); |
|
1156 | + } |
|
1157 | + |
|
1158 | + /** |
|
1159 | + * Output the shortcode. |
|
1160 | + * |
|
1161 | + * @param array $args |
|
1162 | + * @param string $content |
|
1163 | + * |
|
1164 | + * @return string |
|
1165 | + */ |
|
1166 | + public function shortcode_output( $args = array(), $content = '' ) { |
|
1167 | + $args = self::argument_values( $args ); |
|
1168 | + |
|
1169 | + // add extra argument so we know its a output to gutenberg |
|
1170 | + //$args |
|
1171 | + $args = $this->string_to_bool( $args ); |
|
1172 | + |
|
1173 | + |
|
1174 | + $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
1175 | + |
|
1176 | + $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
1177 | + $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
1178 | + |
|
1179 | + $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
1180 | + $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
1181 | + |
|
1182 | + $shortcode_args = array(); |
|
1183 | + $output = ''; |
|
1184 | + $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
1185 | + $main_content = $this->output( $args, $shortcode_args, $content ); |
|
1186 | + if ( $main_content && ! $no_wrap ) { |
|
1187 | + // wrap the shortcode in a dive with the same class as the widget |
|
1188 | + $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
1189 | + if ( ! empty( $args['title'] ) ) { |
|
1190 | + // if its a shortcode and there is a title try to grab the title wrappers |
|
1191 | + $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
1192 | + if ( empty( $instance ) ) { |
|
1193 | + global $wp_registered_sidebars; |
|
1194 | + if ( ! empty( $wp_registered_sidebars ) ) { |
|
1195 | + foreach ( $wp_registered_sidebars as $sidebar ) { |
|
1196 | + if ( ! empty( $sidebar['before_title'] ) ) { |
|
1197 | + $shortcode_args['before_title'] = $sidebar['before_title']; |
|
1198 | + $shortcode_args['after_title'] = $sidebar['after_title']; |
|
1199 | + break; |
|
1200 | + } |
|
1201 | + } |
|
1202 | + } |
|
1203 | + } |
|
1204 | + $output .= $this->output_title( $shortcode_args, $args ); |
|
1205 | + } |
|
1206 | + $output .= $main_content; |
|
1207 | + $output .= '</div>'; |
|
1208 | + } elseif ( $main_content && $no_wrap ) { |
|
1209 | + $output .= $main_content; |
|
1210 | + } |
|
1211 | + |
|
1212 | + // if preview show a placeholder if empty |
|
1213 | + if ( $this->is_preview() && $output == '' ) { |
|
1214 | + $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
1215 | + } |
|
1216 | + |
|
1217 | + return $output; |
|
1218 | + } |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
1222 | + * |
|
1223 | + * @param string $name |
|
1224 | + * |
|
1225 | + * @return string |
|
1226 | + */ |
|
1227 | + public function preview_placeholder_text( $name = '' ) { |
|
1228 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
1229 | + } |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * Sometimes booleans values can be turned to strings, so we fix that. |
|
1233 | + * |
|
1234 | + * @param $options |
|
1235 | + * |
|
1236 | + * @return mixed |
|
1237 | + */ |
|
1238 | + public function string_to_bool( $options ) { |
|
1239 | + // convert bool strings to booleans |
|
1240 | + foreach ( $options as $key => $val ) { |
|
1241 | + if ( $val == 'false' ) { |
|
1242 | + $options[ $key ] = false; |
|
1243 | + } elseif ( $val == 'true' ) { |
|
1244 | + $options[ $key ] = true; |
|
1245 | + } |
|
1246 | + } |
|
1247 | + |
|
1248 | + return $options; |
|
1249 | + } |
|
1250 | + |
|
1251 | + /** |
|
1252 | + * Get the argument values that are also filterable. |
|
1253 | + * |
|
1254 | + * @param $instance |
|
1255 | + * |
|
1256 | + * @since 1.0.12 Don't set checkbox default value if the value is empty. |
|
1257 | + * |
|
1258 | + * @return array |
|
1259 | + */ |
|
1260 | + public function argument_values( $instance ) { |
|
1261 | + $argument_values = array(); |
|
1262 | + |
|
1263 | + // set widget instance |
|
1264 | + $this->instance = $instance; |
|
1265 | + |
|
1266 | + if ( empty( $this->arguments ) ) { |
|
1267 | + $this->arguments = $this->get_arguments(); |
|
1268 | + } |
|
1269 | + |
|
1270 | + if ( ! empty( $this->arguments ) ) { |
|
1271 | + foreach ( $this->arguments as $key => $args ) { |
|
1272 | + // set the input name from the key |
|
1273 | + $args['name'] = $key; |
|
1274 | + // |
|
1275 | + $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
1276 | + if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
1277 | + // don't set default for an empty checkbox |
|
1278 | + } |
|
1279 | + elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1280 | + $argument_values[ $key ] = $args['default']; |
|
1281 | + } |
|
1282 | + } |
|
1283 | + } |
|
1284 | + |
|
1285 | + return $argument_values; |
|
1286 | + } |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * Set arguments in super duper. |
|
1290 | + * |
|
1291 | + * @since 1.0.0 |
|
1292 | + * |
|
1293 | + * @return array Set arguments. |
|
1294 | + */ |
|
1295 | + public function set_arguments() { |
|
1296 | + return $this->arguments; |
|
1297 | + } |
|
1298 | + |
|
1299 | + /** |
|
1300 | + * Get arguments in super duper. |
|
1301 | + * |
|
1302 | + * @since 1.0.0 |
|
1303 | + * |
|
1304 | + * @return array Get arguments. |
|
1305 | + */ |
|
1306 | + public function get_arguments() { |
|
1307 | + if ( empty( $this->arguments ) ) { |
|
1308 | + $this->arguments = $this->set_arguments(); |
|
1309 | + } |
|
1310 | + |
|
1311 | + $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
1312 | + $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
1313 | + |
|
1314 | + return $this->arguments; |
|
1315 | + } |
|
1316 | + |
|
1317 | + /** |
|
1318 | + * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
1319 | + * |
|
1320 | + * @param array $args |
|
1321 | + * @param array $widget_args |
|
1322 | + * @param string $content |
|
1323 | + */ |
|
1324 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
1325 | + |
|
1326 | + } |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Add the dynamic block code inline when the wp-block in enqueued. |
|
1330 | + */ |
|
1331 | + public function register_block() { |
|
1332 | + wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
1333 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
1334 | + |
|
1335 | + wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
1336 | + |
|
1337 | + } |
|
1338 | + } |
|
1339 | + |
|
1340 | + /** |
|
1341 | + * Check if we need to show advanced options. |
|
1342 | + * |
|
1343 | + * @return bool |
|
1344 | + */ |
|
1345 | + public function block_show_advanced() { |
|
1346 | + |
|
1347 | + $show = false; |
|
1348 | + $arguments = $this->arguments; |
|
1349 | + |
|
1350 | + if ( empty( $arguments ) ) { |
|
1351 | + $arguments = $this->get_arguments(); |
|
1352 | + } |
|
1353 | + |
|
1354 | + if ( ! empty( $arguments ) ) { |
|
1355 | + foreach ( $arguments as $argument ) { |
|
1356 | + if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
1357 | + $show = true; |
|
1358 | + } |
|
1359 | + } |
|
1360 | + } |
|
1361 | + |
|
1362 | + return $show; |
|
1363 | + } |
|
1364 | + |
|
1365 | + |
|
1366 | + /** |
|
1367 | + * Output the JS for building the dynamic Guntenberg block. |
|
1368 | + * |
|
1369 | + * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
|
1370 | + * @since 1.0.9 Save numbers as numbers and not strings. |
|
1371 | + * @return mixed |
|
1372 | + */ |
|
1373 | + public function block() { |
|
1374 | + ob_start(); |
|
1375 | + ?> |
|
1376 | 1376 | <script> |
1377 | 1377 | /** |
1378 | 1378 | * BLOCK: Basic |
@@ -1411,76 +1411,76 @@ discard block |
||
1411 | 1411 | icon: '<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
1412 | 1412 | category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
1413 | 1413 | <?php if ( isset( $this->options['block-keywords'] ) ) { |
1414 | - echo "keywords : " . $this->options['block-keywords'] . ","; |
|
1415 | - }?> |
|
1414 | + echo "keywords : " . $this->options['block-keywords'] . ","; |
|
1415 | + }?> |
|
1416 | 1416 | |
1417 | 1417 | <?php |
1418 | 1418 | |
1419 | - $show_advanced = $this->block_show_advanced(); |
|
1420 | - |
|
1421 | - $show_alignment = false; |
|
1422 | - |
|
1423 | - if ( ! empty( $this->arguments ) ) { |
|
1424 | - echo "attributes : {"; |
|
1425 | - |
|
1426 | - if ( $show_advanced ) { |
|
1427 | - echo "show_advanced: {"; |
|
1428 | - echo " type: 'boolean',"; |
|
1429 | - echo " default: false,"; |
|
1430 | - echo "},"; |
|
1431 | - } |
|
1432 | - |
|
1433 | - // block wrap element |
|
1434 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
1435 | - echo "block_wrap: {"; |
|
1436 | - echo " type: 'string',"; |
|
1437 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
1438 | - echo "},"; |
|
1439 | - } |
|
1440 | - |
|
1441 | - |
|
1442 | - foreach ( $this->arguments as $key => $args ) { |
|
1443 | - |
|
1444 | - // set if we should show alignment |
|
1445 | - if ( $key == 'alignment' ) { |
|
1446 | - $show_alignment = true; |
|
1447 | - } |
|
1448 | - |
|
1449 | - $extra = ''; |
|
1450 | - |
|
1451 | - if ( $args['type'] == 'checkbox' ) { |
|
1452 | - $type = 'boolean'; |
|
1453 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
1454 | - } elseif ( $args['type'] == 'number' ) { |
|
1455 | - $type = 'number'; |
|
1456 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1457 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
1458 | - $type = 'array'; |
|
1459 | - if ( is_array( $args['default'] ) ) { |
|
1460 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
1461 | - } else { |
|
1462 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1463 | - } |
|
1464 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
1465 | - $type = 'array'; |
|
1466 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1467 | - } else { |
|
1468 | - $type = 'string'; |
|
1469 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1470 | - } |
|
1471 | - echo $key . " : {"; |
|
1472 | - echo "type : '$type',"; |
|
1473 | - echo "default : $default,"; |
|
1474 | - echo "},"; |
|
1475 | - } |
|
1476 | - |
|
1477 | - echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
1478 | - |
|
1479 | - echo "},"; |
|
1480 | - |
|
1481 | - } |
|
1482 | - |
|
1483 | - ?> |
|
1419 | + $show_advanced = $this->block_show_advanced(); |
|
1420 | + |
|
1421 | + $show_alignment = false; |
|
1422 | + |
|
1423 | + if ( ! empty( $this->arguments ) ) { |
|
1424 | + echo "attributes : {"; |
|
1425 | + |
|
1426 | + if ( $show_advanced ) { |
|
1427 | + echo "show_advanced: {"; |
|
1428 | + echo " type: 'boolean',"; |
|
1429 | + echo " default: false,"; |
|
1430 | + echo "},"; |
|
1431 | + } |
|
1432 | + |
|
1433 | + // block wrap element |
|
1434 | + if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
1435 | + echo "block_wrap: {"; |
|
1436 | + echo " type: 'string',"; |
|
1437 | + echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
1438 | + echo "},"; |
|
1439 | + } |
|
1440 | + |
|
1441 | + |
|
1442 | + foreach ( $this->arguments as $key => $args ) { |
|
1443 | + |
|
1444 | + // set if we should show alignment |
|
1445 | + if ( $key == 'alignment' ) { |
|
1446 | + $show_alignment = true; |
|
1447 | + } |
|
1448 | + |
|
1449 | + $extra = ''; |
|
1450 | + |
|
1451 | + if ( $args['type'] == 'checkbox' ) { |
|
1452 | + $type = 'boolean'; |
|
1453 | + $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
1454 | + } elseif ( $args['type'] == 'number' ) { |
|
1455 | + $type = 'number'; |
|
1456 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1457 | + } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
1458 | + $type = 'array'; |
|
1459 | + if ( is_array( $args['default'] ) ) { |
|
1460 | + $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
1461 | + } else { |
|
1462 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1463 | + } |
|
1464 | + } elseif ( $args['type'] == 'multiselect' ) { |
|
1465 | + $type = 'array'; |
|
1466 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1467 | + } else { |
|
1468 | + $type = 'string'; |
|
1469 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1470 | + } |
|
1471 | + echo $key . " : {"; |
|
1472 | + echo "type : '$type',"; |
|
1473 | + echo "default : $default,"; |
|
1474 | + echo "},"; |
|
1475 | + } |
|
1476 | + |
|
1477 | + echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
1478 | + |
|
1479 | + echo "},"; |
|
1480 | + |
|
1481 | + } |
|
1482 | + |
|
1483 | + ?> |
|
1484 | 1484 | |
1485 | 1485 | // The "edit" property must be a valid function. |
1486 | 1486 | edit: function (props) { |
@@ -1499,8 +1499,8 @@ discard block |
||
1499 | 1499 | 'shortcode': '<?php echo $this->options['base_id'];?>', |
1500 | 1500 | 'attributes': props.attributes, |
1501 | 1501 | 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
1502 | - echo $post->ID; |
|
1503 | - }?>, |
|
1502 | + echo $post->ID; |
|
1503 | + }?>, |
|
1504 | 1504 | '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
1505 | 1505 | }; |
1506 | 1506 | |
@@ -1547,10 +1547,10 @@ discard block |
||
1547 | 1547 | |
1548 | 1548 | <?php |
1549 | 1549 | |
1550 | - if(! empty( $this->arguments )){ |
|
1550 | + if(! empty( $this->arguments )){ |
|
1551 | 1551 | |
1552 | - if ( $show_advanced ) { |
|
1553 | - ?> |
|
1552 | + if ( $show_advanced ) { |
|
1553 | + ?> |
|
1554 | 1554 | el( |
1555 | 1555 | wp.components.ToggleControl, |
1556 | 1556 | { |
@@ -1563,73 +1563,73 @@ discard block |
||
1563 | 1563 | ), |
1564 | 1564 | <?php |
1565 | 1565 | |
1566 | - } |
|
1567 | - |
|
1568 | - foreach($this->arguments as $key => $args){ |
|
1569 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
1570 | - $options = ''; |
|
1571 | - $extra = ''; |
|
1572 | - $require = ''; |
|
1573 | - $onchange = "props.setAttributes({ $key: $key } )"; |
|
1574 | - $value = "props.attributes.$key"; |
|
1575 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
1576 | - if ( in_array( $args['type'], $text_type ) ) { |
|
1577 | - $type = 'TextControl'; |
|
1578 | - // Save numbers as numbers and not strings |
|
1579 | - if ( $args['type'] == 'number' ) { |
|
1580 | - $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
1581 | - } |
|
1582 | - } |
|
1566 | + } |
|
1567 | + |
|
1568 | + foreach($this->arguments as $key => $args){ |
|
1569 | + $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
1570 | + $options = ''; |
|
1571 | + $extra = ''; |
|
1572 | + $require = ''; |
|
1573 | + $onchange = "props.setAttributes({ $key: $key } )"; |
|
1574 | + $value = "props.attributes.$key"; |
|
1575 | + $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
1576 | + if ( in_array( $args['type'], $text_type ) ) { |
|
1577 | + $type = 'TextControl'; |
|
1578 | + // Save numbers as numbers and not strings |
|
1579 | + if ( $args['type'] == 'number' ) { |
|
1580 | + $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
1581 | + } |
|
1582 | + } |
|
1583 | 1583 | // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we may have to add our own https://github.com/WordPress/gutenberg/issues/14378 |
1584 | 1584 | // $type = 'ColorPicker'; |
1585 | 1585 | // } |
1586 | - elseif ( $args['type'] == 'checkbox' ) { |
|
1587 | - $type = 'CheckboxControl'; |
|
1588 | - $extra .= "checked: props.attributes.$key,"; |
|
1589 | - $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
1590 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
1591 | - $type = 'SelectControl'; |
|
1592 | - if ( ! empty( $args['options'] ) ) { |
|
1593 | - $options .= "options : ["; |
|
1594 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
1595 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
1596 | - } |
|
1597 | - $options .= "],"; |
|
1598 | - } |
|
1599 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
1600 | - $extra .= ' multiple: true, '; |
|
1601 | - //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
1602 | - //$value = "['edit', 'delete']"; |
|
1603 | - } |
|
1604 | - } elseif ( $args['type'] == 'alignment' ) { |
|
1605 | - $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
1606 | - } else { |
|
1607 | - continue;// if we have not implemented the control then don't break the JS. |
|
1608 | - } |
|
1609 | - |
|
1610 | - // add show only if advanced |
|
1611 | - if ( ! empty( $args['advanced'] ) ) { |
|
1612 | - echo "props.attributes.show_advanced && "; |
|
1613 | - } |
|
1614 | - // add setting require if defined |
|
1615 | - if ( ! empty( $args['element_require'] ) ) { |
|
1616 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
1617 | - } |
|
1618 | - ?> |
|
1586 | + elseif ( $args['type'] == 'checkbox' ) { |
|
1587 | + $type = 'CheckboxControl'; |
|
1588 | + $extra .= "checked: props.attributes.$key,"; |
|
1589 | + $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
1590 | + } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
1591 | + $type = 'SelectControl'; |
|
1592 | + if ( ! empty( $args['options'] ) ) { |
|
1593 | + $options .= "options : ["; |
|
1594 | + foreach ( $args['options'] as $option_val => $option_label ) { |
|
1595 | + $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
1596 | + } |
|
1597 | + $options .= "],"; |
|
1598 | + } |
|
1599 | + if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
1600 | + $extra .= ' multiple: true, '; |
|
1601 | + //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
1602 | + //$value = "['edit', 'delete']"; |
|
1603 | + } |
|
1604 | + } elseif ( $args['type'] == 'alignment' ) { |
|
1605 | + $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
1606 | + } else { |
|
1607 | + continue;// if we have not implemented the control then don't break the JS. |
|
1608 | + } |
|
1609 | + |
|
1610 | + // add show only if advanced |
|
1611 | + if ( ! empty( $args['advanced'] ) ) { |
|
1612 | + echo "props.attributes.show_advanced && "; |
|
1613 | + } |
|
1614 | + // add setting require if defined |
|
1615 | + if ( ! empty( $args['element_require'] ) ) { |
|
1616 | + echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
1617 | + } |
|
1618 | + ?> |
|
1619 | 1619 | el( |
1620 | 1620 | wp.components.<?php echo esc_attr( $type );?>, |
1621 | 1621 | { |
1622 | 1622 | label: '<?php echo esc_attr( $args['title'] );?>', |
1623 | 1623 | help: '<?php if ( isset( $args['desc'] ) ) { |
1624 | - echo esc_attr( $args['desc'] ); |
|
1625 | - }?>', |
|
1624 | + echo esc_attr( $args['desc'] ); |
|
1625 | + }?>', |
|
1626 | 1626 | value: <?php echo $value;?>, |
1627 | 1627 | <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
1628 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
1629 | - }?> |
|
1628 | + echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
1629 | + }?> |
|
1630 | 1630 | <?php if ( ! empty( $args['placeholder'] ) ) { |
1631 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
1632 | - }?> |
|
1631 | + echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
1632 | + }?> |
|
1633 | 1633 | <?php echo $options;?> |
1634 | 1634 | <?php echo $extra;?> |
1635 | 1635 | <?php echo $custom_attributes;?> |
@@ -1639,27 +1639,27 @@ discard block |
||
1639 | 1639 | } |
1640 | 1640 | ), |
1641 | 1641 | <?php |
1642 | - } |
|
1643 | - } |
|
1644 | - ?> |
|
1642 | + } |
|
1643 | + } |
|
1644 | + ?> |
|
1645 | 1645 | |
1646 | 1646 | ), |
1647 | 1647 | |
1648 | 1648 | <?php |
1649 | - // If the user sets block-output array then build it |
|
1650 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
1651 | - $this->block_element( $this->options['block-output'] ); |
|
1652 | - }else{ |
|
1653 | - // if no block-output is set then we try and get the shortcode html output via ajax. |
|
1654 | - ?> |
|
1649 | + // If the user sets block-output array then build it |
|
1650 | + if ( ! empty( $this->options['block-output'] ) ) { |
|
1651 | + $this->block_element( $this->options['block-output'] ); |
|
1652 | + }else{ |
|
1653 | + // if no block-output is set then we try and get the shortcode html output via ajax. |
|
1654 | + ?> |
|
1655 | 1655 | el('div', { |
1656 | 1656 | dangerouslySetInnerHTML: {__html: onChangeContent()}, |
1657 | 1657 | className: props.className, |
1658 | 1658 | style: {'min-height': '30px'} |
1659 | 1659 | }) |
1660 | 1660 | <?php |
1661 | - } |
|
1662 | - ?> |
|
1661 | + } |
|
1662 | + ?> |
|
1663 | 1663 | ]; // end return |
1664 | 1664 | }, |
1665 | 1665 | |
@@ -1676,17 +1676,17 @@ discard block |
||
1676 | 1676 | var content = "[<?php echo $this->options['base_id'];?>"; |
1677 | 1677 | <?php |
1678 | 1678 | |
1679 | - if(! empty( $this->arguments )){ |
|
1680 | - foreach($this->arguments as $key => $args){ |
|
1681 | - ?> |
|
1679 | + if(! empty( $this->arguments )){ |
|
1680 | + foreach($this->arguments as $key => $args){ |
|
1681 | + ?> |
|
1682 | 1682 | if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
1683 | 1683 | content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
1684 | 1684 | } |
1685 | 1685 | <?php |
1686 | - } |
|
1687 | - } |
|
1686 | + } |
|
1687 | + } |
|
1688 | 1688 | |
1689 | - ?> |
|
1689 | + ?> |
|
1690 | 1690 | content += "]"; |
1691 | 1691 | |
1692 | 1692 | |
@@ -1715,456 +1715,456 @@ discard block |
||
1715 | 1715 | })(); |
1716 | 1716 | </script> |
1717 | 1717 | <?php |
1718 | - $output = ob_get_clean(); |
|
1718 | + $output = ob_get_clean(); |
|
1719 | 1719 | |
1720 | - /* |
|
1720 | + /* |
|
1721 | 1721 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1722 | 1722 | */ |
1723 | 1723 | |
1724 | - return str_replace( array( |
|
1725 | - '<script>', |
|
1726 | - '</script>' |
|
1727 | - ), '', $output ); |
|
1728 | - } |
|
1729 | - |
|
1730 | - /** |
|
1731 | - * Convert an array of attributes to block string. |
|
1732 | - * |
|
1733 | - * @todo there is prob a faster way to do this, also we could add some validation here. |
|
1734 | - * |
|
1735 | - * @param $custom_attributes |
|
1736 | - * |
|
1737 | - * @return string |
|
1738 | - */ |
|
1739 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
1740 | - $attributes = ''; |
|
1741 | - if ( ! empty( $custom_attributes ) ) { |
|
1742 | - |
|
1743 | - if ( $html ) { |
|
1744 | - foreach ( $custom_attributes as $key => $val ) { |
|
1745 | - $attributes .= " $key='$val' "; |
|
1746 | - } |
|
1747 | - } else { |
|
1748 | - foreach ( $custom_attributes as $key => $val ) { |
|
1749 | - $attributes .= "'$key': '$val',"; |
|
1750 | - } |
|
1751 | - } |
|
1752 | - } |
|
1753 | - |
|
1754 | - return $attributes; |
|
1755 | - } |
|
1756 | - |
|
1757 | - /** |
|
1758 | - * A self looping function to create the output for JS block elements. |
|
1759 | - * |
|
1760 | - * This is what is output in the WP Editor visual view. |
|
1761 | - * |
|
1762 | - * @param $args |
|
1763 | - */ |
|
1764 | - public function block_element( $args ) { |
|
1765 | - |
|
1766 | - |
|
1767 | - if ( ! empty( $args ) ) { |
|
1768 | - foreach ( $args as $element => $new_args ) { |
|
1769 | - |
|
1770 | - if ( is_array( $new_args ) ) { // its an element |
|
1771 | - |
|
1772 | - |
|
1773 | - if ( isset( $new_args['element'] ) ) { |
|
1774 | - |
|
1775 | - if ( isset( $new_args['element_require'] ) ) { |
|
1776 | - echo str_replace( array( |
|
1777 | - "'+", |
|
1778 | - "+'" |
|
1779 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
1780 | - unset( $new_args['element_require'] ); |
|
1781 | - } |
|
1782 | - |
|
1783 | - echo "\n el( '" . $new_args['element'] . "', {"; |
|
1784 | - |
|
1785 | - // get the attributes |
|
1786 | - foreach ( $new_args as $new_key => $new_value ) { |
|
1787 | - |
|
1788 | - |
|
1789 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
1790 | - // do nothing |
|
1791 | - } else { |
|
1792 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
1793 | - } |
|
1794 | - } |
|
1795 | - |
|
1796 | - echo "},";// end attributes |
|
1797 | - |
|
1798 | - // get the content |
|
1799 | - $first_item = 0; |
|
1800 | - foreach ( $new_args as $new_key => $new_value ) { |
|
1801 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
1802 | - |
|
1803 | - if ( $new_key === 'content' ) { |
|
1804 | - echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
1805 | - } |
|
1806 | - |
|
1807 | - if ( is_array( $new_value ) ) { |
|
1808 | - |
|
1809 | - if ( isset( $new_value['element_require'] ) ) { |
|
1810 | - echo str_replace( array( |
|
1811 | - "'+", |
|
1812 | - "+'" |
|
1813 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
1814 | - unset( $new_value['element_require'] ); |
|
1815 | - } |
|
1816 | - |
|
1817 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
1818 | - $x = 1; |
|
1819 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
1820 | - $this->block_element( array( '' => $new_value ) ); |
|
1821 | - $x ++; |
|
1822 | - } |
|
1823 | - } else { |
|
1824 | - $this->block_element( array( '' => $new_value ) ); |
|
1825 | - } |
|
1826 | - } |
|
1827 | - $first_item ++; |
|
1828 | - } |
|
1829 | - } |
|
1830 | - |
|
1831 | - echo ")";// end content |
|
1832 | - |
|
1833 | - echo ", \n"; |
|
1834 | - |
|
1835 | - } |
|
1836 | - } else { |
|
1837 | - |
|
1838 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
1839 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
1840 | - } elseif ( $element == 'style' ) { |
|
1841 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
1842 | - } else { |
|
1843 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
1844 | - } |
|
1845 | - |
|
1846 | - } |
|
1847 | - } |
|
1848 | - } |
|
1849 | - } |
|
1850 | - |
|
1851 | - /** |
|
1852 | - * Replace block attributes placeholders with the proper naming. |
|
1853 | - * |
|
1854 | - * @param $string |
|
1855 | - * |
|
1856 | - * @return mixed |
|
1857 | - */ |
|
1858 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
1859 | - |
|
1860 | - if ( $no_wrap ) { |
|
1861 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
1862 | - } else { |
|
1863 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
1864 | - } |
|
1865 | - |
|
1866 | - return $string; |
|
1867 | - } |
|
1868 | - |
|
1869 | - /** |
|
1870 | - * Outputs the content of the widget |
|
1871 | - * |
|
1872 | - * @param array $args |
|
1873 | - * @param array $instance |
|
1874 | - */ |
|
1875 | - public function widget( $args, $instance ) { |
|
1876 | - |
|
1877 | - // get the filtered values |
|
1878 | - $argument_values = $this->argument_values( $instance ); |
|
1879 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
1880 | - $output = $this->output( $argument_values, $args ); |
|
1881 | - |
|
1882 | - if ( $output ) { |
|
1883 | - // Before widget |
|
1884 | - $before_widget = $args['before_widget']; |
|
1885 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
1886 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
1887 | - |
|
1888 | - // After widget |
|
1889 | - $after_widget = $args['after_widget']; |
|
1890 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
1891 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
1892 | - |
|
1893 | - echo $before_widget; |
|
1894 | - // elementor strips the widget wrapping div so we check for and add it back if needed |
|
1895 | - if ( $this->is_elementor_widget_output() ) { |
|
1896 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
1897 | - } |
|
1898 | - echo $this->output_title( $args, $instance ); |
|
1899 | - echo $output; |
|
1900 | - if ( $this->is_elementor_widget_output() ) { |
|
1901 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
1902 | - } |
|
1903 | - echo $after_widget; |
|
1904 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
1905 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
1906 | - echo $output; |
|
1907 | - } |
|
1908 | - } |
|
1909 | - |
|
1910 | - /** |
|
1911 | - * Tests if the current output is inside a elementor container. |
|
1912 | - * |
|
1913 | - * @since 1.0.4 |
|
1914 | - * @return bool |
|
1915 | - */ |
|
1916 | - public function is_elementor_widget_output() { |
|
1917 | - $result = false; |
|
1918 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
1919 | - $result = true; |
|
1920 | - } |
|
1921 | - |
|
1922 | - return $result; |
|
1923 | - } |
|
1924 | - |
|
1925 | - /** |
|
1926 | - * Tests if the current output is inside a elementor preview. |
|
1927 | - * |
|
1928 | - * @since 1.0.4 |
|
1929 | - * @return bool |
|
1930 | - */ |
|
1931 | - public function is_elementor_preview() { |
|
1932 | - $result = false; |
|
1933 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
1934 | - $result = true; |
|
1935 | - } |
|
1936 | - |
|
1937 | - return $result; |
|
1938 | - } |
|
1939 | - |
|
1940 | - /** |
|
1941 | - * Tests if the current output is inside a Divi preview. |
|
1942 | - * |
|
1943 | - * @since 1.0.6 |
|
1944 | - * @return bool |
|
1945 | - */ |
|
1946 | - public function is_divi_preview() { |
|
1947 | - $result = false; |
|
1948 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
1949 | - $result = true; |
|
1950 | - } |
|
1951 | - |
|
1952 | - return $result; |
|
1953 | - } |
|
1954 | - |
|
1955 | - /** |
|
1956 | - * Tests if the current output is inside a Beaver builder preview. |
|
1957 | - * |
|
1958 | - * @since 1.0.6 |
|
1959 | - * @return bool |
|
1960 | - */ |
|
1961 | - public function is_beaver_preview() { |
|
1962 | - $result = false; |
|
1963 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
1964 | - $result = true; |
|
1965 | - } |
|
1966 | - |
|
1967 | - return $result; |
|
1968 | - } |
|
1969 | - |
|
1970 | - /** |
|
1971 | - * Tests if the current output is inside a siteorigin builder preview. |
|
1972 | - * |
|
1973 | - * @since 1.0.6 |
|
1974 | - * @return bool |
|
1975 | - */ |
|
1976 | - public function is_siteorigin_preview() { |
|
1977 | - $result = false; |
|
1978 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
1979 | - $result = true; |
|
1980 | - } |
|
1981 | - |
|
1982 | - return $result; |
|
1983 | - } |
|
1984 | - |
|
1985 | - /** |
|
1986 | - * Tests if the current output is inside a cornerstone builder preview. |
|
1987 | - * |
|
1988 | - * @since 1.0.8 |
|
1989 | - * @return bool |
|
1990 | - */ |
|
1991 | - public function is_cornerstone_preview() { |
|
1992 | - $result = false; |
|
1993 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
1994 | - $result = true; |
|
1995 | - } |
|
1996 | - |
|
1997 | - return $result; |
|
1998 | - } |
|
1999 | - |
|
2000 | - /** |
|
2001 | - * General function to check if we are in a preview situation. |
|
2002 | - * |
|
2003 | - * @since 1.0.6 |
|
2004 | - * @return bool |
|
2005 | - */ |
|
2006 | - public function is_preview() { |
|
2007 | - $preview = false; |
|
2008 | - if ( $this->is_divi_preview() ) { |
|
2009 | - $preview = true; |
|
2010 | - } elseif ( $this->is_elementor_preview() ) { |
|
2011 | - $preview = true; |
|
2012 | - } elseif ( $this->is_beaver_preview() ) { |
|
2013 | - $preview = true; |
|
2014 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
2015 | - $preview = true; |
|
2016 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
2017 | - $preview = true; |
|
2018 | - } |
|
2019 | - |
|
2020 | - return $preview; |
|
2021 | - } |
|
2022 | - |
|
2023 | - /** |
|
2024 | - * Output the super title. |
|
2025 | - * |
|
2026 | - * @param $args |
|
2027 | - * @param array $instance |
|
2028 | - * |
|
2029 | - * @return string |
|
2030 | - */ |
|
2031 | - public function output_title( $args, $instance = array() ) { |
|
2032 | - $output = ''; |
|
2033 | - if ( ! empty( $instance['title'] ) ) { |
|
2034 | - /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
2035 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
2036 | - $output = $args['before_title'] . $title . $args['after_title']; |
|
2037 | - } |
|
2038 | - |
|
2039 | - return $output; |
|
2040 | - } |
|
2041 | - |
|
2042 | - /** |
|
2043 | - * Outputs the options form inputs for the widget. |
|
2044 | - * |
|
2045 | - * @param array $instance The widget options. |
|
2046 | - */ |
|
2047 | - public function form( $instance ) { |
|
2048 | - |
|
2049 | - // set widget instance |
|
2050 | - $this->instance = $instance; |
|
2051 | - |
|
2052 | - // set it as a SD widget |
|
2053 | - echo $this->widget_advanced_toggle(); |
|
2054 | - |
|
2055 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
2056 | - $arguments = $this->get_arguments(); |
|
2057 | - |
|
2058 | - if ( is_array( $arguments ) ) { |
|
2059 | - foreach ( $arguments as $key => $args ) { |
|
2060 | - $this->widget_inputs( $args, $instance ); |
|
2061 | - } |
|
2062 | - } |
|
2063 | - } |
|
2064 | - |
|
2065 | - /** |
|
2066 | - * Get the hidden input that when added makes the advanced button show on widget settings. |
|
2067 | - * |
|
2068 | - * @return string |
|
2069 | - */ |
|
2070 | - public function widget_advanced_toggle() { |
|
2071 | - |
|
2072 | - $output = ''; |
|
2073 | - if ( $this->block_show_advanced() ) { |
|
2074 | - $val = 1; |
|
2075 | - } else { |
|
2076 | - $val = 0; |
|
2077 | - } |
|
2078 | - |
|
2079 | - $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
2080 | - |
|
2081 | - return $output; |
|
2082 | - } |
|
2083 | - |
|
2084 | - /** |
|
2085 | - * Convert require element. |
|
2086 | - * |
|
2087 | - * @since 1.0.0 |
|
2088 | - * |
|
2089 | - * @param string $input Input element. |
|
2090 | - * |
|
2091 | - * @return string $output |
|
2092 | - */ |
|
2093 | - public function convert_element_require( $input ) { |
|
2094 | - |
|
2095 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
2096 | - |
|
2097 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
2098 | - "jQuery(form).find('[data-argument=\"", |
|
2099 | - "\"]').find('input,select').val()" |
|
2100 | - ), $input ) ); |
|
2101 | - |
|
2102 | - return $output; |
|
2103 | - } |
|
2104 | - |
|
2105 | - /** |
|
2106 | - * Builds the inputs for the widget options. |
|
2107 | - * |
|
2108 | - * @param $args |
|
2109 | - * @param $instance |
|
2110 | - */ |
|
2111 | - public function widget_inputs( $args, $instance ) { |
|
2112 | - |
|
2113 | - $class = ""; |
|
2114 | - $element_require = ""; |
|
2115 | - $custom_attributes = ""; |
|
2116 | - |
|
2117 | - // get value |
|
2118 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
2119 | - $value = $instance[ $args['name'] ]; |
|
2120 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
2121 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
2122 | - } else { |
|
2123 | - $value = ''; |
|
2124 | - } |
|
2125 | - |
|
2126 | - // get placeholder |
|
2127 | - if ( ! empty( $args['placeholder'] ) ) { |
|
2128 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
2129 | - } else { |
|
2130 | - $placeholder = ''; |
|
2131 | - } |
|
2132 | - |
|
2133 | - // get if advanced |
|
2134 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
2135 | - $class .= " sd-advanced-setting "; |
|
2136 | - } |
|
2137 | - |
|
2138 | - // element_require |
|
2139 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
2140 | - $element_require = $args['element_require']; |
|
2141 | - } |
|
2142 | - |
|
2143 | - // custom_attributes |
|
2144 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
2145 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
2146 | - } |
|
2147 | - |
|
2148 | - // before wrapper |
|
2149 | - ?> |
|
1724 | + return str_replace( array( |
|
1725 | + '<script>', |
|
1726 | + '</script>' |
|
1727 | + ), '', $output ); |
|
1728 | + } |
|
1729 | + |
|
1730 | + /** |
|
1731 | + * Convert an array of attributes to block string. |
|
1732 | + * |
|
1733 | + * @todo there is prob a faster way to do this, also we could add some validation here. |
|
1734 | + * |
|
1735 | + * @param $custom_attributes |
|
1736 | + * |
|
1737 | + * @return string |
|
1738 | + */ |
|
1739 | + public function array_to_attributes( $custom_attributes, $html = false ) { |
|
1740 | + $attributes = ''; |
|
1741 | + if ( ! empty( $custom_attributes ) ) { |
|
1742 | + |
|
1743 | + if ( $html ) { |
|
1744 | + foreach ( $custom_attributes as $key => $val ) { |
|
1745 | + $attributes .= " $key='$val' "; |
|
1746 | + } |
|
1747 | + } else { |
|
1748 | + foreach ( $custom_attributes as $key => $val ) { |
|
1749 | + $attributes .= "'$key': '$val',"; |
|
1750 | + } |
|
1751 | + } |
|
1752 | + } |
|
1753 | + |
|
1754 | + return $attributes; |
|
1755 | + } |
|
1756 | + |
|
1757 | + /** |
|
1758 | + * A self looping function to create the output for JS block elements. |
|
1759 | + * |
|
1760 | + * This is what is output in the WP Editor visual view. |
|
1761 | + * |
|
1762 | + * @param $args |
|
1763 | + */ |
|
1764 | + public function block_element( $args ) { |
|
1765 | + |
|
1766 | + |
|
1767 | + if ( ! empty( $args ) ) { |
|
1768 | + foreach ( $args as $element => $new_args ) { |
|
1769 | + |
|
1770 | + if ( is_array( $new_args ) ) { // its an element |
|
1771 | + |
|
1772 | + |
|
1773 | + if ( isset( $new_args['element'] ) ) { |
|
1774 | + |
|
1775 | + if ( isset( $new_args['element_require'] ) ) { |
|
1776 | + echo str_replace( array( |
|
1777 | + "'+", |
|
1778 | + "+'" |
|
1779 | + ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
1780 | + unset( $new_args['element_require'] ); |
|
1781 | + } |
|
1782 | + |
|
1783 | + echo "\n el( '" . $new_args['element'] . "', {"; |
|
1784 | + |
|
1785 | + // get the attributes |
|
1786 | + foreach ( $new_args as $new_key => $new_value ) { |
|
1787 | + |
|
1788 | + |
|
1789 | + if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
1790 | + // do nothing |
|
1791 | + } else { |
|
1792 | + echo $this->block_element( array( $new_key => $new_value ) ); |
|
1793 | + } |
|
1794 | + } |
|
1795 | + |
|
1796 | + echo "},";// end attributes |
|
1797 | + |
|
1798 | + // get the content |
|
1799 | + $first_item = 0; |
|
1800 | + foreach ( $new_args as $new_key => $new_value ) { |
|
1801 | + if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
1802 | + |
|
1803 | + if ( $new_key === 'content' ) { |
|
1804 | + echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
1805 | + } |
|
1806 | + |
|
1807 | + if ( is_array( $new_value ) ) { |
|
1808 | + |
|
1809 | + if ( isset( $new_value['element_require'] ) ) { |
|
1810 | + echo str_replace( array( |
|
1811 | + "'+", |
|
1812 | + "+'" |
|
1813 | + ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
1814 | + unset( $new_value['element_require'] ); |
|
1815 | + } |
|
1816 | + |
|
1817 | + if ( isset( $new_value['element_repeat'] ) ) { |
|
1818 | + $x = 1; |
|
1819 | + while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
1820 | + $this->block_element( array( '' => $new_value ) ); |
|
1821 | + $x ++; |
|
1822 | + } |
|
1823 | + } else { |
|
1824 | + $this->block_element( array( '' => $new_value ) ); |
|
1825 | + } |
|
1826 | + } |
|
1827 | + $first_item ++; |
|
1828 | + } |
|
1829 | + } |
|
1830 | + |
|
1831 | + echo ")";// end content |
|
1832 | + |
|
1833 | + echo ", \n"; |
|
1834 | + |
|
1835 | + } |
|
1836 | + } else { |
|
1837 | + |
|
1838 | + if ( substr( $element, 0, 3 ) === "if_" ) { |
|
1839 | + echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
1840 | + } elseif ( $element == 'style' ) { |
|
1841 | + echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
1842 | + } else { |
|
1843 | + echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
1844 | + } |
|
1845 | + |
|
1846 | + } |
|
1847 | + } |
|
1848 | + } |
|
1849 | + } |
|
1850 | + |
|
1851 | + /** |
|
1852 | + * Replace block attributes placeholders with the proper naming. |
|
1853 | + * |
|
1854 | + * @param $string |
|
1855 | + * |
|
1856 | + * @return mixed |
|
1857 | + */ |
|
1858 | + public function block_props_replace( $string, $no_wrap = false ) { |
|
1859 | + |
|
1860 | + if ( $no_wrap ) { |
|
1861 | + $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
1862 | + } else { |
|
1863 | + $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
1864 | + } |
|
1865 | + |
|
1866 | + return $string; |
|
1867 | + } |
|
1868 | + |
|
1869 | + /** |
|
1870 | + * Outputs the content of the widget |
|
1871 | + * |
|
1872 | + * @param array $args |
|
1873 | + * @param array $instance |
|
1874 | + */ |
|
1875 | + public function widget( $args, $instance ) { |
|
1876 | + |
|
1877 | + // get the filtered values |
|
1878 | + $argument_values = $this->argument_values( $instance ); |
|
1879 | + $argument_values = $this->string_to_bool( $argument_values ); |
|
1880 | + $output = $this->output( $argument_values, $args ); |
|
1881 | + |
|
1882 | + if ( $output ) { |
|
1883 | + // Before widget |
|
1884 | + $before_widget = $args['before_widget']; |
|
1885 | + $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
1886 | + $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
1887 | + |
|
1888 | + // After widget |
|
1889 | + $after_widget = $args['after_widget']; |
|
1890 | + $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
1891 | + $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
1892 | + |
|
1893 | + echo $before_widget; |
|
1894 | + // elementor strips the widget wrapping div so we check for and add it back if needed |
|
1895 | + if ( $this->is_elementor_widget_output() ) { |
|
1896 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
1897 | + } |
|
1898 | + echo $this->output_title( $args, $instance ); |
|
1899 | + echo $output; |
|
1900 | + if ( $this->is_elementor_widget_output() ) { |
|
1901 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
1902 | + } |
|
1903 | + echo $after_widget; |
|
1904 | + } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
1905 | + $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
1906 | + echo $output; |
|
1907 | + } |
|
1908 | + } |
|
1909 | + |
|
1910 | + /** |
|
1911 | + * Tests if the current output is inside a elementor container. |
|
1912 | + * |
|
1913 | + * @since 1.0.4 |
|
1914 | + * @return bool |
|
1915 | + */ |
|
1916 | + public function is_elementor_widget_output() { |
|
1917 | + $result = false; |
|
1918 | + if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
1919 | + $result = true; |
|
1920 | + } |
|
1921 | + |
|
1922 | + return $result; |
|
1923 | + } |
|
1924 | + |
|
1925 | + /** |
|
1926 | + * Tests if the current output is inside a elementor preview. |
|
1927 | + * |
|
1928 | + * @since 1.0.4 |
|
1929 | + * @return bool |
|
1930 | + */ |
|
1931 | + public function is_elementor_preview() { |
|
1932 | + $result = false; |
|
1933 | + if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
1934 | + $result = true; |
|
1935 | + } |
|
1936 | + |
|
1937 | + return $result; |
|
1938 | + } |
|
1939 | + |
|
1940 | + /** |
|
1941 | + * Tests if the current output is inside a Divi preview. |
|
1942 | + * |
|
1943 | + * @since 1.0.6 |
|
1944 | + * @return bool |
|
1945 | + */ |
|
1946 | + public function is_divi_preview() { |
|
1947 | + $result = false; |
|
1948 | + if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
1949 | + $result = true; |
|
1950 | + } |
|
1951 | + |
|
1952 | + return $result; |
|
1953 | + } |
|
1954 | + |
|
1955 | + /** |
|
1956 | + * Tests if the current output is inside a Beaver builder preview. |
|
1957 | + * |
|
1958 | + * @since 1.0.6 |
|
1959 | + * @return bool |
|
1960 | + */ |
|
1961 | + public function is_beaver_preview() { |
|
1962 | + $result = false; |
|
1963 | + if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
1964 | + $result = true; |
|
1965 | + } |
|
1966 | + |
|
1967 | + return $result; |
|
1968 | + } |
|
1969 | + |
|
1970 | + /** |
|
1971 | + * Tests if the current output is inside a siteorigin builder preview. |
|
1972 | + * |
|
1973 | + * @since 1.0.6 |
|
1974 | + * @return bool |
|
1975 | + */ |
|
1976 | + public function is_siteorigin_preview() { |
|
1977 | + $result = false; |
|
1978 | + if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
1979 | + $result = true; |
|
1980 | + } |
|
1981 | + |
|
1982 | + return $result; |
|
1983 | + } |
|
1984 | + |
|
1985 | + /** |
|
1986 | + * Tests if the current output is inside a cornerstone builder preview. |
|
1987 | + * |
|
1988 | + * @since 1.0.8 |
|
1989 | + * @return bool |
|
1990 | + */ |
|
1991 | + public function is_cornerstone_preview() { |
|
1992 | + $result = false; |
|
1993 | + if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
1994 | + $result = true; |
|
1995 | + } |
|
1996 | + |
|
1997 | + return $result; |
|
1998 | + } |
|
1999 | + |
|
2000 | + /** |
|
2001 | + * General function to check if we are in a preview situation. |
|
2002 | + * |
|
2003 | + * @since 1.0.6 |
|
2004 | + * @return bool |
|
2005 | + */ |
|
2006 | + public function is_preview() { |
|
2007 | + $preview = false; |
|
2008 | + if ( $this->is_divi_preview() ) { |
|
2009 | + $preview = true; |
|
2010 | + } elseif ( $this->is_elementor_preview() ) { |
|
2011 | + $preview = true; |
|
2012 | + } elseif ( $this->is_beaver_preview() ) { |
|
2013 | + $preview = true; |
|
2014 | + } elseif ( $this->is_siteorigin_preview() ) { |
|
2015 | + $preview = true; |
|
2016 | + } elseif ( $this->is_cornerstone_preview() ) { |
|
2017 | + $preview = true; |
|
2018 | + } |
|
2019 | + |
|
2020 | + return $preview; |
|
2021 | + } |
|
2022 | + |
|
2023 | + /** |
|
2024 | + * Output the super title. |
|
2025 | + * |
|
2026 | + * @param $args |
|
2027 | + * @param array $instance |
|
2028 | + * |
|
2029 | + * @return string |
|
2030 | + */ |
|
2031 | + public function output_title( $args, $instance = array() ) { |
|
2032 | + $output = ''; |
|
2033 | + if ( ! empty( $instance['title'] ) ) { |
|
2034 | + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
2035 | + $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
2036 | + $output = $args['before_title'] . $title . $args['after_title']; |
|
2037 | + } |
|
2038 | + |
|
2039 | + return $output; |
|
2040 | + } |
|
2041 | + |
|
2042 | + /** |
|
2043 | + * Outputs the options form inputs for the widget. |
|
2044 | + * |
|
2045 | + * @param array $instance The widget options. |
|
2046 | + */ |
|
2047 | + public function form( $instance ) { |
|
2048 | + |
|
2049 | + // set widget instance |
|
2050 | + $this->instance = $instance; |
|
2051 | + |
|
2052 | + // set it as a SD widget |
|
2053 | + echo $this->widget_advanced_toggle(); |
|
2054 | + |
|
2055 | + echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
2056 | + $arguments = $this->get_arguments(); |
|
2057 | + |
|
2058 | + if ( is_array( $arguments ) ) { |
|
2059 | + foreach ( $arguments as $key => $args ) { |
|
2060 | + $this->widget_inputs( $args, $instance ); |
|
2061 | + } |
|
2062 | + } |
|
2063 | + } |
|
2064 | + |
|
2065 | + /** |
|
2066 | + * Get the hidden input that when added makes the advanced button show on widget settings. |
|
2067 | + * |
|
2068 | + * @return string |
|
2069 | + */ |
|
2070 | + public function widget_advanced_toggle() { |
|
2071 | + |
|
2072 | + $output = ''; |
|
2073 | + if ( $this->block_show_advanced() ) { |
|
2074 | + $val = 1; |
|
2075 | + } else { |
|
2076 | + $val = 0; |
|
2077 | + } |
|
2078 | + |
|
2079 | + $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
2080 | + |
|
2081 | + return $output; |
|
2082 | + } |
|
2083 | + |
|
2084 | + /** |
|
2085 | + * Convert require element. |
|
2086 | + * |
|
2087 | + * @since 1.0.0 |
|
2088 | + * |
|
2089 | + * @param string $input Input element. |
|
2090 | + * |
|
2091 | + * @return string $output |
|
2092 | + */ |
|
2093 | + public function convert_element_require( $input ) { |
|
2094 | + |
|
2095 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
2096 | + |
|
2097 | + $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
2098 | + "jQuery(form).find('[data-argument=\"", |
|
2099 | + "\"]').find('input,select').val()" |
|
2100 | + ), $input ) ); |
|
2101 | + |
|
2102 | + return $output; |
|
2103 | + } |
|
2104 | + |
|
2105 | + /** |
|
2106 | + * Builds the inputs for the widget options. |
|
2107 | + * |
|
2108 | + * @param $args |
|
2109 | + * @param $instance |
|
2110 | + */ |
|
2111 | + public function widget_inputs( $args, $instance ) { |
|
2112 | + |
|
2113 | + $class = ""; |
|
2114 | + $element_require = ""; |
|
2115 | + $custom_attributes = ""; |
|
2116 | + |
|
2117 | + // get value |
|
2118 | + if ( isset( $instance[ $args['name'] ] ) ) { |
|
2119 | + $value = $instance[ $args['name'] ]; |
|
2120 | + } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
2121 | + $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
2122 | + } else { |
|
2123 | + $value = ''; |
|
2124 | + } |
|
2125 | + |
|
2126 | + // get placeholder |
|
2127 | + if ( ! empty( $args['placeholder'] ) ) { |
|
2128 | + $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
2129 | + } else { |
|
2130 | + $placeholder = ''; |
|
2131 | + } |
|
2132 | + |
|
2133 | + // get if advanced |
|
2134 | + if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
2135 | + $class .= " sd-advanced-setting "; |
|
2136 | + } |
|
2137 | + |
|
2138 | + // element_require |
|
2139 | + if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
2140 | + $element_require = $args['element_require']; |
|
2141 | + } |
|
2142 | + |
|
2143 | + // custom_attributes |
|
2144 | + if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
2145 | + $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
2146 | + } |
|
2147 | + |
|
2148 | + // before wrapper |
|
2149 | + ?> |
|
2150 | 2150 | <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
2151 | 2151 | data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
2152 | 2152 | data-element_require='<?php if ( $element_require ) { |
2153 | - echo $this->convert_element_require( $element_require ); |
|
2154 | - } ?>' |
|
2153 | + echo $this->convert_element_require( $element_require ); |
|
2154 | + } ?>' |
|
2155 | 2155 | > |
2156 | 2156 | <?php |
2157 | 2157 | |
2158 | - switch ( $args['type'] ) { |
|
2159 | - //array('text','password','number','email','tel','url','color') |
|
2160 | - case "text": |
|
2161 | - case "password": |
|
2162 | - case "number": |
|
2163 | - case "email": |
|
2164 | - case "tel": |
|
2165 | - case "url": |
|
2166 | - case "color": |
|
2167 | - ?> |
|
2158 | + switch ( $args['type'] ) { |
|
2159 | + //array('text','password','number','email','tel','url','color') |
|
2160 | + case "text": |
|
2161 | + case "password": |
|
2162 | + case "number": |
|
2163 | + case "email": |
|
2164 | + case "tel": |
|
2165 | + case "url": |
|
2166 | + case "color": |
|
2167 | + ?> |
|
2168 | 2168 | <label |
2169 | 2169 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
2170 | 2170 | <input <?php echo $placeholder; ?> class="widefat" |
@@ -2175,47 +2175,47 @@ discard block |
||
2175 | 2175 | value="<?php echo esc_attr( $value ); ?>"> |
2176 | 2176 | <?php |
2177 | 2177 | |
2178 | - break; |
|
2179 | - case "select": |
|
2180 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
2181 | - if ( $multiple ) { |
|
2182 | - if ( empty( $value ) ) { |
|
2183 | - $value = array(); |
|
2184 | - } |
|
2185 | - } |
|
2186 | - ?> |
|
2178 | + break; |
|
2179 | + case "select": |
|
2180 | + $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
2181 | + if ( $multiple ) { |
|
2182 | + if ( empty( $value ) ) { |
|
2183 | + $value = array(); |
|
2184 | + } |
|
2185 | + } |
|
2186 | + ?> |
|
2187 | 2187 | <label |
2188 | 2188 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
2189 | 2189 | <select <?php echo $placeholder; ?> class="widefat" |
2190 | 2190 | <?php echo $custom_attributes; ?> |
2191 | 2191 | id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
2192 | 2192 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
2193 | - if ( $multiple ) { |
|
2194 | - echo "[]"; |
|
2195 | - } ?>" |
|
2193 | + if ( $multiple ) { |
|
2194 | + echo "[]"; |
|
2195 | + } ?>" |
|
2196 | 2196 | <?php if ( $multiple ) { |
2197 | - echo "multiple"; |
|
2198 | - } //@todo not implemented yet due to gutenberg not supporting it |
|
2199 | - ?> |
|
2197 | + echo "multiple"; |
|
2198 | + } //@todo not implemented yet due to gutenberg not supporting it |
|
2199 | + ?> |
|
2200 | 2200 | > |
2201 | 2201 | <?php |
2202 | 2202 | |
2203 | - if ( ! empty( $args['options'] ) ) { |
|
2204 | - foreach ( $args['options'] as $val => $label ) { |
|
2205 | - if ( $multiple ) { |
|
2206 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
2207 | - } else { |
|
2208 | - $selected = selected( $value, $val, false ); |
|
2209 | - } |
|
2210 | - echo "<option value='$val' " . $selected . ">$label</option>"; |
|
2211 | - } |
|
2212 | - } |
|
2213 | - ?> |
|
2203 | + if ( ! empty( $args['options'] ) ) { |
|
2204 | + foreach ( $args['options'] as $val => $label ) { |
|
2205 | + if ( $multiple ) { |
|
2206 | + $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
2207 | + } else { |
|
2208 | + $selected = selected( $value, $val, false ); |
|
2209 | + } |
|
2210 | + echo "<option value='$val' " . $selected . ">$label</option>"; |
|
2211 | + } |
|
2212 | + } |
|
2213 | + ?> |
|
2214 | 2214 | </select> |
2215 | 2215 | <?php |
2216 | - break; |
|
2217 | - case "checkbox": |
|
2218 | - ?> |
|
2216 | + break; |
|
2217 | + case "checkbox": |
|
2218 | + ?> |
|
2219 | 2219 | <input <?php echo $placeholder; ?> |
2220 | 2220 | <?php checked( 1, $value, true ) ?> |
2221 | 2221 | <?php echo $custom_attributes; ?> |
@@ -2225,136 +2225,136 @@ discard block |
||
2225 | 2225 | <label |
2226 | 2226 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
2227 | 2227 | <?php |
2228 | - break; |
|
2229 | - case "hidden": |
|
2230 | - ?> |
|
2228 | + break; |
|
2229 | + case "hidden": |
|
2230 | + ?> |
|
2231 | 2231 | <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
2232 | 2232 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
2233 | 2233 | value="<?php echo esc_attr( $value ); ?>"> |
2234 | 2234 | <?php |
2235 | - break; |
|
2236 | - default: |
|
2237 | - echo "No input type found!"; // @todo we need to add more input types. |
|
2238 | - } |
|
2235 | + break; |
|
2236 | + default: |
|
2237 | + echo "No input type found!"; // @todo we need to add more input types. |
|
2238 | + } |
|
2239 | 2239 | |
2240 | - // after wrapper |
|
2241 | - ?> |
|
2240 | + // after wrapper |
|
2241 | + ?> |
|
2242 | 2242 | </p> |
2243 | 2243 | <?php |
2244 | 2244 | |
2245 | - } |
|
2246 | - |
|
2247 | - /** |
|
2248 | - * Get the widget input description html. |
|
2249 | - * |
|
2250 | - * @param $args |
|
2251 | - * |
|
2252 | - * @return string |
|
2253 | - * @todo, need to make its own tooltip script |
|
2254 | - */ |
|
2255 | - public function widget_field_desc( $args ) { |
|
2256 | - |
|
2257 | - $description = ''; |
|
2258 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
2259 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
2260 | - $description = $this->desc_tip( $args['desc'] ); |
|
2261 | - } else { |
|
2262 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
2263 | - } |
|
2264 | - } |
|
2265 | - |
|
2266 | - return $description; |
|
2267 | - } |
|
2268 | - |
|
2269 | - /** |
|
2270 | - * Get the tool tip html. |
|
2271 | - * |
|
2272 | - * @param $tip |
|
2273 | - * @param bool $allow_html |
|
2274 | - * |
|
2275 | - * @return string |
|
2276 | - */ |
|
2277 | - function desc_tip( $tip, $allow_html = false ) { |
|
2278 | - if ( $allow_html ) { |
|
2279 | - $tip = $this->sanitize_tooltip( $tip ); |
|
2280 | - } else { |
|
2281 | - $tip = esc_attr( $tip ); |
|
2282 | - } |
|
2283 | - |
|
2284 | - return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
2285 | - } |
|
2286 | - |
|
2287 | - /** |
|
2288 | - * Sanitize a string destined to be a tooltip. |
|
2289 | - * |
|
2290 | - * @param string $var |
|
2291 | - * |
|
2292 | - * @return string |
|
2293 | - */ |
|
2294 | - public function sanitize_tooltip( $var ) { |
|
2295 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
2296 | - 'br' => array(), |
|
2297 | - 'em' => array(), |
|
2298 | - 'strong' => array(), |
|
2299 | - 'small' => array(), |
|
2300 | - 'span' => array(), |
|
2301 | - 'ul' => array(), |
|
2302 | - 'li' => array(), |
|
2303 | - 'ol' => array(), |
|
2304 | - 'p' => array(), |
|
2305 | - ) ) ); |
|
2306 | - } |
|
2307 | - |
|
2308 | - /** |
|
2309 | - * Processing widget options on save |
|
2310 | - * |
|
2311 | - * @param array $new_instance The new options |
|
2312 | - * @param array $old_instance The previous options |
|
2313 | - * |
|
2314 | - * @return array |
|
2315 | - * @todo we should add some sanitation here. |
|
2316 | - */ |
|
2317 | - public function update( $new_instance, $old_instance ) { |
|
2318 | - |
|
2319 | - //save the widget |
|
2320 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
2321 | - |
|
2322 | - // set widget instance |
|
2323 | - $this->instance = $instance; |
|
2324 | - |
|
2325 | - if ( empty( $this->arguments ) ) { |
|
2326 | - $this->get_arguments(); |
|
2327 | - } |
|
2328 | - |
|
2329 | - // check for checkboxes |
|
2330 | - if ( ! empty( $this->arguments ) ) { |
|
2331 | - foreach ( $this->arguments as $argument ) { |
|
2332 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
2333 | - $instance[ $argument['name'] ] = '0'; |
|
2334 | - } |
|
2335 | - } |
|
2336 | - } |
|
2337 | - |
|
2338 | - return $instance; |
|
2339 | - } |
|
2340 | - |
|
2341 | - /** |
|
2342 | - * Checks if the current call is a ajax call to get the block content. |
|
2343 | - * |
|
2344 | - * This can be used in your widget to return different content as the block content. |
|
2345 | - * |
|
2346 | - * @since 1.0.3 |
|
2347 | - * @return bool |
|
2348 | - */ |
|
2349 | - public function is_block_content_call() { |
|
2350 | - $result = false; |
|
2351 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
2352 | - $result = true; |
|
2353 | - } |
|
2354 | - |
|
2355 | - return $result; |
|
2356 | - } |
|
2357 | - |
|
2358 | - } |
|
2245 | + } |
|
2246 | + |
|
2247 | + /** |
|
2248 | + * Get the widget input description html. |
|
2249 | + * |
|
2250 | + * @param $args |
|
2251 | + * |
|
2252 | + * @return string |
|
2253 | + * @todo, need to make its own tooltip script |
|
2254 | + */ |
|
2255 | + public function widget_field_desc( $args ) { |
|
2256 | + |
|
2257 | + $description = ''; |
|
2258 | + if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
2259 | + if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
2260 | + $description = $this->desc_tip( $args['desc'] ); |
|
2261 | + } else { |
|
2262 | + $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
2263 | + } |
|
2264 | + } |
|
2265 | + |
|
2266 | + return $description; |
|
2267 | + } |
|
2268 | + |
|
2269 | + /** |
|
2270 | + * Get the tool tip html. |
|
2271 | + * |
|
2272 | + * @param $tip |
|
2273 | + * @param bool $allow_html |
|
2274 | + * |
|
2275 | + * @return string |
|
2276 | + */ |
|
2277 | + function desc_tip( $tip, $allow_html = false ) { |
|
2278 | + if ( $allow_html ) { |
|
2279 | + $tip = $this->sanitize_tooltip( $tip ); |
|
2280 | + } else { |
|
2281 | + $tip = esc_attr( $tip ); |
|
2282 | + } |
|
2283 | + |
|
2284 | + return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
2285 | + } |
|
2286 | + |
|
2287 | + /** |
|
2288 | + * Sanitize a string destined to be a tooltip. |
|
2289 | + * |
|
2290 | + * @param string $var |
|
2291 | + * |
|
2292 | + * @return string |
|
2293 | + */ |
|
2294 | + public function sanitize_tooltip( $var ) { |
|
2295 | + return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
2296 | + 'br' => array(), |
|
2297 | + 'em' => array(), |
|
2298 | + 'strong' => array(), |
|
2299 | + 'small' => array(), |
|
2300 | + 'span' => array(), |
|
2301 | + 'ul' => array(), |
|
2302 | + 'li' => array(), |
|
2303 | + 'ol' => array(), |
|
2304 | + 'p' => array(), |
|
2305 | + ) ) ); |
|
2306 | + } |
|
2307 | + |
|
2308 | + /** |
|
2309 | + * Processing widget options on save |
|
2310 | + * |
|
2311 | + * @param array $new_instance The new options |
|
2312 | + * @param array $old_instance The previous options |
|
2313 | + * |
|
2314 | + * @return array |
|
2315 | + * @todo we should add some sanitation here. |
|
2316 | + */ |
|
2317 | + public function update( $new_instance, $old_instance ) { |
|
2318 | + |
|
2319 | + //save the widget |
|
2320 | + $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
2321 | + |
|
2322 | + // set widget instance |
|
2323 | + $this->instance = $instance; |
|
2324 | + |
|
2325 | + if ( empty( $this->arguments ) ) { |
|
2326 | + $this->get_arguments(); |
|
2327 | + } |
|
2328 | + |
|
2329 | + // check for checkboxes |
|
2330 | + if ( ! empty( $this->arguments ) ) { |
|
2331 | + foreach ( $this->arguments as $argument ) { |
|
2332 | + if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
2333 | + $instance[ $argument['name'] ] = '0'; |
|
2334 | + } |
|
2335 | + } |
|
2336 | + } |
|
2337 | + |
|
2338 | + return $instance; |
|
2339 | + } |
|
2340 | + |
|
2341 | + /** |
|
2342 | + * Checks if the current call is a ajax call to get the block content. |
|
2343 | + * |
|
2344 | + * This can be used in your widget to return different content as the block content. |
|
2345 | + * |
|
2346 | + * @since 1.0.3 |
|
2347 | + * @return bool |
|
2348 | + */ |
|
2349 | + public function is_block_content_call() { |
|
2350 | + $result = false; |
|
2351 | + if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
2352 | + $result = true; |
|
2353 | + } |
|
2354 | + |
|
2355 | + return $result; |
|
2356 | + } |
|
2357 | + |
|
2358 | + } |
|
2359 | 2359 | |
2360 | 2360 | } |
2361 | 2361 | \ No newline at end of file |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | -if ( ! class_exists( 'WP_Super_Duper' ) ) { |
|
6 | +if (!class_exists('WP_Super_Duper')) { |
|
7 | 7 | |
8 | 8 | |
9 | 9 | /** |
@@ -39,27 +39,27 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * Take the array options and use them to build. |
41 | 41 | */ |
42 | - public function __construct( $options ) { |
|
42 | + public function __construct($options) { |
|
43 | 43 | global $sd_widgets; |
44 | 44 | |
45 | - $sd_widgets[ $options['base_id'] ] = array( |
|
45 | + $sd_widgets[$options['base_id']] = array( |
|
46 | 46 | 'name' => $options['name'], |
47 | 47 | 'class_name' => $options['class_name'] |
48 | 48 | ); |
49 | - $this->base_id = $options['base_id']; |
|
49 | + $this->base_id = $options['base_id']; |
|
50 | 50 | // lets filter the options before we do anything |
51 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
52 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
53 | - $options = $this->add_name_from_key( $options ); |
|
51 | + $options = apply_filters("wp_super_duper_options", $options); |
|
52 | + $options = apply_filters("wp_super_duper_options_{$this->base_id}", $options); |
|
53 | + $options = $this->add_name_from_key($options); |
|
54 | 54 | $this->options = $options; |
55 | 55 | |
56 | 56 | $this->base_id = $options['base_id']; |
57 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
57 | + $this->arguments = isset($options['arguments']) ? $options['arguments'] : array(); |
|
58 | 58 | |
59 | 59 | // init parent |
60 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
60 | + parent::__construct($options['base_id'], $options['name'], $options['widget_ops']); |
|
61 | 61 | |
62 | - if ( isset( $options['class_name'] ) ) { |
|
62 | + if (isset($options['class_name'])) { |
|
63 | 63 | // register widget |
64 | 64 | $this->class_name = $options['class_name']; |
65 | 65 | |
@@ -67,47 +67,47 @@ discard block |
||
67 | 67 | $this->register_shortcode(); |
68 | 68 | |
69 | 69 | // register block |
70 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
70 | + add_action('admin_enqueue_scripts', array($this, 'register_block')); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // add the CSS and JS we need ONCE |
74 | 74 | global $sd_widget_scripts; |
75 | 75 | |
76 | - if ( ! $sd_widget_scripts ) { |
|
77 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
78 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
79 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
76 | + if (!$sd_widget_scripts) { |
|
77 | + wp_add_inline_script('admin-widgets', $this->widget_js()); |
|
78 | + wp_add_inline_script('customize-controls', $this->widget_js()); |
|
79 | + wp_add_inline_style('widgets', $this->widget_css()); |
|
80 | 80 | |
81 | 81 | $sd_widget_scripts = true; |
82 | 82 | |
83 | 83 | // add shortcode insert button once |
84 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
85 | - if ( $this->is_preview() ) { |
|
86 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
84 | + add_action('media_buttons', array($this, 'shortcode_insert_button')); |
|
85 | + if ($this->is_preview()) { |
|
86 | + add_action('wp_footer', array($this, 'shortcode_insert_button_script')); |
|
87 | 87 | // this makes the insert button work for elementor |
88 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
88 | + add_action('elementor/editor/after_enqueue_scripts', array( |
|
89 | 89 | $this, |
90 | 90 | 'shortcode_insert_button_script' |
91 | - ) ); // for elementor |
|
91 | + )); // for elementor |
|
92 | 92 | } |
93 | 93 | // this makes the insert button work for cornerstone |
94 | - add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
94 | + add_action('wp_print_footer_scripts', array(__CLASS__, 'maybe_cornerstone_builder')); |
|
95 | 95 | |
96 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
97 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
96 | + add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings')); |
|
97 | + add_action('wp_ajax_super_duper_get_picker', array(__CLASS__, 'get_picker')); |
|
98 | 98 | |
99 | 99 | // add generator text to admin head |
100 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
100 | + add_action('admin_head', array($this, 'generator')); |
|
101 | 101 | } |
102 | 102 | |
103 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
103 | + do_action('wp_super_duper_widget_init', $options, $this); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
108 | 108 | */ |
109 | - public static function maybe_cornerstone_builder(){ |
|
110 | - if(did_action('cornerstone_before_boot_app')){ |
|
109 | + public static function maybe_cornerstone_builder() { |
|
110 | + if (did_action('cornerstone_before_boot_app')) { |
|
111 | 111 | self::shortcode_insert_button_script(); |
112 | 112 | } |
113 | 113 | } |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return string |
121 | 121 | */ |
122 | - public static function get_picker( $editor_id = '' ) { |
|
122 | + public static function get_picker($editor_id = '') { |
|
123 | 123 | |
124 | 124 | ob_start(); |
125 | - if ( isset( $_POST['editor_id'] ) ) { |
|
126 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
127 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
125 | + if (isset($_POST['editor_id'])) { |
|
126 | + $editor_id = esc_attr($_POST['editor_id']); |
|
127 | + } elseif (isset($_REQUEST['et_fb'])) { |
|
128 | 128 | $editor_id = 'main_content_content_vb_tiny_mce'; |
129 | 129 | } |
130 | 130 | |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | |
134 | 134 | <div class="sd-shortcode-left-wrap"> |
135 | 135 | <?php |
136 | - asort( $sd_widgets ); |
|
137 | - if ( ! empty( $sd_widgets ) ) { |
|
136 | + asort($sd_widgets); |
|
137 | + if (!empty($sd_widgets)) { |
|
138 | 138 | echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
139 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
140 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
141 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
139 | + echo "<option>" . __('Select shortcode') . "</option>"; |
|
140 | + foreach ($sd_widgets as $shortcode => $class) { |
|
141 | + echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>"; |
|
142 | 142 | } |
143 | 143 | echo "</select>"; |
144 | 144 | |
@@ -151,37 +151,37 @@ discard block |
||
151 | 151 | <div class="sd-shortcode-right-wrap"> |
152 | 152 | <textarea id='sd-shortcode-output' disabled></textarea> |
153 | 153 | <div id='sd-shortcode-output-actions'> |
154 | - <?php if ( $editor_id != '' ) { ?> |
|
154 | + <?php if ($editor_id != '') { ?> |
|
155 | 155 | <button class="button sd-insert-shortcode-button" |
156 | - onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
|
156 | + onclick="sd_insert_shortcode(<?php if (!empty($editor_id)) { |
|
157 | 157 | echo "'" . $editor_id . "'"; |
158 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
158 | + } ?>)"><?php _e('Insert shortcode'); ?></button> |
|
159 | 159 | <?php } ?> |
160 | 160 | <button class="button" |
161 | - onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
|
161 | + onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button> |
|
162 | 162 | </div> |
163 | 163 | </div> |
164 | 164 | <?php |
165 | 165 | |
166 | 166 | $html = ob_get_clean(); |
167 | 167 | |
168 | - if ( wp_doing_ajax() ) { |
|
168 | + if (wp_doing_ajax()) { |
|
169 | 169 | echo $html; |
170 | 170 | $should_die = true; |
171 | 171 | |
172 | 172 | // some builder get the editor via ajax so we should not die on those ocasions |
173 | 173 | $dont_die = array( |
174 | - 'parent_tag',// WP Bakery |
|
174 | + 'parent_tag', // WP Bakery |
|
175 | 175 | 'avia_request' // enfold |
176 | 176 | ); |
177 | 177 | |
178 | - foreach ( $dont_die as $request ) { |
|
179 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
178 | + foreach ($dont_die as $request) { |
|
179 | + if (isset($_REQUEST[$request])) { |
|
180 | 180 | $should_die = false; |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | - if ( $should_die ) { |
|
184 | + if ($should_die) { |
|
185 | 185 | wp_die(); |
186 | 186 | } |
187 | 187 | |
@@ -208,16 +208,16 @@ discard block |
||
208 | 208 | public static function get_widget_settings() { |
209 | 209 | global $sd_widgets; |
210 | 210 | |
211 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
212 | - if ( ! $shortcode ) { |
|
211 | + $shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : ''; |
|
212 | + if (!$shortcode) { |
|
213 | 213 | wp_die(); |
214 | 214 | } |
215 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
216 | - if ( ! $widget_args ) { |
|
215 | + $widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : ''; |
|
216 | + if (!$widget_args) { |
|
217 | 217 | wp_die(); |
218 | 218 | } |
219 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
220 | - if ( ! $class_name ) { |
|
219 | + $class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
220 | + if (!$class_name) { |
|
221 | 221 | wp_die(); |
222 | 222 | } |
223 | 223 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | $widget = new $class_name; |
226 | 226 | |
227 | 227 | ob_start(); |
228 | - $widget->form( array() ); |
|
228 | + $widget->form(array()); |
|
229 | 229 | $form = ob_get_clean(); |
230 | 230 | echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
231 | 231 | echo "<style>" . $widget->widget_css() . "</style>"; |
@@ -243,9 +243,9 @@ discard block |
||
243 | 243 | * @param string $editor_id Optional. Shortcode editor id. Default null. |
244 | 244 | * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
245 | 245 | */ |
246 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
246 | + public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') { |
|
247 | 247 | global $sd_widgets, $shortcode_insert_button_once; |
248 | - if ( $shortcode_insert_button_once ) { |
|
248 | + if ($shortcode_insert_button_once) { |
|
249 | 249 | return; |
250 | 250 | } |
251 | 251 | add_thickbox(); |
@@ -255,18 +255,18 @@ discard block |
||
255 | 255 | * Cornerstone makes us play dirty tricks :/ |
256 | 256 | * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
257 | 257 | */ |
258 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
258 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
259 | 259 | echo '<span id="insert-media-button">'; |
260 | 260 | } |
261 | 261 | |
262 | - echo self::shortcode_button( 'this', 'true' ); |
|
262 | + echo self::shortcode_button('this', 'true'); |
|
263 | 263 | |
264 | 264 | // see opening note |
265 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
265 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
266 | 266 | echo '</span>'; // end #insert-media-button |
267 | 267 | } |
268 | 268 | |
269 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
269 | + self::shortcode_insert_button_script($editor_id, $insert_shortcode_function); |
|
270 | 270 | $shortcode_insert_button_once = true; |
271 | 271 | } |
272 | 272 | |
@@ -278,12 +278,12 @@ discard block |
||
278 | 278 | * |
279 | 279 | * @return mixed |
280 | 280 | */ |
281 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
281 | + public static function shortcode_button($id = '', $search_for_id = '') { |
|
282 | 282 | ob_start(); |
283 | 283 | ?> |
284 | 284 | <span class="sd-lable-shortcode-inserter"> |
285 | 285 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
286 | - if ( $search_for_id ) { |
|
286 | + if ($search_for_id) { |
|
287 | 287 | echo "," . $search_for_id; |
288 | 288 | } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
289 | 289 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | $html = ob_get_clean(); |
300 | 300 | |
301 | 301 | // remove line breaks so we can use it in js |
302 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
302 | + return preg_replace("/\r|\n/", "", trim($html)); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | jQuery($this).data('sd-widget-enabled', true); |
358 | 358 | } |
359 | 359 | |
360 | - var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
360 | + var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
361 | 361 | var form = jQuery($this).parents('' + $selector + ''); |
362 | 362 | |
363 | 363 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -394,10 +394,10 @@ discard block |
||
394 | 394 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
395 | 395 | */ |
396 | 396 | |
397 | - return str_replace( array( |
|
397 | + return str_replace(array( |
|
398 | 398 | '<script>', |
399 | 399 | '</script>' |
400 | - ), '', $output ); |
|
400 | + ), '', $output); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | * @param string $editor_id |
409 | 409 | * @param string $insert_shortcode_function |
410 | 410 | */ |
411 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
411 | + public static function shortcode_insert_button_script($editor_id = '', $insert_shortcode_function = '') { |
|
412 | 412 | ?> |
413 | 413 | <style> |
414 | 414 | .sd-shortcode-left-wrap { |
@@ -528,15 +528,15 @@ discard block |
||
528 | 528 | } |
529 | 529 | </style> |
530 | 530 | <?php |
531 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
531 | + if (class_exists('SiteOrigin_Panels')) { |
|
532 | 532 | echo "<script>" . self::siteorigin_js() . "</script>"; |
533 | 533 | } |
534 | 534 | ?> |
535 | 535 | <script> |
536 | 536 | <?php |
537 | - if(! empty( $insert_shortcode_function )){ |
|
537 | + if (!empty($insert_shortcode_function)) { |
|
538 | 538 | echo $insert_shortcode_function; |
539 | - }else{ |
|
539 | + } else { |
|
540 | 540 | |
541 | 541 | /** |
542 | 542 | * Function for super duper insert shortcode. |
@@ -551,9 +551,9 @@ discard block |
||
551 | 551 | if (!$editor_id) { |
552 | 552 | |
553 | 553 | <?php |
554 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
554 | + if (isset($_REQUEST['et_fb'])) { |
|
555 | 555 | echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
556 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
556 | + } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') { |
|
557 | 557 | echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
558 | 558 | } else { |
559 | 559 | echo '$editor_id = "#wp-content-editor-container textarea";'; |
@@ -633,11 +633,11 @@ discard block |
||
633 | 633 | 'shortcode': $short_code, |
634 | 634 | 'attributes': 123, |
635 | 635 | 'post_id': 321, |
636 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
636 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
637 | 637 | }; |
638 | 638 | |
639 | 639 | if (typeof ajaxurl === 'undefined') { |
640 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' );?>"; |
|
640 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | jQuery.post(ajaxurl, data, function (response) { |
@@ -835,11 +835,11 @@ discard block |
||
835 | 835 | var data = { |
836 | 836 | 'action': 'super_duper_get_picker', |
837 | 837 | 'editor_id': $id, |
838 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_picker' );?>' |
|
838 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_picker'); ?>' |
|
839 | 839 | }; |
840 | 840 | |
841 | 841 | if (!ajaxurl) { |
842 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>"; |
|
842 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | jQuery.post(ajaxurl, data, function (response) { |
@@ -860,9 +860,9 @@ discard block |
||
860 | 860 | */ |
861 | 861 | function sd_shortcode_button($id) { |
862 | 862 | if ($id) { |
863 | - return '<?php echo self::shortcode_button( "\\''+\$id+'\\'" );?>'; |
|
863 | + return '<?php echo self::shortcode_button("\\''+\$id+'\\'"); ?>'; |
|
864 | 864 | } else { |
865 | - return '<?php echo self::shortcode_button();?>'; |
|
865 | + return '<?php echo self::shortcode_button(); ?>'; |
|
866 | 866 | } |
867 | 867 | } |
868 | 868 | |
@@ -904,10 +904,10 @@ discard block |
||
904 | 904 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
905 | 905 | */ |
906 | 906 | |
907 | - return str_replace( array( |
|
907 | + return str_replace(array( |
|
908 | 908 | '<style>', |
909 | 909 | '</style>' |
910 | - ), '', $output ); |
|
910 | + ), '', $output); |
|
911 | 911 | } |
912 | 912 | |
913 | 913 | /** |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | jQuery($this).data('sd-widget-enabled', true); |
978 | 978 | } |
979 | 979 | |
980 | - var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
980 | + var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
981 | 981 | var form = jQuery($this).parents('' + $selector + ''); |
982 | 982 | |
983 | 983 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -1069,7 +1069,7 @@ discard block |
||
1069 | 1069 | }); |
1070 | 1070 | |
1071 | 1071 | } |
1072 | - <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
|
1072 | + <?php do_action('wp_super_duper_widget_js', $this); ?> |
|
1073 | 1073 | </script> |
1074 | 1074 | <?php |
1075 | 1075 | $output = ob_get_clean(); |
@@ -1078,10 +1078,10 @@ discard block |
||
1078 | 1078 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1079 | 1079 | */ |
1080 | 1080 | |
1081 | - return str_replace( array( |
|
1081 | + return str_replace(array( |
|
1082 | 1082 | '<script>', |
1083 | 1083 | '</script>' |
1084 | - ), '', $output ); |
|
1084 | + ), '', $output); |
|
1085 | 1085 | } |
1086 | 1086 | |
1087 | 1087 | |
@@ -1092,14 +1092,14 @@ discard block |
||
1092 | 1092 | * |
1093 | 1093 | * @return mixed |
1094 | 1094 | */ |
1095 | - private function add_name_from_key( $options, $arguments = false ) { |
|
1096 | - if ( ! empty( $options['arguments'] ) ) { |
|
1097 | - foreach ( $options['arguments'] as $key => $val ) { |
|
1098 | - $options['arguments'][ $key ]['name'] = $key; |
|
1095 | + private function add_name_from_key($options, $arguments = false) { |
|
1096 | + if (!empty($options['arguments'])) { |
|
1097 | + foreach ($options['arguments'] as $key => $val) { |
|
1098 | + $options['arguments'][$key]['name'] = $key; |
|
1099 | 1099 | } |
1100 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
1101 | - foreach ( $options as $key => $val ) { |
|
1102 | - $options[ $key ]['name'] = $key; |
|
1100 | + } elseif ($arguments && is_array($options) && !empty($options)) { |
|
1101 | + foreach ($options as $key => $val) { |
|
1102 | + $options[$key]['name'] = $key; |
|
1103 | 1103 | } |
1104 | 1104 | } |
1105 | 1105 | |
@@ -1112,8 +1112,8 @@ discard block |
||
1112 | 1112 | * @since 1.0.0 |
1113 | 1113 | */ |
1114 | 1114 | public function register_shortcode() { |
1115 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
1116 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
1115 | + add_shortcode($this->base_id, array($this, 'shortcode_output')); |
|
1116 | + add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode')); |
|
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | /** |
@@ -1123,33 +1123,33 @@ discard block |
||
1123 | 1123 | */ |
1124 | 1124 | public static function render_shortcode() { |
1125 | 1125 | |
1126 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
1127 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1126 | + check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true); |
|
1127 | + if (!current_user_can('manage_options')) { |
|
1128 | 1128 | wp_die(); |
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | // we might need the $post value here so lets set it. |
1132 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
1133 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
1134 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
1132 | + if (isset($_POST['post_id']) && $_POST['post_id']) { |
|
1133 | + $post_obj = get_post(absint($_POST['post_id'])); |
|
1134 | + if (!empty($post_obj) && empty($post)) { |
|
1135 | 1135 | global $post; |
1136 | 1136 | $post = $post_obj; |
1137 | 1137 | } |
1138 | 1138 | } |
1139 | 1139 | |
1140 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
1141 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
1142 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
1140 | + if (isset($_POST['shortcode']) && $_POST['shortcode']) { |
|
1141 | + $shortcode_name = sanitize_title_with_dashes($_POST['shortcode']); |
|
1142 | + $attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
1143 | 1143 | $attributes = ''; |
1144 | - if ( ! empty( $attributes_array ) ) { |
|
1145 | - foreach ( $attributes_array as $key => $value ) { |
|
1146 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
1144 | + if (!empty($attributes_array)) { |
|
1145 | + foreach ($attributes_array as $key => $value) { |
|
1146 | + $attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' "; |
|
1147 | 1147 | } |
1148 | 1148 | } |
1149 | 1149 | |
1150 | 1150 | $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
1151 | 1151 | |
1152 | - echo do_shortcode( $shortcode ); |
|
1152 | + echo do_shortcode($shortcode); |
|
1153 | 1153 | |
1154 | 1154 | } |
1155 | 1155 | wp_die(); |
@@ -1163,37 +1163,37 @@ discard block |
||
1163 | 1163 | * |
1164 | 1164 | * @return string |
1165 | 1165 | */ |
1166 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
1167 | - $args = self::argument_values( $args ); |
|
1166 | + public function shortcode_output($args = array(), $content = '') { |
|
1167 | + $args = self::argument_values($args); |
|
1168 | 1168 | |
1169 | 1169 | // add extra argument so we know its a output to gutenberg |
1170 | 1170 | //$args |
1171 | - $args = $this->string_to_bool( $args ); |
|
1171 | + $args = $this->string_to_bool($args); |
|
1172 | 1172 | |
1173 | 1173 | |
1174 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
1174 | + $calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : ''; |
|
1175 | 1175 | |
1176 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
1177 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
1176 | + $calss = apply_filters('wp_super_duper_div_classname', $calss, $args, $this); |
|
1177 | + $calss = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this); |
|
1178 | 1178 | |
1179 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
1180 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
1179 | + $attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this); |
|
1180 | + $attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this); |
|
1181 | 1181 | |
1182 | 1182 | $shortcode_args = array(); |
1183 | 1183 | $output = ''; |
1184 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
1185 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
1186 | - if ( $main_content && ! $no_wrap ) { |
|
1184 | + $no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false; |
|
1185 | + $main_content = $this->output($args, $shortcode_args, $content); |
|
1186 | + if ($main_content && !$no_wrap) { |
|
1187 | 1187 | // wrap the shortcode in a dive with the same class as the widget |
1188 | 1188 | $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
1189 | - if ( ! empty( $args['title'] ) ) { |
|
1189 | + if (!empty($args['title'])) { |
|
1190 | 1190 | // if its a shortcode and there is a title try to grab the title wrappers |
1191 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
1192 | - if ( empty( $instance ) ) { |
|
1191 | + $shortcode_args = array('before_title' => '', 'after_title' => ''); |
|
1192 | + if (empty($instance)) { |
|
1193 | 1193 | global $wp_registered_sidebars; |
1194 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
1195 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
1196 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
1194 | + if (!empty($wp_registered_sidebars)) { |
|
1195 | + foreach ($wp_registered_sidebars as $sidebar) { |
|
1196 | + if (!empty($sidebar['before_title'])) { |
|
1197 | 1197 | $shortcode_args['before_title'] = $sidebar['before_title']; |
1198 | 1198 | $shortcode_args['after_title'] = $sidebar['after_title']; |
1199 | 1199 | break; |
@@ -1201,17 +1201,17 @@ discard block |
||
1201 | 1201 | } |
1202 | 1202 | } |
1203 | 1203 | } |
1204 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
1204 | + $output .= $this->output_title($shortcode_args, $args); |
|
1205 | 1205 | } |
1206 | 1206 | $output .= $main_content; |
1207 | 1207 | $output .= '</div>'; |
1208 | - } elseif ( $main_content && $no_wrap ) { |
|
1208 | + } elseif ($main_content && $no_wrap) { |
|
1209 | 1209 | $output .= $main_content; |
1210 | 1210 | } |
1211 | 1211 | |
1212 | 1212 | // if preview show a placeholder if empty |
1213 | - if ( $this->is_preview() && $output == '' ) { |
|
1214 | - $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
1213 | + if ($this->is_preview() && $output == '') { |
|
1214 | + $output = $this->preview_placeholder_text("[{" . $this->base_id . "}]"); |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | return $output; |
@@ -1224,8 +1224,8 @@ discard block |
||
1224 | 1224 | * |
1225 | 1225 | * @return string |
1226 | 1226 | */ |
1227 | - public function preview_placeholder_text( $name = '' ) { |
|
1228 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
1227 | + public function preview_placeholder_text($name = '') { |
|
1228 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf(__('Placeholder for: %s'), $name) . "</div>"; |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | /** |
@@ -1235,13 +1235,13 @@ discard block |
||
1235 | 1235 | * |
1236 | 1236 | * @return mixed |
1237 | 1237 | */ |
1238 | - public function string_to_bool( $options ) { |
|
1238 | + public function string_to_bool($options) { |
|
1239 | 1239 | // convert bool strings to booleans |
1240 | - foreach ( $options as $key => $val ) { |
|
1241 | - if ( $val == 'false' ) { |
|
1242 | - $options[ $key ] = false; |
|
1243 | - } elseif ( $val == 'true' ) { |
|
1244 | - $options[ $key ] = true; |
|
1240 | + foreach ($options as $key => $val) { |
|
1241 | + if ($val == 'false') { |
|
1242 | + $options[$key] = false; |
|
1243 | + } elseif ($val == 'true') { |
|
1244 | + $options[$key] = true; |
|
1245 | 1245 | } |
1246 | 1246 | } |
1247 | 1247 | |
@@ -1257,27 +1257,27 @@ discard block |
||
1257 | 1257 | * |
1258 | 1258 | * @return array |
1259 | 1259 | */ |
1260 | - public function argument_values( $instance ) { |
|
1260 | + public function argument_values($instance) { |
|
1261 | 1261 | $argument_values = array(); |
1262 | 1262 | |
1263 | 1263 | // set widget instance |
1264 | 1264 | $this->instance = $instance; |
1265 | 1265 | |
1266 | - if ( empty( $this->arguments ) ) { |
|
1266 | + if (empty($this->arguments)) { |
|
1267 | 1267 | $this->arguments = $this->get_arguments(); |
1268 | 1268 | } |
1269 | 1269 | |
1270 | - if ( ! empty( $this->arguments ) ) { |
|
1271 | - foreach ( $this->arguments as $key => $args ) { |
|
1270 | + if (!empty($this->arguments)) { |
|
1271 | + foreach ($this->arguments as $key => $args) { |
|
1272 | 1272 | // set the input name from the key |
1273 | 1273 | $args['name'] = $key; |
1274 | 1274 | // |
1275 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
1276 | - if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
1275 | + $argument_values[$key] = isset($instance[$key]) ? $instance[$key] : ''; |
|
1276 | + if ($args['type'] == 'checkbox' && $argument_values[$key] == '') { |
|
1277 | 1277 | // don't set default for an empty checkbox |
1278 | 1278 | } |
1279 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1280 | - $argument_values[ $key ] = $args['default']; |
|
1279 | + elseif ($argument_values[$key] == '' && isset($args['default'])) { |
|
1280 | + $argument_values[$key] = $args['default']; |
|
1281 | 1281 | } |
1282 | 1282 | } |
1283 | 1283 | } |
@@ -1304,12 +1304,12 @@ discard block |
||
1304 | 1304 | * @return array Get arguments. |
1305 | 1305 | */ |
1306 | 1306 | public function get_arguments() { |
1307 | - if ( empty( $this->arguments ) ) { |
|
1307 | + if (empty($this->arguments)) { |
|
1308 | 1308 | $this->arguments = $this->set_arguments(); |
1309 | 1309 | } |
1310 | 1310 | |
1311 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
1312 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
1311 | + $this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance); |
|
1312 | + $this->arguments = $this->add_name_from_key($this->arguments, true); |
|
1313 | 1313 | |
1314 | 1314 | return $this->arguments; |
1315 | 1315 | } |
@@ -1321,7 +1321,7 @@ discard block |
||
1321 | 1321 | * @param array $widget_args |
1322 | 1322 | * @param string $content |
1323 | 1323 | */ |
1324 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
1324 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
1325 | 1325 | |
1326 | 1326 | } |
1327 | 1327 | |
@@ -1329,10 +1329,10 @@ discard block |
||
1329 | 1329 | * Add the dynamic block code inline when the wp-block in enqueued. |
1330 | 1330 | */ |
1331 | 1331 | public function register_block() { |
1332 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
1333 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
1332 | + wp_add_inline_script('wp-blocks', $this->block()); |
|
1333 | + if (class_exists('SiteOrigin_Panels')) { |
|
1334 | 1334 | |
1335 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
1335 | + wp_add_inline_script('wp-blocks', $this->siteorigin_js()); |
|
1336 | 1336 | |
1337 | 1337 | } |
1338 | 1338 | } |
@@ -1347,13 +1347,13 @@ discard block |
||
1347 | 1347 | $show = false; |
1348 | 1348 | $arguments = $this->arguments; |
1349 | 1349 | |
1350 | - if ( empty( $arguments ) ) { |
|
1350 | + if (empty($arguments)) { |
|
1351 | 1351 | $arguments = $this->get_arguments(); |
1352 | 1352 | } |
1353 | 1353 | |
1354 | - if ( ! empty( $arguments ) ) { |
|
1355 | - foreach ( $arguments as $argument ) { |
|
1356 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
1354 | + if (!empty($arguments)) { |
|
1355 | + foreach ($arguments as $argument) { |
|
1356 | + if (isset($argument['advanced']) && $argument['advanced']) { |
|
1357 | 1357 | $show = true; |
1358 | 1358 | } |
1359 | 1359 | } |
@@ -1405,12 +1405,12 @@ discard block |
||
1405 | 1405 | * @return {?WPBlock} The block, if it has been successfully |
1406 | 1406 | * registered; otherwise `undefined`. |
1407 | 1407 | */ |
1408 | - registerBlockType('<?php echo str_replace( "_", "-", sanitize_title_with_dashes( $this->options['textdomain'] ) . '/' . sanitize_title_with_dashes( $this->options['class_name'] ) ); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
|
1409 | - title: '<?php echo $this->options['name'];?>', // Block title. |
|
1410 | - description: '<?php echo esc_attr( $this->options['widget_ops']['description'] )?>', // Block title. |
|
1411 | - icon: '<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
|
1412 | - category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
|
1413 | - <?php if ( isset( $this->options['block-keywords'] ) ) { |
|
1408 | + registerBlockType('<?php echo str_replace("_", "-", sanitize_title_with_dashes($this->options['textdomain']) . '/' . sanitize_title_with_dashes($this->options['class_name'])); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
|
1409 | + title: '<?php echo $this->options['name']; ?>', // Block title. |
|
1410 | + description: '<?php echo esc_attr($this->options['widget_ops']['description'])?>', // Block title. |
|
1411 | + icon: '<?php echo isset($this->options['block-icon']) ? esc_attr($this->options['block-icon']) : 'shield-alt'; ?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
|
1412 | + category: '<?php echo isset($this->options['block-category']) ? esc_attr($this->options['block-category']) : 'common'; ?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
|
1413 | + <?php if (isset($this->options['block-keywords'])) { |
|
1414 | 1414 | echo "keywords : " . $this->options['block-keywords'] . ","; |
1415 | 1415 | }?> |
1416 | 1416 | |
@@ -1420,10 +1420,10 @@ discard block |
||
1420 | 1420 | |
1421 | 1421 | $show_alignment = false; |
1422 | 1422 | |
1423 | - if ( ! empty( $this->arguments ) ) { |
|
1423 | + if (!empty($this->arguments)) { |
|
1424 | 1424 | echo "attributes : {"; |
1425 | 1425 | |
1426 | - if ( $show_advanced ) { |
|
1426 | + if ($show_advanced) { |
|
1427 | 1427 | echo "show_advanced: {"; |
1428 | 1428 | echo " type: 'boolean',"; |
1429 | 1429 | echo " default: false,"; |
@@ -1431,42 +1431,42 @@ discard block |
||
1431 | 1431 | } |
1432 | 1432 | |
1433 | 1433 | // block wrap element |
1434 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
1434 | + if (isset($this->options['block-wrap'])) { //@todo we should validate this? |
|
1435 | 1435 | echo "block_wrap: {"; |
1436 | 1436 | echo " type: 'string',"; |
1437 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
1437 | + echo " default: '" . esc_attr($this->options['block-wrap']) . "',"; |
|
1438 | 1438 | echo "},"; |
1439 | 1439 | } |
1440 | 1440 | |
1441 | 1441 | |
1442 | - foreach ( $this->arguments as $key => $args ) { |
|
1442 | + foreach ($this->arguments as $key => $args) { |
|
1443 | 1443 | |
1444 | 1444 | // set if we should show alignment |
1445 | - if ( $key == 'alignment' ) { |
|
1445 | + if ($key == 'alignment') { |
|
1446 | 1446 | $show_alignment = true; |
1447 | 1447 | } |
1448 | 1448 | |
1449 | 1449 | $extra = ''; |
1450 | 1450 | |
1451 | - if ( $args['type'] == 'checkbox' ) { |
|
1451 | + if ($args['type'] == 'checkbox') { |
|
1452 | 1452 | $type = 'boolean'; |
1453 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
1454 | - } elseif ( $args['type'] == 'number' ) { |
|
1453 | + $default = isset($args['default']) && $args['default'] ? 'true' : 'false'; |
|
1454 | + } elseif ($args['type'] == 'number') { |
|
1455 | 1455 | $type = 'number'; |
1456 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1457 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
1456 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
1457 | + } elseif ($args['type'] == 'select' && !empty($args['multiple'])) { |
|
1458 | 1458 | $type = 'array'; |
1459 | - if ( is_array( $args['default'] ) ) { |
|
1460 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
1459 | + if (is_array($args['default'])) { |
|
1460 | + $default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]"; |
|
1461 | 1461 | } else { |
1462 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1462 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
1463 | 1463 | } |
1464 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
1464 | + } elseif ($args['type'] == 'multiselect') { |
|
1465 | 1465 | $type = 'array'; |
1466 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1466 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
1467 | 1467 | } else { |
1468 | 1468 | $type = 'string'; |
1469 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1469 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
1470 | 1470 | } |
1471 | 1471 | echo $key . " : {"; |
1472 | 1472 | echo "type : '$type',"; |
@@ -1496,12 +1496,12 @@ discard block |
||
1496 | 1496 | is_fetching = true; |
1497 | 1497 | var data = { |
1498 | 1498 | 'action': 'super_duper_output_shortcode', |
1499 | - 'shortcode': '<?php echo $this->options['base_id'];?>', |
|
1499 | + 'shortcode': '<?php echo $this->options['base_id']; ?>', |
|
1500 | 1500 | 'attributes': props.attributes, |
1501 | - 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
|
1501 | + 'post_id': <?php global $post; if (isset($post->ID)) { |
|
1502 | 1502 | echo $post->ID; |
1503 | 1503 | }?>, |
1504 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
1504 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
1505 | 1505 | }; |
1506 | 1506 | |
1507 | 1507 | jQuery.post(ajaxurl, data, function (response) { |
@@ -1510,7 +1510,7 @@ discard block |
||
1510 | 1510 | |
1511 | 1511 | // if the content is empty then we place some placeholder text |
1512 | 1512 | if (env == '') { |
1513 | - env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e( 'Placeholder for: ' );?>" + props.name + "</div>"; |
|
1513 | + env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e('Placeholder for: '); ?>" + props.name + "</div>"; |
|
1514 | 1514 | } |
1515 | 1515 | |
1516 | 1516 | props.setAttributes({content: env}); |
@@ -1529,7 +1529,7 @@ discard block |
||
1529 | 1529 | |
1530 | 1530 | el(wp.editor.BlockControls, {key: 'controls'}, |
1531 | 1531 | |
1532 | - <?php if($show_alignment){?> |
|
1532 | + <?php if ($show_alignment) {?> |
|
1533 | 1533 | el( |
1534 | 1534 | wp.editor.AlignmentToolbar, |
1535 | 1535 | { |
@@ -1547,9 +1547,9 @@ discard block |
||
1547 | 1547 | |
1548 | 1548 | <?php |
1549 | 1549 | |
1550 | - if(! empty( $this->arguments )){ |
|
1550 | + if (!empty($this->arguments)) { |
|
1551 | 1551 | |
1552 | - if ( $show_advanced ) { |
|
1552 | + if ($show_advanced) { |
|
1553 | 1553 | ?> |
1554 | 1554 | el( |
1555 | 1555 | wp.components.ToggleControl, |
@@ -1565,76 +1565,76 @@ discard block |
||
1565 | 1565 | |
1566 | 1566 | } |
1567 | 1567 | |
1568 | - foreach($this->arguments as $key => $args){ |
|
1569 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
1568 | + foreach ($this->arguments as $key => $args) { |
|
1569 | + $custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : ''; |
|
1570 | 1570 | $options = ''; |
1571 | 1571 | $extra = ''; |
1572 | 1572 | $require = ''; |
1573 | 1573 | $onchange = "props.setAttributes({ $key: $key } )"; |
1574 | 1574 | $value = "props.attributes.$key"; |
1575 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
1576 | - if ( in_array( $args['type'], $text_type ) ) { |
|
1575 | + $text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'color'); |
|
1576 | + if (in_array($args['type'], $text_type)) { |
|
1577 | 1577 | $type = 'TextControl'; |
1578 | 1578 | // Save numbers as numbers and not strings |
1579 | - if ( $args['type'] == 'number' ) { |
|
1579 | + if ($args['type'] == 'number') { |
|
1580 | 1580 | $onchange = "props.setAttributes({ $key: Number($key) } )"; |
1581 | 1581 | } |
1582 | 1582 | } |
1583 | 1583 | // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we may have to add our own https://github.com/WordPress/gutenberg/issues/14378 |
1584 | 1584 | // $type = 'ColorPicker'; |
1585 | 1585 | // } |
1586 | - elseif ( $args['type'] == 'checkbox' ) { |
|
1586 | + elseif ($args['type'] == 'checkbox') { |
|
1587 | 1587 | $type = 'CheckboxControl'; |
1588 | 1588 | $extra .= "checked: props.attributes.$key,"; |
1589 | 1589 | $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
1590 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
1590 | + } elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') { |
|
1591 | 1591 | $type = 'SelectControl'; |
1592 | - if ( ! empty( $args['options'] ) ) { |
|
1592 | + if (!empty($args['options'])) { |
|
1593 | 1593 | $options .= "options : ["; |
1594 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
1595 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
1594 | + foreach ($args['options'] as $option_val => $option_label) { |
|
1595 | + $options .= "{ value : '" . esc_attr($option_val) . "', label : '" . esc_attr($option_label) . "' },"; |
|
1596 | 1596 | } |
1597 | 1597 | $options .= "],"; |
1598 | 1598 | } |
1599 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
1599 | + if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
1600 | 1600 | $extra .= ' multiple: true, '; |
1601 | 1601 | //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
1602 | 1602 | //$value = "['edit', 'delete']"; |
1603 | 1603 | } |
1604 | - } elseif ( $args['type'] == 'alignment' ) { |
|
1604 | + } elseif ($args['type'] == 'alignment') { |
|
1605 | 1605 | $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
1606 | 1606 | } else { |
1607 | - continue;// if we have not implemented the control then don't break the JS. |
|
1607 | + continue; // if we have not implemented the control then don't break the JS. |
|
1608 | 1608 | } |
1609 | 1609 | |
1610 | 1610 | // add show only if advanced |
1611 | - if ( ! empty( $args['advanced'] ) ) { |
|
1611 | + if (!empty($args['advanced'])) { |
|
1612 | 1612 | echo "props.attributes.show_advanced && "; |
1613 | 1613 | } |
1614 | 1614 | // add setting require if defined |
1615 | - if ( ! empty( $args['element_require'] ) ) { |
|
1616 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
1615 | + if (!empty($args['element_require'])) { |
|
1616 | + echo $this->block_props_replace($args['element_require'], true) . " && "; |
|
1617 | 1617 | } |
1618 | 1618 | ?> |
1619 | 1619 | el( |
1620 | - wp.components.<?php echo esc_attr( $type );?>, |
|
1620 | + wp.components.<?php echo esc_attr($type); ?>, |
|
1621 | 1621 | { |
1622 | - label: '<?php echo esc_attr( $args['title'] );?>', |
|
1623 | - help: '<?php if ( isset( $args['desc'] ) ) { |
|
1624 | - echo esc_attr( $args['desc'] ); |
|
1622 | + label: '<?php echo esc_attr($args['title']); ?>', |
|
1623 | + help: '<?php if (isset($args['desc'])) { |
|
1624 | + echo esc_attr($args['desc']); |
|
1625 | 1625 | }?>', |
1626 | - value: <?php echo $value;?>, |
|
1627 | - <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
|
1628 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
1626 | + value: <?php echo $value; ?>, |
|
1627 | + <?php if ($type == 'TextControl' && $args['type'] != 'text') { |
|
1628 | + echo "type: '" . esc_attr($args['type']) . "',"; |
|
1629 | 1629 | }?> |
1630 | - <?php if ( ! empty( $args['placeholder'] ) ) { |
|
1631 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
1630 | + <?php if (!empty($args['placeholder'])) { |
|
1631 | + echo "placeholder: '" . esc_attr($args['placeholder']) . "',"; |
|
1632 | 1632 | }?> |
1633 | - <?php echo $options;?> |
|
1634 | - <?php echo $extra;?> |
|
1635 | - <?php echo $custom_attributes;?> |
|
1636 | - onChange: function ( <?php echo $key;?> ) { |
|
1637 | - <?php echo $onchange;?> |
|
1633 | + <?php echo $options; ?> |
|
1634 | + <?php echo $extra; ?> |
|
1635 | + <?php echo $custom_attributes; ?> |
|
1636 | + onChange: function ( <?php echo $key; ?> ) { |
|
1637 | + <?php echo $onchange; ?> |
|
1638 | 1638 | } |
1639 | 1639 | } |
1640 | 1640 | ), |
@@ -1647,9 +1647,9 @@ discard block |
||
1647 | 1647 | |
1648 | 1648 | <?php |
1649 | 1649 | // If the user sets block-output array then build it |
1650 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
1651 | - $this->block_element( $this->options['block-output'] ); |
|
1652 | - }else{ |
|
1650 | + if (!empty($this->options['block-output'])) { |
|
1651 | + $this->block_element($this->options['block-output']); |
|
1652 | + } else { |
|
1653 | 1653 | // if no block-output is set then we try and get the shortcode html output via ajax. |
1654 | 1654 | ?> |
1655 | 1655 | el('div', { |
@@ -1673,14 +1673,14 @@ discard block |
||
1673 | 1673 | var align = ''; |
1674 | 1674 | |
1675 | 1675 | // build the shortcode. |
1676 | - var content = "[<?php echo $this->options['base_id'];?>"; |
|
1676 | + var content = "[<?php echo $this->options['base_id']; ?>"; |
|
1677 | 1677 | <?php |
1678 | 1678 | |
1679 | - if(! empty( $this->arguments )){ |
|
1680 | - foreach($this->arguments as $key => $args){ |
|
1679 | + if (!empty($this->arguments)) { |
|
1680 | + foreach ($this->arguments as $key => $args) { |
|
1681 | 1681 | ?> |
1682 | - if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
|
1683 | - content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
|
1682 | + if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) { |
|
1683 | + content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' "; |
|
1684 | 1684 | } |
1685 | 1685 | <?php |
1686 | 1686 | } |
@@ -1721,10 +1721,10 @@ discard block |
||
1721 | 1721 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1722 | 1722 | */ |
1723 | 1723 | |
1724 | - return str_replace( array( |
|
1724 | + return str_replace(array( |
|
1725 | 1725 | '<script>', |
1726 | 1726 | '</script>' |
1727 | - ), '', $output ); |
|
1727 | + ), '', $output); |
|
1728 | 1728 | } |
1729 | 1729 | |
1730 | 1730 | /** |
@@ -1736,16 +1736,16 @@ discard block |
||
1736 | 1736 | * |
1737 | 1737 | * @return string |
1738 | 1738 | */ |
1739 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
1739 | + public function array_to_attributes($custom_attributes, $html = false) { |
|
1740 | 1740 | $attributes = ''; |
1741 | - if ( ! empty( $custom_attributes ) ) { |
|
1741 | + if (!empty($custom_attributes)) { |
|
1742 | 1742 | |
1743 | - if ( $html ) { |
|
1744 | - foreach ( $custom_attributes as $key => $val ) { |
|
1743 | + if ($html) { |
|
1744 | + foreach ($custom_attributes as $key => $val) { |
|
1745 | 1745 | $attributes .= " $key='$val' "; |
1746 | 1746 | } |
1747 | 1747 | } else { |
1748 | - foreach ( $custom_attributes as $key => $val ) { |
|
1748 | + foreach ($custom_attributes as $key => $val) { |
|
1749 | 1749 | $attributes .= "'$key': '$val',"; |
1750 | 1750 | } |
1751 | 1751 | } |
@@ -1761,86 +1761,86 @@ discard block |
||
1761 | 1761 | * |
1762 | 1762 | * @param $args |
1763 | 1763 | */ |
1764 | - public function block_element( $args ) { |
|
1764 | + public function block_element($args) { |
|
1765 | 1765 | |
1766 | 1766 | |
1767 | - if ( ! empty( $args ) ) { |
|
1768 | - foreach ( $args as $element => $new_args ) { |
|
1767 | + if (!empty($args)) { |
|
1768 | + foreach ($args as $element => $new_args) { |
|
1769 | 1769 | |
1770 | - if ( is_array( $new_args ) ) { // its an element |
|
1770 | + if (is_array($new_args)) { // its an element |
|
1771 | 1771 | |
1772 | 1772 | |
1773 | - if ( isset( $new_args['element'] ) ) { |
|
1773 | + if (isset($new_args['element'])) { |
|
1774 | 1774 | |
1775 | - if ( isset( $new_args['element_require'] ) ) { |
|
1776 | - echo str_replace( array( |
|
1775 | + if (isset($new_args['element_require'])) { |
|
1776 | + echo str_replace(array( |
|
1777 | 1777 | "'+", |
1778 | 1778 | "+'" |
1779 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
1780 | - unset( $new_args['element_require'] ); |
|
1779 | + ), '', $this->block_props_replace($new_args['element_require'])) . " && "; |
|
1780 | + unset($new_args['element_require']); |
|
1781 | 1781 | } |
1782 | 1782 | |
1783 | 1783 | echo "\n el( '" . $new_args['element'] . "', {"; |
1784 | 1784 | |
1785 | 1785 | // get the attributes |
1786 | - foreach ( $new_args as $new_key => $new_value ) { |
|
1786 | + foreach ($new_args as $new_key => $new_value) { |
|
1787 | 1787 | |
1788 | 1788 | |
1789 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
1789 | + if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) { |
|
1790 | 1790 | // do nothing |
1791 | 1791 | } else { |
1792 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
1792 | + echo $this->block_element(array($new_key => $new_value)); |
|
1793 | 1793 | } |
1794 | 1794 | } |
1795 | 1795 | |
1796 | - echo "},";// end attributes |
|
1796 | + echo "},"; // end attributes |
|
1797 | 1797 | |
1798 | 1798 | // get the content |
1799 | 1799 | $first_item = 0; |
1800 | - foreach ( $new_args as $new_key => $new_value ) { |
|
1801 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
1800 | + foreach ($new_args as $new_key => $new_value) { |
|
1801 | + if ($new_key === 'content' || is_array($new_value)) { |
|
1802 | 1802 | |
1803 | - if ( $new_key === 'content' ) { |
|
1804 | - echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
1803 | + if ($new_key === 'content') { |
|
1804 | + echo "'" . $this->block_props_replace($new_value) . "'"; |
|
1805 | 1805 | } |
1806 | 1806 | |
1807 | - if ( is_array( $new_value ) ) { |
|
1807 | + if (is_array($new_value)) { |
|
1808 | 1808 | |
1809 | - if ( isset( $new_value['element_require'] ) ) { |
|
1810 | - echo str_replace( array( |
|
1809 | + if (isset($new_value['element_require'])) { |
|
1810 | + echo str_replace(array( |
|
1811 | 1811 | "'+", |
1812 | 1812 | "+'" |
1813 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
1814 | - unset( $new_value['element_require'] ); |
|
1813 | + ), '', $this->block_props_replace($new_value['element_require'])) . " && "; |
|
1814 | + unset($new_value['element_require']); |
|
1815 | 1815 | } |
1816 | 1816 | |
1817 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
1817 | + if (isset($new_value['element_repeat'])) { |
|
1818 | 1818 | $x = 1; |
1819 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
1820 | - $this->block_element( array( '' => $new_value ) ); |
|
1821 | - $x ++; |
|
1819 | + while ($x <= absint($new_value['element_repeat'])) { |
|
1820 | + $this->block_element(array('' => $new_value)); |
|
1821 | + $x++; |
|
1822 | 1822 | } |
1823 | 1823 | } else { |
1824 | - $this->block_element( array( '' => $new_value ) ); |
|
1824 | + $this->block_element(array('' => $new_value)); |
|
1825 | 1825 | } |
1826 | 1826 | } |
1827 | - $first_item ++; |
|
1827 | + $first_item++; |
|
1828 | 1828 | } |
1829 | 1829 | } |
1830 | 1830 | |
1831 | - echo ")";// end content |
|
1831 | + echo ")"; // end content |
|
1832 | 1832 | |
1833 | 1833 | echo ", \n"; |
1834 | 1834 | |
1835 | 1835 | } |
1836 | 1836 | } else { |
1837 | 1837 | |
1838 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
1839 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
1840 | - } elseif ( $element == 'style' ) { |
|
1841 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
1838 | + if (substr($element, 0, 3) === "if_") { |
|
1839 | + echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ","; |
|
1840 | + } elseif ($element == 'style') { |
|
1841 | + echo $element . ": " . $this->block_props_replace($new_args) . ","; |
|
1842 | 1842 | } else { |
1843 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
1843 | + echo $element . ": '" . $this->block_props_replace($new_args) . "',"; |
|
1844 | 1844 | } |
1845 | 1845 | |
1846 | 1846 | } |
@@ -1855,12 +1855,12 @@ discard block |
||
1855 | 1855 | * |
1856 | 1856 | * @return mixed |
1857 | 1857 | */ |
1858 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
1858 | + public function block_props_replace($string, $no_wrap = false) { |
|
1859 | 1859 | |
1860 | - if ( $no_wrap ) { |
|
1861 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
1860 | + if ($no_wrap) { |
|
1861 | + $string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string); |
|
1862 | 1862 | } else { |
1863 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
1863 | + $string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string); |
|
1864 | 1864 | } |
1865 | 1865 | |
1866 | 1866 | return $string; |
@@ -1872,37 +1872,37 @@ discard block |
||
1872 | 1872 | * @param array $args |
1873 | 1873 | * @param array $instance |
1874 | 1874 | */ |
1875 | - public function widget( $args, $instance ) { |
|
1875 | + public function widget($args, $instance) { |
|
1876 | 1876 | |
1877 | 1877 | // get the filtered values |
1878 | - $argument_values = $this->argument_values( $instance ); |
|
1879 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
1880 | - $output = $this->output( $argument_values, $args ); |
|
1878 | + $argument_values = $this->argument_values($instance); |
|
1879 | + $argument_values = $this->string_to_bool($argument_values); |
|
1880 | + $output = $this->output($argument_values, $args); |
|
1881 | 1881 | |
1882 | - if ( $output ) { |
|
1882 | + if ($output) { |
|
1883 | 1883 | // Before widget |
1884 | 1884 | $before_widget = $args['before_widget']; |
1885 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
1886 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
1885 | + $before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this); |
|
1886 | + $before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this); |
|
1887 | 1887 | |
1888 | 1888 | // After widget |
1889 | 1889 | $after_widget = $args['after_widget']; |
1890 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
1891 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
1890 | + $after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this); |
|
1891 | + $after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this); |
|
1892 | 1892 | |
1893 | 1893 | echo $before_widget; |
1894 | 1894 | // elementor strips the widget wrapping div so we check for and add it back if needed |
1895 | - if ( $this->is_elementor_widget_output() ) { |
|
1896 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
1895 | + if ($this->is_elementor_widget_output()) { |
|
1896 | + echo !empty($this->options['widget_ops']['classname']) ? "<span class='" . esc_attr($this->options['widget_ops']['classname']) . "'>" : ''; |
|
1897 | 1897 | } |
1898 | - echo $this->output_title( $args, $instance ); |
|
1898 | + echo $this->output_title($args, $instance); |
|
1899 | 1899 | echo $output; |
1900 | - if ( $this->is_elementor_widget_output() ) { |
|
1901 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
1900 | + if ($this->is_elementor_widget_output()) { |
|
1901 | + echo !empty($this->options['widget_ops']['classname']) ? "</span>" : ''; |
|
1902 | 1902 | } |
1903 | 1903 | echo $after_widget; |
1904 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
1905 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
1904 | + } elseif ($this->is_preview() && $output == '') {// if preview show a placeholder if empty |
|
1905 | + $output = $this->preview_placeholder_text("{{" . $this->base_id . "}}"); |
|
1906 | 1906 | echo $output; |
1907 | 1907 | } |
1908 | 1908 | } |
@@ -1915,7 +1915,7 @@ discard block |
||
1915 | 1915 | */ |
1916 | 1916 | public function is_elementor_widget_output() { |
1917 | 1917 | $result = false; |
1918 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
1918 | + if (defined('ELEMENTOR_VERSION') && isset($this->number) && $this->number == 'REPLACE_TO_ID') { |
|
1919 | 1919 | $result = true; |
1920 | 1920 | } |
1921 | 1921 | |
@@ -1930,7 +1930,7 @@ discard block |
||
1930 | 1930 | */ |
1931 | 1931 | public function is_elementor_preview() { |
1932 | 1932 | $result = false; |
1933 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
1933 | + if (isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax')) { |
|
1934 | 1934 | $result = true; |
1935 | 1935 | } |
1936 | 1936 | |
@@ -1945,7 +1945,7 @@ discard block |
||
1945 | 1945 | */ |
1946 | 1946 | public function is_divi_preview() { |
1947 | 1947 | $result = false; |
1948 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
1948 | + if (isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor')) { |
|
1949 | 1949 | $result = true; |
1950 | 1950 | } |
1951 | 1951 | |
@@ -1960,7 +1960,7 @@ discard block |
||
1960 | 1960 | */ |
1961 | 1961 | public function is_beaver_preview() { |
1962 | 1962 | $result = false; |
1963 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
1963 | + if (isset($_REQUEST['fl_builder'])) { |
|
1964 | 1964 | $result = true; |
1965 | 1965 | } |
1966 | 1966 | |
@@ -1975,7 +1975,7 @@ discard block |
||
1975 | 1975 | */ |
1976 | 1976 | public function is_siteorigin_preview() { |
1977 | 1977 | $result = false; |
1978 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
1978 | + if (!empty($_REQUEST['siteorigin_panels_live_editor'])) { |
|
1979 | 1979 | $result = true; |
1980 | 1980 | } |
1981 | 1981 | |
@@ -1990,7 +1990,7 @@ discard block |
||
1990 | 1990 | */ |
1991 | 1991 | public function is_cornerstone_preview() { |
1992 | 1992 | $result = false; |
1993 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
1993 | + if (!empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint') { |
|
1994 | 1994 | $result = true; |
1995 | 1995 | } |
1996 | 1996 | |
@@ -2005,15 +2005,15 @@ discard block |
||
2005 | 2005 | */ |
2006 | 2006 | public function is_preview() { |
2007 | 2007 | $preview = false; |
2008 | - if ( $this->is_divi_preview() ) { |
|
2008 | + if ($this->is_divi_preview()) { |
|
2009 | 2009 | $preview = true; |
2010 | - } elseif ( $this->is_elementor_preview() ) { |
|
2010 | + } elseif ($this->is_elementor_preview()) { |
|
2011 | 2011 | $preview = true; |
2012 | - } elseif ( $this->is_beaver_preview() ) { |
|
2012 | + } elseif ($this->is_beaver_preview()) { |
|
2013 | 2013 | $preview = true; |
2014 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
2014 | + } elseif ($this->is_siteorigin_preview()) { |
|
2015 | 2015 | $preview = true; |
2016 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
2016 | + } elseif ($this->is_cornerstone_preview()) { |
|
2017 | 2017 | $preview = true; |
2018 | 2018 | } |
2019 | 2019 | |
@@ -2028,11 +2028,11 @@ discard block |
||
2028 | 2028 | * |
2029 | 2029 | * @return string |
2030 | 2030 | */ |
2031 | - public function output_title( $args, $instance = array() ) { |
|
2031 | + public function output_title($args, $instance = array()) { |
|
2032 | 2032 | $output = ''; |
2033 | - if ( ! empty( $instance['title'] ) ) { |
|
2033 | + if (!empty($instance['title'])) { |
|
2034 | 2034 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
2035 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
2035 | + $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); |
|
2036 | 2036 | $output = $args['before_title'] . $title . $args['after_title']; |
2037 | 2037 | } |
2038 | 2038 | |
@@ -2044,7 +2044,7 @@ discard block |
||
2044 | 2044 | * |
2045 | 2045 | * @param array $instance The widget options. |
2046 | 2046 | */ |
2047 | - public function form( $instance ) { |
|
2047 | + public function form($instance) { |
|
2048 | 2048 | |
2049 | 2049 | // set widget instance |
2050 | 2050 | $this->instance = $instance; |
@@ -2052,12 +2052,12 @@ discard block |
||
2052 | 2052 | // set it as a SD widget |
2053 | 2053 | echo $this->widget_advanced_toggle(); |
2054 | 2054 | |
2055 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
2055 | + echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>"; |
|
2056 | 2056 | $arguments = $this->get_arguments(); |
2057 | 2057 | |
2058 | - if ( is_array( $arguments ) ) { |
|
2059 | - foreach ( $arguments as $key => $args ) { |
|
2060 | - $this->widget_inputs( $args, $instance ); |
|
2058 | + if (is_array($arguments)) { |
|
2059 | + foreach ($arguments as $key => $args) { |
|
2060 | + $this->widget_inputs($args, $instance); |
|
2061 | 2061 | } |
2062 | 2062 | } |
2063 | 2063 | } |
@@ -2070,7 +2070,7 @@ discard block |
||
2070 | 2070 | public function widget_advanced_toggle() { |
2071 | 2071 | |
2072 | 2072 | $output = ''; |
2073 | - if ( $this->block_show_advanced() ) { |
|
2073 | + if ($this->block_show_advanced()) { |
|
2074 | 2074 | $val = 1; |
2075 | 2075 | } else { |
2076 | 2076 | $val = 0; |
@@ -2090,14 +2090,14 @@ discard block |
||
2090 | 2090 | * |
2091 | 2091 | * @return string $output |
2092 | 2092 | */ |
2093 | - public function convert_element_require( $input ) { |
|
2093 | + public function convert_element_require($input) { |
|
2094 | 2094 | |
2095 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
2095 | + $input = str_replace("'", '"', $input); // we only want double quotes |
|
2096 | 2096 | |
2097 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
2097 | + $output = esc_attr(str_replace(array("[%", "%]"), array( |
|
2098 | 2098 | "jQuery(form).find('[data-argument=\"", |
2099 | 2099 | "\"]').find('input,select').val()" |
2100 | - ), $input ) ); |
|
2100 | + ), $input)); |
|
2101 | 2101 | |
2102 | 2102 | return $output; |
2103 | 2103 | } |
@@ -2108,54 +2108,54 @@ discard block |
||
2108 | 2108 | * @param $args |
2109 | 2109 | * @param $instance |
2110 | 2110 | */ |
2111 | - public function widget_inputs( $args, $instance ) { |
|
2111 | + public function widget_inputs($args, $instance) { |
|
2112 | 2112 | |
2113 | 2113 | $class = ""; |
2114 | 2114 | $element_require = ""; |
2115 | 2115 | $custom_attributes = ""; |
2116 | 2116 | |
2117 | 2117 | // get value |
2118 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
2119 | - $value = $instance[ $args['name'] ]; |
|
2120 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
2121 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
2118 | + if (isset($instance[$args['name']])) { |
|
2119 | + $value = $instance[$args['name']]; |
|
2120 | + } elseif (!isset($instance[$args['name']]) && !empty($args['default'])) { |
|
2121 | + $value = is_array($args['default']) ? array_map("esc_html", $args['default']) : esc_html($args['default']); |
|
2122 | 2122 | } else { |
2123 | 2123 | $value = ''; |
2124 | 2124 | } |
2125 | 2125 | |
2126 | 2126 | // get placeholder |
2127 | - if ( ! empty( $args['placeholder'] ) ) { |
|
2128 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
2127 | + if (!empty($args['placeholder'])) { |
|
2128 | + $placeholder = "placeholder='" . esc_html($args['placeholder']) . "'"; |
|
2129 | 2129 | } else { |
2130 | 2130 | $placeholder = ''; |
2131 | 2131 | } |
2132 | 2132 | |
2133 | 2133 | // get if advanced |
2134 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
2134 | + if (isset($args['advanced']) && $args['advanced']) { |
|
2135 | 2135 | $class .= " sd-advanced-setting "; |
2136 | 2136 | } |
2137 | 2137 | |
2138 | 2138 | // element_require |
2139 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
2139 | + if (isset($args['element_require']) && $args['element_require']) { |
|
2140 | 2140 | $element_require = $args['element_require']; |
2141 | 2141 | } |
2142 | 2142 | |
2143 | 2143 | // custom_attributes |
2144 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
2145 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
2144 | + if (isset($args['custom_attributes']) && $args['custom_attributes']) { |
|
2145 | + $custom_attributes = $this->array_to_attributes($args['custom_attributes'], true); |
|
2146 | 2146 | } |
2147 | 2147 | |
2148 | 2148 | // before wrapper |
2149 | 2149 | ?> |
2150 | - <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
|
2151 | - data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
|
2152 | - data-element_require='<?php if ( $element_require ) { |
|
2153 | - echo $this->convert_element_require( $element_require ); |
|
2150 | + <p class="sd-argument <?php echo esc_attr($class); ?>" |
|
2151 | + data-argument='<?php echo esc_attr($args['name']); ?>' |
|
2152 | + data-element_require='<?php if ($element_require) { |
|
2153 | + echo $this->convert_element_require($element_require); |
|
2154 | 2154 | } ?>' |
2155 | 2155 | > |
2156 | 2156 | <?php |
2157 | 2157 | |
2158 | - switch ( $args['type'] ) { |
|
2158 | + switch ($args['type']) { |
|
2159 | 2159 | //array('text','password','number','email','tel','url','color') |
2160 | 2160 | case "text": |
2161 | 2161 | case "password": |
@@ -2166,46 +2166,46 @@ discard block |
||
2166 | 2166 | case "color": |
2167 | 2167 | ?> |
2168 | 2168 | <label |
2169 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
2169 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
2170 | 2170 | <input <?php echo $placeholder; ?> class="widefat" |
2171 | 2171 | <?php echo $custom_attributes; ?> |
2172 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
2173 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" |
|
2174 | - type="<?php echo esc_attr( $args['type'] ); ?>" |
|
2175 | - value="<?php echo esc_attr( $value ); ?>"> |
|
2172 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
2173 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" |
|
2174 | + type="<?php echo esc_attr($args['type']); ?>" |
|
2175 | + value="<?php echo esc_attr($value); ?>"> |
|
2176 | 2176 | <?php |
2177 | 2177 | |
2178 | 2178 | break; |
2179 | 2179 | case "select": |
2180 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
2181 | - if ( $multiple ) { |
|
2182 | - if ( empty( $value ) ) { |
|
2180 | + $multiple = isset($args['multiple']) && $args['multiple'] ? true : false; |
|
2181 | + if ($multiple) { |
|
2182 | + if (empty($value)) { |
|
2183 | 2183 | $value = array(); |
2184 | 2184 | } |
2185 | 2185 | } |
2186 | 2186 | ?> |
2187 | 2187 | <label |
2188 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
2188 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
2189 | 2189 | <select <?php echo $placeholder; ?> class="widefat" |
2190 | 2190 | <?php echo $custom_attributes; ?> |
2191 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
2192 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
|
2193 | - if ( $multiple ) { |
|
2191 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
2192 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); |
|
2193 | + if ($multiple) { |
|
2194 | 2194 | echo "[]"; |
2195 | 2195 | } ?>" |
2196 | - <?php if ( $multiple ) { |
|
2196 | + <?php if ($multiple) { |
|
2197 | 2197 | echo "multiple"; |
2198 | 2198 | } //@todo not implemented yet due to gutenberg not supporting it |
2199 | 2199 | ?> |
2200 | 2200 | > |
2201 | 2201 | <?php |
2202 | 2202 | |
2203 | - if ( ! empty( $args['options'] ) ) { |
|
2204 | - foreach ( $args['options'] as $val => $label ) { |
|
2205 | - if ( $multiple ) { |
|
2206 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
2203 | + if (!empty($args['options'])) { |
|
2204 | + foreach ($args['options'] as $val => $label) { |
|
2205 | + if ($multiple) { |
|
2206 | + $selected = in_array($val, $value) ? 'selected="selected"' : ''; |
|
2207 | 2207 | } else { |
2208 | - $selected = selected( $value, $val, false ); |
|
2208 | + $selected = selected($value, $val, false); |
|
2209 | 2209 | } |
2210 | 2210 | echo "<option value='$val' " . $selected . ">$label</option>"; |
2211 | 2211 | } |
@@ -2217,20 +2217,20 @@ discard block |
||
2217 | 2217 | case "checkbox": |
2218 | 2218 | ?> |
2219 | 2219 | <input <?php echo $placeholder; ?> |
2220 | - <?php checked( 1, $value, true ) ?> |
|
2220 | + <?php checked(1, $value, true) ?> |
|
2221 | 2221 | <?php echo $custom_attributes; ?> |
2222 | - class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
2223 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox" |
|
2222 | + class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
2223 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox" |
|
2224 | 2224 | value="1"> |
2225 | 2225 | <label |
2226 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
2226 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
2227 | 2227 | <?php |
2228 | 2228 | break; |
2229 | 2229 | case "hidden": |
2230 | 2230 | ?> |
2231 | - <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
2232 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
|
2233 | - value="<?php echo esc_attr( $value ); ?>"> |
|
2231 | + <input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
2232 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden" |
|
2233 | + value="<?php echo esc_attr($value); ?>"> |
|
2234 | 2234 | <?php |
2235 | 2235 | break; |
2236 | 2236 | default: |
@@ -2252,14 +2252,14 @@ discard block |
||
2252 | 2252 | * @return string |
2253 | 2253 | * @todo, need to make its own tooltip script |
2254 | 2254 | */ |
2255 | - public function widget_field_desc( $args ) { |
|
2255 | + public function widget_field_desc($args) { |
|
2256 | 2256 | |
2257 | 2257 | $description = ''; |
2258 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
2259 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
2260 | - $description = $this->desc_tip( $args['desc'] ); |
|
2258 | + if (isset($args['desc']) && $args['desc']) { |
|
2259 | + if (isset($args['desc_tip']) && $args['desc_tip']) { |
|
2260 | + $description = $this->desc_tip($args['desc']); |
|
2261 | 2261 | } else { |
2262 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
2262 | + $description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>'; |
|
2263 | 2263 | } |
2264 | 2264 | } |
2265 | 2265 | |
@@ -2274,11 +2274,11 @@ discard block |
||
2274 | 2274 | * |
2275 | 2275 | * @return string |
2276 | 2276 | */ |
2277 | - function desc_tip( $tip, $allow_html = false ) { |
|
2278 | - if ( $allow_html ) { |
|
2279 | - $tip = $this->sanitize_tooltip( $tip ); |
|
2277 | + function desc_tip($tip, $allow_html = false) { |
|
2278 | + if ($allow_html) { |
|
2279 | + $tip = $this->sanitize_tooltip($tip); |
|
2280 | 2280 | } else { |
2281 | - $tip = esc_attr( $tip ); |
|
2281 | + $tip = esc_attr($tip); |
|
2282 | 2282 | } |
2283 | 2283 | |
2284 | 2284 | return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -2291,8 +2291,8 @@ discard block |
||
2291 | 2291 | * |
2292 | 2292 | * @return string |
2293 | 2293 | */ |
2294 | - public function sanitize_tooltip( $var ) { |
|
2295 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
2294 | + public function sanitize_tooltip($var) { |
|
2295 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
2296 | 2296 | 'br' => array(), |
2297 | 2297 | 'em' => array(), |
2298 | 2298 | 'strong' => array(), |
@@ -2302,7 +2302,7 @@ discard block |
||
2302 | 2302 | 'li' => array(), |
2303 | 2303 | 'ol' => array(), |
2304 | 2304 | 'p' => array(), |
2305 | - ) ) ); |
|
2305 | + ))); |
|
2306 | 2306 | } |
2307 | 2307 | |
2308 | 2308 | /** |
@@ -2314,23 +2314,23 @@ discard block |
||
2314 | 2314 | * @return array |
2315 | 2315 | * @todo we should add some sanitation here. |
2316 | 2316 | */ |
2317 | - public function update( $new_instance, $old_instance ) { |
|
2317 | + public function update($new_instance, $old_instance) { |
|
2318 | 2318 | |
2319 | 2319 | //save the widget |
2320 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
2320 | + $instance = array_merge((array)$old_instance, (array)$new_instance); |
|
2321 | 2321 | |
2322 | 2322 | // set widget instance |
2323 | 2323 | $this->instance = $instance; |
2324 | 2324 | |
2325 | - if ( empty( $this->arguments ) ) { |
|
2325 | + if (empty($this->arguments)) { |
|
2326 | 2326 | $this->get_arguments(); |
2327 | 2327 | } |
2328 | 2328 | |
2329 | 2329 | // check for checkboxes |
2330 | - if ( ! empty( $this->arguments ) ) { |
|
2331 | - foreach ( $this->arguments as $argument ) { |
|
2332 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
2333 | - $instance[ $argument['name'] ] = '0'; |
|
2330 | + if (!empty($this->arguments)) { |
|
2331 | + foreach ($this->arguments as $argument) { |
|
2332 | + if (isset($argument['type']) && $argument['type'] == 'checkbox' && !isset($new_instance[$argument['name']])) { |
|
2333 | + $instance[$argument['name']] = '0'; |
|
2334 | 2334 | } |
2335 | 2335 | } |
2336 | 2336 | } |
@@ -2348,7 +2348,7 @@ discard block |
||
2348 | 2348 | */ |
2349 | 2349 | public function is_block_content_call() { |
2350 | 2350 | $result = false; |
2351 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
2351 | + if (wp_doing_ajax() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'super_duper_output_shortcode') { |
|
2352 | 2352 | $result = true; |
2353 | 2353 | } |
2354 | 2354 |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | <?php |
537 | 537 | if(! empty( $insert_shortcode_function )){ |
538 | 538 | echo $insert_shortcode_function; |
539 | - }else{ |
|
539 | + } else{ |
|
540 | 540 | |
541 | 541 | /** |
542 | 542 | * Function for super duper insert shortcode. |
@@ -1275,8 +1275,7 @@ discard block |
||
1275 | 1275 | $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
1276 | 1276 | if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
1277 | 1277 | // don't set default for an empty checkbox |
1278 | - } |
|
1279 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1278 | + } elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1280 | 1279 | $argument_values[ $key ] = $args['default']; |
1281 | 1280 | } |
1282 | 1281 | } |
@@ -1649,7 +1648,7 @@ discard block |
||
1649 | 1648 | // If the user sets block-output array then build it |
1650 | 1649 | if ( ! empty( $this->options['block-output'] ) ) { |
1651 | 1650 | $this->block_element( $this->options['block-output'] ); |
1652 | - }else{ |
|
1651 | + } else{ |
|
1653 | 1652 | // if no block-output is set then we try and get the shortcode html output via ajax. |
1654 | 1653 | ?> |
1655 | 1654 | el('div', { |