@@ -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 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
9 | - exit; |
|
9 | + exit; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -15,71 +15,71 @@ discard block |
||
15 | 15 | class WPInv_Admin_Addons extends Ayecode_Addons { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Get the extensions page tabs. |
|
20 | - * |
|
21 | - * @return array of tabs. |
|
22 | - */ |
|
23 | - public function get_tabs(){ |
|
24 | - $tabs = array( |
|
25 | - 'addons' => __("Addons", "invoicing"), |
|
18 | + /** |
|
19 | + * Get the extensions page tabs. |
|
20 | + * |
|
21 | + * @return array of tabs. |
|
22 | + */ |
|
23 | + public function get_tabs(){ |
|
24 | + $tabs = array( |
|
25 | + 'addons' => __("Addons", "invoicing"), |
|
26 | 26 | 'gateways' => __("Payment Gateways", "invoicing"), |
27 | 27 | 'recommended_plugins' => __("Recommended plugins", "invoicing"), |
28 | 28 | 'membership' => __("Membership", "invoicing"), |
29 | - ); |
|
30 | - |
|
31 | - return $tabs; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Get section content for the addons screen. |
|
36 | - * |
|
37 | - * @param string $section_id |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function get_section_data( $section_id ) { |
|
42 | - $section = self::get_tab( $section_id ); |
|
43 | - $api_url = "https://wpinvoicing.com/edd-api/v2/products/"; |
|
44 | - $section_data = new stdClass(); |
|
45 | - |
|
46 | - if($section_id=='recommended_plugins'){ |
|
47 | - $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
|
48 | - } |
|
49 | - elseif ( ! empty( $section ) ) { |
|
50 | - if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
51 | - //if ( 1==1) { |
|
52 | - |
|
53 | - $query_args = array( 'category' => $section_id, 'number' => 100); |
|
54 | - $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id); |
|
55 | - |
|
56 | - $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout' => 15, ) ); |
|
57 | - |
|
58 | - if ( ! is_wp_error( $raw_section ) ) { |
|
59 | - $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
60 | - |
|
61 | - if ( ! empty( $section_data->products ) ) { |
|
62 | - set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
63 | - } |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - $products = isset($section_data->products) ? $section_data->products : ''; |
|
69 | - |
|
70 | - return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Outputs a button. |
|
75 | - *ccc |
|
76 | - * @param string $url |
|
77 | - * @param string $text |
|
78 | - * @param string $theme |
|
79 | - * @param string $plugin |
|
80 | - */ |
|
81 | - public function output_button( $addon ) { |
|
82 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
29 | + ); |
|
30 | + |
|
31 | + return $tabs; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Get section content for the addons screen. |
|
36 | + * |
|
37 | + * @param string $section_id |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function get_section_data( $section_id ) { |
|
42 | + $section = self::get_tab( $section_id ); |
|
43 | + $api_url = "https://wpinvoicing.com/edd-api/v2/products/"; |
|
44 | + $section_data = new stdClass(); |
|
45 | + |
|
46 | + if($section_id=='recommended_plugins'){ |
|
47 | + $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
|
48 | + } |
|
49 | + elseif ( ! empty( $section ) ) { |
|
50 | + if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
51 | + //if ( 1==1) { |
|
52 | + |
|
53 | + $query_args = array( 'category' => $section_id, 'number' => 100); |
|
54 | + $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id); |
|
55 | + |
|
56 | + $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout' => 15, ) ); |
|
57 | + |
|
58 | + if ( ! is_wp_error( $raw_section ) ) { |
|
59 | + $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
60 | + |
|
61 | + if ( ! empty( $section_data->products ) ) { |
|
62 | + set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
63 | + } |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + $products = isset($section_data->products) ? $section_data->products : ''; |
|
69 | + |
|
70 | + return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Outputs a button. |
|
75 | + *ccc |
|
76 | + * @param string $url |
|
77 | + * @param string $text |
|
78 | + * @param string $theme |
|
79 | + * @param string $plugin |
|
80 | + */ |
|
81 | + public function output_button( $addon ) { |
|
82 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
83 | 83 | // $button_text = __('Free','invoicing'); |
84 | 84 | // $licensing = false; |
85 | 85 | // $installed = false; |
@@ -91,123 +91,123 @@ discard block |
||
91 | 91 | // $install_status = 'get'; |
92 | 92 | // $onclick = ''; |
93 | 93 | |
94 | - $wp_org_themes = array('supreme-directory','directory-starter'); |
|
95 | - |
|
96 | - $button_args = array( |
|
97 | - 'type' => $current_tab, |
|
98 | - 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
|
99 | - 'title' => isset($addon->info->title) ? $addon->info->title : '', |
|
100 | - 'button_text' => __('Free','invoicing'), |
|
101 | - 'price_text' => __('Free','invoicing'), |
|
102 | - 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
|
103 | - 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
|
104 | - 'class' => 'button-primary', |
|
105 | - 'install_status' => 'get', |
|
106 | - 'installed' => false, |
|
107 | - 'price' => '', |
|
108 | - 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
|
109 | - 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
|
110 | - 'onclick' => '', |
|
111 | - 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
|
112 | - 'active' => false, |
|
113 | - 'file' => '', |
|
114 | - 'update_url' => '', |
|
115 | - ); |
|
116 | - |
|
117 | - if( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
118 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
119 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
120 | - $status = self::install_plugin_install_status($addon); |
|
121 | - $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
122 | - if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
123 | - $button_args['update_url'] = "https://wpinvoicing.com"; |
|
124 | - }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
126 | - $button_args['installed'] = self::is_theme_installed($addon); |
|
127 | - if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
128 | - $button_args['update_url'] = "https://wpinvoicing.com"; |
|
129 | - } |
|
130 | - }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
|
131 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
132 | - $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
133 | - $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
|
134 | - $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
135 | - } |
|
136 | - |
|
137 | - // set price |
|
138 | - if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
139 | - if(is_object($addon->pricing)){ |
|
140 | - $prices = (Array)$addon->pricing; |
|
141 | - $button_args['price'] = reset($prices); |
|
142 | - }elseif(isset($addon->pricing)){ |
|
143 | - $button_args['price'] = $addon->pricing; |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - // set price text |
|
148 | - if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
149 | - $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - // set if installed |
|
154 | - if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
155 | - $button_args['installed'] = true; |
|
156 | - } |
|
94 | + $wp_org_themes = array('supreme-directory','directory-starter'); |
|
95 | + |
|
96 | + $button_args = array( |
|
97 | + 'type' => $current_tab, |
|
98 | + 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
|
99 | + 'title' => isset($addon->info->title) ? $addon->info->title : '', |
|
100 | + 'button_text' => __('Free','invoicing'), |
|
101 | + 'price_text' => __('Free','invoicing'), |
|
102 | + 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
|
103 | + 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
|
104 | + 'class' => 'button-primary', |
|
105 | + 'install_status' => 'get', |
|
106 | + 'installed' => false, |
|
107 | + 'price' => '', |
|
108 | + 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
|
109 | + 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
|
110 | + 'onclick' => '', |
|
111 | + 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
|
112 | + 'active' => false, |
|
113 | + 'file' => '', |
|
114 | + 'update_url' => '', |
|
115 | + ); |
|
116 | + |
|
117 | + if( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
118 | + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
119 | + if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
120 | + $status = self::install_plugin_install_status($addon); |
|
121 | + $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
122 | + if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
123 | + $button_args['update_url'] = "https://wpinvoicing.com"; |
|
124 | + }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | + if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
126 | + $button_args['installed'] = self::is_theme_installed($addon); |
|
127 | + if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
128 | + $button_args['update_url'] = "https://wpinvoicing.com"; |
|
129 | + } |
|
130 | + }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
|
131 | + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
132 | + $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
133 | + $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
|
134 | + $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
135 | + } |
|
136 | + |
|
137 | + // set price |
|
138 | + if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
139 | + if(is_object($addon->pricing)){ |
|
140 | + $prices = (Array)$addon->pricing; |
|
141 | + $button_args['price'] = reset($prices); |
|
142 | + }elseif(isset($addon->pricing)){ |
|
143 | + $button_args['price'] = $addon->pricing; |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + // set price text |
|
148 | + if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
149 | + $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + // set if installed |
|
154 | + if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
155 | + $button_args['installed'] = true; |
|
156 | + } |
|
157 | 157 | |
158 | 158 | // print_r($button_args); |
159 | - // set if active |
|
160 | - if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
161 | - if($button_args['type'] != 'themes'){ |
|
162 | - $button_args['active'] = is_plugin_active($button_args['file']); |
|
163 | - }else{ |
|
164 | - $button_args['active'] = self::is_theme_active($addon); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - // set button text and class |
|
169 | - if($button_args['active']){ |
|
170 | - $button_args['button_text'] = __('Active','invoicing'); |
|
171 | - $button_args['class'] = ' button-secondary disabled '; |
|
172 | - }elseif($button_args['installed']){ |
|
173 | - $button_args['button_text'] = __('Activate','invoicing'); |
|
174 | - |
|
175 | - if($button_args['type'] != 'themes'){ |
|
176 | - if ( current_user_can( 'manage_options' ) ) { |
|
177 | - $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | - }else{ |
|
179 | - $button_args['url'] = '#'; |
|
180 | - } |
|
181 | - }else{ |
|
182 | - if ( current_user_can( 'switch_themes' ) ) { |
|
183 | - $button_args['url'] = self::get_theme_activation_url($addon); |
|
184 | - }else{ |
|
185 | - $button_args['url'] = '#'; |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - }else{ |
|
190 | - if($button_args['type'] == 'recommended_plugins'){ |
|
191 | - $button_args['button_text'] = __('Install','invoicing'); |
|
192 | - }else{ |
|
193 | - $button_args['button_text'] = __('Get it','invoicing'); |
|
194 | - |
|
195 | - /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
159 | + // set if active |
|
160 | + if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
161 | + if($button_args['type'] != 'themes'){ |
|
162 | + $button_args['active'] = is_plugin_active($button_args['file']); |
|
163 | + }else{ |
|
164 | + $button_args['active'] = self::is_theme_active($addon); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + // set button text and class |
|
169 | + if($button_args['active']){ |
|
170 | + $button_args['button_text'] = __('Active','invoicing'); |
|
171 | + $button_args['class'] = ' button-secondary disabled '; |
|
172 | + }elseif($button_args['installed']){ |
|
173 | + $button_args['button_text'] = __('Activate','invoicing'); |
|
174 | + |
|
175 | + if($button_args['type'] != 'themes'){ |
|
176 | + if ( current_user_can( 'manage_options' ) ) { |
|
177 | + $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | + }else{ |
|
179 | + $button_args['url'] = '#'; |
|
180 | + } |
|
181 | + }else{ |
|
182 | + if ( current_user_can( 'switch_themes' ) ) { |
|
183 | + $button_args['url'] = self::get_theme_activation_url($addon); |
|
184 | + }else{ |
|
185 | + $button_args['url'] = '#'; |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + }else{ |
|
190 | + if($button_args['type'] == 'recommended_plugins'){ |
|
191 | + $button_args['button_text'] = __('Install','invoicing'); |
|
192 | + }else{ |
|
193 | + $button_args['button_text'] = __('Get it','invoicing'); |
|
194 | + |
|
195 | + /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
196 | 196 | $button_args['button_text'] = __('Install','invoicing'); |
197 | 197 | $button_args['url'] = self::get_theme_install_url($button_args['slug']); |
198 | 198 | $button_args['onclick'] = 'gd_set_button_installing(this);'; |
199 | 199 | }*/ |
200 | 200 | |
201 | - } |
|
202 | - } |
|
201 | + } |
|
202 | + } |
|
203 | 203 | |
204 | 204 | |
205 | - // filter the button arguments |
|
206 | - $button_args = apply_filters('edd_api_button_args',$button_args); |
|
205 | + // filter the button arguments |
|
206 | + $button_args = apply_filters('edd_api_button_args',$button_args); |
|
207 | 207 | |
208 | - // set price text |
|
209 | - if(isset($button_args['price_text'])){ |
|
210 | - ?> |
|
208 | + // set price text |
|
209 | + if(isset($button_args['price_text'])){ |
|
210 | + ?> |
|
211 | 211 | <a |
212 | 212 | target="_blank" |
213 | 213 | class="addons-price-text" |
@@ -215,15 +215,15 @@ discard block |
||
215 | 215 | <?php echo esc_html( $button_args['price_text'] ); ?> |
216 | 216 | </a> |
217 | 217 | <?php |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | 220 | |
221 | - $target = ''; |
|
222 | - if ( ! empty( $button_args['url'] ) ) { |
|
223 | - $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
|
224 | - } |
|
221 | + $target = ''; |
|
222 | + if ( ! empty( $button_args['url'] ) ) { |
|
223 | + $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
|
224 | + } |
|
225 | 225 | |
226 | - ?> |
|
226 | + ?> |
|
227 | 227 | <a |
228 | 228 | data-licence="<?php echo esc_attr($button_args['license']);?>" |
229 | 229 | data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>" |
@@ -246,28 +246,28 @@ discard block |
||
246 | 246 | <?php |
247 | 247 | |
248 | 248 | |
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Handles output of the addons page in admin. |
|
254 | - */ |
|
255 | - public function output() { |
|
256 | - $tabs = self::get_tabs(); |
|
257 | - $sections = self::get_sections(); |
|
258 | - $theme = wp_get_theme(); |
|
259 | - $section_keys = array_keys( $sections ); |
|
260 | - $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
261 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
262 | - include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * A list of recommended wp.org plugins. |
|
267 | - * @return array |
|
268 | - */ |
|
269 | - public function get_recommend_wp_plugins(){ |
|
270 | - $plugins = array( |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Handles output of the addons page in admin. |
|
254 | + */ |
|
255 | + public function output() { |
|
256 | + $tabs = self::get_tabs(); |
|
257 | + $sections = self::get_sections(); |
|
258 | + $theme = wp_get_theme(); |
|
259 | + $section_keys = array_keys( $sections ); |
|
260 | + $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
261 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
262 | + include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * A list of recommended wp.org plugins. |
|
267 | + * @return array |
|
268 | + */ |
|
269 | + public function get_recommend_wp_plugins(){ |
|
270 | + $plugins = array( |
|
271 | 271 | 'invoicing-quotes' => array( |
272 | 272 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
273 | 273 | 'slug' => 'invoicing-quotes', |
@@ -287,8 +287,8 @@ discard block |
||
287 | 287 | 'name' => 'UsersWP', |
288 | 288 | 'desc' => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'), |
289 | 289 | ), |
290 | - ); |
|
290 | + ); |
|
291 | 291 | |
292 | - return $plugins; |
|
293 | - } |
|
292 | + return $plugins; |
|
293 | + } |
|
294 | 294 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,294 +21,294 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | - * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | - * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | - * @ver 1.0.11 |
|
32 | - * @todo decide how to implement textdomain |
|
33 | - */ |
|
34 | - class WP_Font_Awesome_Settings { |
|
35 | - |
|
36 | - /** |
|
37 | - * Class version version. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $version = '1.0.11'; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class textdomain. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - public $textdomain = 'font-awesome-settings'; |
|
49 | - |
|
50 | - /** |
|
51 | - * Latest version of Font Awesome at time of publish published. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $latest = "5.8.2"; |
|
56 | - |
|
57 | - /** |
|
58 | - * The title. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - public $name = 'Font Awesome'; |
|
63 | - |
|
64 | - /** |
|
65 | - * Holds the settings values. |
|
66 | - * |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - private $settings; |
|
70 | - |
|
71 | - /** |
|
72 | - * WP_Font_Awesome_Settings instance. |
|
73 | - * |
|
74 | - * @access private |
|
75 | - * @since 1.0.0 |
|
76 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
77 | - */ |
|
78 | - private static $instance = null; |
|
79 | - |
|
80 | - /** |
|
81 | - * Main WP_Font_Awesome_Settings Instance. |
|
82 | - * |
|
83 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
84 | - * |
|
85 | - * @since 1.0.0 |
|
86 | - * @static |
|
87 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
88 | - */ |
|
89 | - public static function instance() { |
|
90 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
91 | - self::$instance = new WP_Font_Awesome_Settings; |
|
92 | - |
|
93 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
94 | - |
|
95 | - if ( is_admin() ) { |
|
96 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
97 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
98 | - } |
|
99 | - |
|
100 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
101 | - } |
|
102 | - |
|
103 | - return self::$instance; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Initiate the settings and add the required action hooks. |
|
108 | - * |
|
109 | - * @since 1.0.8 Settings name wrong - FIXED |
|
110 | - */ |
|
111 | - public function init() { |
|
112 | - $this->settings = $this->get_settings(); |
|
113 | - |
|
114 | - if ( $this->settings['type'] == 'CSS' ) { |
|
115 | - |
|
116 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
117 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
118 | - } |
|
119 | - |
|
120 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
121 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
122 | - } |
|
123 | - |
|
124 | - } else { |
|
125 | - |
|
126 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
128 | - } |
|
129 | - |
|
130 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
131 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - // remove font awesome if set to do so |
|
136 | - if ( $this->settings['dequeue'] == '1' ) { |
|
137 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
138 | - } |
|
139 | - |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Adds the Font Awesome styles. |
|
144 | - */ |
|
145 | - public function enqueue_style() { |
|
146 | - // build url |
|
147 | - $url = $this->get_url(); |
|
148 | - |
|
149 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
150 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
151 | - wp_enqueue_style( 'font-awesome' ); |
|
152 | - |
|
153 | - if ( $this->settings['shims'] ) { |
|
154 | - $url = $this->get_url( true ); |
|
155 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
156 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
157 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Adds the Font Awesome JS. |
|
163 | - */ |
|
164 | - public function enqueue_scripts() { |
|
165 | - // build url |
|
166 | - $url = $this->get_url(); |
|
167 | - |
|
168 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
169 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
170 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
171 | - wp_enqueue_script( 'font-awesome' ); |
|
172 | - |
|
173 | - if ( $this->settings['shims'] ) { |
|
174 | - $url = $this->get_url( true ); |
|
175 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
176 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
177 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Get the url of the Font Awesome files. |
|
183 | - * |
|
184 | - * @param bool $shims If this is a shim file or not. |
|
185 | - * |
|
186 | - * @return string The url to the file. |
|
187 | - */ |
|
188 | - public function get_url( $shims = false ) { |
|
189 | - $script = $shims ? 'v4-shims' : 'all'; |
|
190 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
191 | - $type = $this->settings['type']; |
|
192 | - $version = $this->settings['version']; |
|
193 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
194 | - $url = ''; |
|
195 | - |
|
196 | - if ( $type == 'KIT' && $kit_url ) { |
|
197 | - if ( $shims ) { |
|
198 | - // if its a kit then we don't add shims here |
|
199 | - return ''; |
|
200 | - } |
|
201 | - $url .= $kit_url; // CDN |
|
202 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
203 | - } else { |
|
204 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
205 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
206 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
207 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
208 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
209 | - } |
|
210 | - |
|
211 | - return $url; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
216 | - * |
|
217 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
218 | - * |
|
219 | - * @param $url |
|
220 | - * @param $original_url |
|
221 | - * @param $_context |
|
222 | - * |
|
223 | - * @return string The filtered url. |
|
224 | - */ |
|
225 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
226 | - |
|
227 | - if ( $_context == 'display' |
|
228 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
229 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
230 | - ) {// it's a font-awesome-url (probably) |
|
231 | - |
|
232 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
233 | - if ( $this->settings['type'] == 'JS' ) { |
|
234 | - if ( $this->settings['js-pseudo'] ) { |
|
235 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
236 | - } else { |
|
237 | - $url .= "' defer='defer"; |
|
238 | - } |
|
239 | - } |
|
240 | - } else { |
|
241 | - $url = ''; // removing the url removes the file |
|
242 | - } |
|
243 | - |
|
244 | - } |
|
245 | - |
|
246 | - return $url; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Register the database settings with WordPress. |
|
251 | - */ |
|
252 | - public function register_settings() { |
|
253 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Add the WordPress settings menu item. |
|
258 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
259 | - */ |
|
260 | - public function menu_item() { |
|
261 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
262 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
263 | - $this, |
|
264 | - 'settings_page' |
|
265 | - ) ); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Get the current Font Awesome output settings. |
|
270 | - * |
|
271 | - * @return array The array of settings. |
|
272 | - */ |
|
273 | - public function get_settings() { |
|
274 | - |
|
275 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
276 | - |
|
277 | - $defaults = array( |
|
278 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
279 | - 'version' => '', // latest |
|
280 | - 'enqueue' => '', // front and backend |
|
281 | - 'shims' => '1', // default on for now, @todo maybe change to off in 2020 |
|
282 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
283 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
284 | - 'pro' => '0', // if pro CDN url should be used |
|
285 | - 'kit-url' => '', // the kit url |
|
286 | - ); |
|
287 | - |
|
288 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
289 | - |
|
290 | - /** |
|
291 | - * Filter the Font Awesome settings. |
|
292 | - * |
|
293 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
294 | - */ |
|
295 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * The settings page html output. |
|
301 | - */ |
|
302 | - public function settings_page() { |
|
303 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
304 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
305 | - } |
|
306 | - |
|
307 | - // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
|
308 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
309 | - $this->get_latest_version( $force_api = true ); |
|
310 | - } |
|
311 | - ?> |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | + * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | + * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | + * @ver 1.0.11 |
|
32 | + * @todo decide how to implement textdomain |
|
33 | + */ |
|
34 | + class WP_Font_Awesome_Settings { |
|
35 | + |
|
36 | + /** |
|
37 | + * Class version version. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $version = '1.0.11'; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class textdomain. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + public $textdomain = 'font-awesome-settings'; |
|
49 | + |
|
50 | + /** |
|
51 | + * Latest version of Font Awesome at time of publish published. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $latest = "5.8.2"; |
|
56 | + |
|
57 | + /** |
|
58 | + * The title. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + public $name = 'Font Awesome'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Holds the settings values. |
|
66 | + * |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + private $settings; |
|
70 | + |
|
71 | + /** |
|
72 | + * WP_Font_Awesome_Settings instance. |
|
73 | + * |
|
74 | + * @access private |
|
75 | + * @since 1.0.0 |
|
76 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
77 | + */ |
|
78 | + private static $instance = null; |
|
79 | + |
|
80 | + /** |
|
81 | + * Main WP_Font_Awesome_Settings Instance. |
|
82 | + * |
|
83 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
84 | + * |
|
85 | + * @since 1.0.0 |
|
86 | + * @static |
|
87 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
88 | + */ |
|
89 | + public static function instance() { |
|
90 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
91 | + self::$instance = new WP_Font_Awesome_Settings; |
|
92 | + |
|
93 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
94 | + |
|
95 | + if ( is_admin() ) { |
|
96 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
97 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
98 | + } |
|
99 | + |
|
100 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
101 | + } |
|
102 | + |
|
103 | + return self::$instance; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Initiate the settings and add the required action hooks. |
|
108 | + * |
|
109 | + * @since 1.0.8 Settings name wrong - FIXED |
|
110 | + */ |
|
111 | + public function init() { |
|
112 | + $this->settings = $this->get_settings(); |
|
113 | + |
|
114 | + if ( $this->settings['type'] == 'CSS' ) { |
|
115 | + |
|
116 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
117 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
118 | + } |
|
119 | + |
|
120 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
121 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
122 | + } |
|
123 | + |
|
124 | + } else { |
|
125 | + |
|
126 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
128 | + } |
|
129 | + |
|
130 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
131 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + // remove font awesome if set to do so |
|
136 | + if ( $this->settings['dequeue'] == '1' ) { |
|
137 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
138 | + } |
|
139 | + |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Adds the Font Awesome styles. |
|
144 | + */ |
|
145 | + public function enqueue_style() { |
|
146 | + // build url |
|
147 | + $url = $this->get_url(); |
|
148 | + |
|
149 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
150 | + wp_register_style( 'font-awesome', $url, array(), null ); |
|
151 | + wp_enqueue_style( 'font-awesome' ); |
|
152 | + |
|
153 | + if ( $this->settings['shims'] ) { |
|
154 | + $url = $this->get_url( true ); |
|
155 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
156 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
157 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Adds the Font Awesome JS. |
|
163 | + */ |
|
164 | + public function enqueue_scripts() { |
|
165 | + // build url |
|
166 | + $url = $this->get_url(); |
|
167 | + |
|
168 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
169 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
170 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
171 | + wp_enqueue_script( 'font-awesome' ); |
|
172 | + |
|
173 | + if ( $this->settings['shims'] ) { |
|
174 | + $url = $this->get_url( true ); |
|
175 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
176 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
177 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Get the url of the Font Awesome files. |
|
183 | + * |
|
184 | + * @param bool $shims If this is a shim file or not. |
|
185 | + * |
|
186 | + * @return string The url to the file. |
|
187 | + */ |
|
188 | + public function get_url( $shims = false ) { |
|
189 | + $script = $shims ? 'v4-shims' : 'all'; |
|
190 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
191 | + $type = $this->settings['type']; |
|
192 | + $version = $this->settings['version']; |
|
193 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
194 | + $url = ''; |
|
195 | + |
|
196 | + if ( $type == 'KIT' && $kit_url ) { |
|
197 | + if ( $shims ) { |
|
198 | + // if its a kit then we don't add shims here |
|
199 | + return ''; |
|
200 | + } |
|
201 | + $url .= $kit_url; // CDN |
|
202 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
203 | + } else { |
|
204 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
205 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
206 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
207 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
208 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
209 | + } |
|
210 | + |
|
211 | + return $url; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
216 | + * |
|
217 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
218 | + * |
|
219 | + * @param $url |
|
220 | + * @param $original_url |
|
221 | + * @param $_context |
|
222 | + * |
|
223 | + * @return string The filtered url. |
|
224 | + */ |
|
225 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
226 | + |
|
227 | + if ( $_context == 'display' |
|
228 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
229 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
230 | + ) {// it's a font-awesome-url (probably) |
|
231 | + |
|
232 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
233 | + if ( $this->settings['type'] == 'JS' ) { |
|
234 | + if ( $this->settings['js-pseudo'] ) { |
|
235 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
236 | + } else { |
|
237 | + $url .= "' defer='defer"; |
|
238 | + } |
|
239 | + } |
|
240 | + } else { |
|
241 | + $url = ''; // removing the url removes the file |
|
242 | + } |
|
243 | + |
|
244 | + } |
|
245 | + |
|
246 | + return $url; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Register the database settings with WordPress. |
|
251 | + */ |
|
252 | + public function register_settings() { |
|
253 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Add the WordPress settings menu item. |
|
258 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
259 | + */ |
|
260 | + public function menu_item() { |
|
261 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
262 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
263 | + $this, |
|
264 | + 'settings_page' |
|
265 | + ) ); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Get the current Font Awesome output settings. |
|
270 | + * |
|
271 | + * @return array The array of settings. |
|
272 | + */ |
|
273 | + public function get_settings() { |
|
274 | + |
|
275 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
276 | + |
|
277 | + $defaults = array( |
|
278 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
279 | + 'version' => '', // latest |
|
280 | + 'enqueue' => '', // front and backend |
|
281 | + 'shims' => '1', // default on for now, @todo maybe change to off in 2020 |
|
282 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
283 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
284 | + 'pro' => '0', // if pro CDN url should be used |
|
285 | + 'kit-url' => '', // the kit url |
|
286 | + ); |
|
287 | + |
|
288 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
289 | + |
|
290 | + /** |
|
291 | + * Filter the Font Awesome settings. |
|
292 | + * |
|
293 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
294 | + */ |
|
295 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * The settings page html output. |
|
301 | + */ |
|
302 | + public function settings_page() { |
|
303 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
304 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
305 | + } |
|
306 | + |
|
307 | + // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
|
308 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
309 | + $this->get_latest_version( $force_api = true ); |
|
310 | + } |
|
311 | + ?> |
|
312 | 312 | <style> |
313 | 313 | .wpfas-kit-show { |
314 | 314 | display: none; |
@@ -326,10 +326,10 @@ discard block |
||
326 | 326 | <h1><?php echo $this->name; ?></h1> |
327 | 327 | <form method="post" action="options.php"> |
328 | 328 | <?php |
329 | - settings_fields( 'wp-font-awesome-settings' ); |
|
330 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
331 | - $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
332 | - ?> |
|
329 | + settings_fields( 'wp-font-awesome-settings' ); |
|
330 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
331 | + $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
332 | + ?> |
|
333 | 333 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
334 | 334 | <tr valign="top"> |
335 | 335 | <th scope="row"><label |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
356 | 356 | placeholder="https://kit.fontawesome.com/123abc.js"/> |
357 | 357 | <span><?php |
358 | - echo sprintf( |
|
359 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
360 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
361 | - '</a>' |
|
362 | - ); |
|
363 | - ?></span> |
|
358 | + echo sprintf( |
|
359 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
360 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
361 | + '</a>' |
|
362 | + ); |
|
363 | + ?></span> |
|
364 | 364 | </td> |
365 | 365 | </tr> |
366 | 366 | |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
421 | 421 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
422 | 422 | <span><?php |
423 | - echo sprintf( |
|
424 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
425 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
426 | - '</a>', |
|
427 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
428 | - '</a>' |
|
429 | - ); |
|
430 | - ?></span> |
|
423 | + echo sprintf( |
|
424 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
425 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
426 | + '</a>', |
|
427 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
428 | + '</a>' |
|
429 | + ); |
|
430 | + ?></span> |
|
431 | 431 | </td> |
432 | 432 | </tr> |
433 | 433 | |
@@ -470,88 +470,88 @@ discard block |
||
470 | 470 | |
471 | 471 | </table> |
472 | 472 | <?php |
473 | - submit_button(); |
|
474 | - ?> |
|
473 | + submit_button(); |
|
474 | + ?> |
|
475 | 475 | </form> |
476 | 476 | |
477 | 477 | <div id="wpfas-version"><?php echo $this->version; ?></div> |
478 | 478 | </div> |
479 | 479 | |
480 | 480 | <?php |
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Check a version number is valid and if so return it or else return an empty string. |
|
485 | - * |
|
486 | - * @param $version string The version number to check. |
|
487 | - * |
|
488 | - * @since 1.0.6 |
|
489 | - * |
|
490 | - * @return string Either a valid version number or an empty string. |
|
491 | - */ |
|
492 | - public function validate_version_number( $version ) { |
|
493 | - |
|
494 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
495 | - // valid |
|
496 | - } else { |
|
497 | - $version = '';// not validated |
|
498 | - } |
|
499 | - |
|
500 | - return $version; |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * Get the latest version of Font Awesome. |
|
506 | - * |
|
507 | - * We check for a cached bersion and if none we will check for a live version via API and then cache it for 48 hours. |
|
508 | - * |
|
509 | - * @since 1.0.7 |
|
510 | - * @return mixed|string The latest version number found. |
|
511 | - */ |
|
512 | - public function get_latest_version( $force_api = false ) { |
|
513 | - $latest_version = $this->latest; |
|
514 | - |
|
515 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
516 | - |
|
517 | - if ( $cache === false || $force_api ) { // its not set |
|
518 | - $api_ver = $this->get_latest_version_from_api(); |
|
519 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
520 | - $latest_version = $api_ver; |
|
521 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
522 | - } |
|
523 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
524 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
525 | - $latest_version = $cache; |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - return $latest_version; |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * Get the latest Font Awesome version from the github API. |
|
534 | - * |
|
535 | - * @since 1.0.7 |
|
536 | - * @return string The latest version number or `0` on API fail. |
|
537 | - */ |
|
538 | - public function get_latest_version_from_api() { |
|
539 | - $version = "0"; |
|
540 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
541 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
542 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
543 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
544 | - $version = $api_response['tag_name']; |
|
545 | - } |
|
546 | - } |
|
547 | - |
|
548 | - return $version; |
|
549 | - } |
|
550 | - |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Run the class if found. |
|
555 | - */ |
|
556 | - WP_Font_Awesome_Settings::instance(); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Check a version number is valid and if so return it or else return an empty string. |
|
485 | + * |
|
486 | + * @param $version string The version number to check. |
|
487 | + * |
|
488 | + * @since 1.0.6 |
|
489 | + * |
|
490 | + * @return string Either a valid version number or an empty string. |
|
491 | + */ |
|
492 | + public function validate_version_number( $version ) { |
|
493 | + |
|
494 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
495 | + // valid |
|
496 | + } else { |
|
497 | + $version = '';// not validated |
|
498 | + } |
|
499 | + |
|
500 | + return $version; |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * Get the latest version of Font Awesome. |
|
506 | + * |
|
507 | + * We check for a cached bersion and if none we will check for a live version via API and then cache it for 48 hours. |
|
508 | + * |
|
509 | + * @since 1.0.7 |
|
510 | + * @return mixed|string The latest version number found. |
|
511 | + */ |
|
512 | + public function get_latest_version( $force_api = false ) { |
|
513 | + $latest_version = $this->latest; |
|
514 | + |
|
515 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
516 | + |
|
517 | + if ( $cache === false || $force_api ) { // its not set |
|
518 | + $api_ver = $this->get_latest_version_from_api(); |
|
519 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
520 | + $latest_version = $api_ver; |
|
521 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
522 | + } |
|
523 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
524 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
525 | + $latest_version = $cache; |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + return $latest_version; |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * Get the latest Font Awesome version from the github API. |
|
534 | + * |
|
535 | + * @since 1.0.7 |
|
536 | + * @return string The latest version number or `0` on API fail. |
|
537 | + */ |
|
538 | + public function get_latest_version_from_api() { |
|
539 | + $version = "0"; |
|
540 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
541 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
542 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
543 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
544 | + $version = $api_response['tag_name']; |
|
545 | + } |
|
546 | + } |
|
547 | + |
|
548 | + return $version; |
|
549 | + } |
|
550 | + |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Run the class if found. |
|
555 | + */ |
|
556 | + WP_Font_Awesome_Settings::instance(); |
|
557 | 557 | } |
558 | 558 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | add_ThickBox(); |
10 | 10 | ?> |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | <?php if ( $tabs ){ ?> |
15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
16 | 16 | <?php |
17 | - foreach ( $tabs as $name => $label ) { |
|
18 | - echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
19 | - } |
|
20 | - do_action( 'wpi_addons_tabs' ); |
|
21 | - ?> |
|
17 | + foreach ( $tabs as $name => $label ) { |
|
18 | + echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
19 | + } |
|
20 | + do_action( 'wpi_addons_tabs' ); |
|
21 | + ?> |
|
22 | 22 | </nav> |
23 | 23 | |
24 | 24 | <?php |
25 | 25 | |
26 | - if($current_tab == 'membership'){ |
|
26 | + if($current_tab == 'membership'){ |
|
27 | 27 | |
28 | - ?> |
|
28 | + ?> |
|
29 | 29 | |
30 | 30 | <div class="wpi-membership-tab-conatiner"> |
31 | 31 | <div class="membership-content"> |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | <h2>Have a membership key?</h2> |
37 | 37 | <p> |
38 | 38 | <?php |
39 | - $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | - echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108)); |
|
41 | - ?> |
|
39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | + echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108)); |
|
41 | + ?> |
|
42 | 42 | </p> |
43 | 43 | <?php }?> |
44 | 44 | |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | <div class="testimonial-content"> |
90 | 90 | <div class="t-image"> |
91 | 91 | <?php |
92 | - echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
93 | - ?> |
|
92 | + echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
93 | + ?> |
|
94 | 94 | </div> |
95 | 95 | <div class="t-content"> |
96 | 96 | <p> |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | <div class="testimonial-content"> |
110 | 110 | <div class="t-image"> |
111 | 111 | <?php |
112 | - echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
113 | - ?> |
|
112 | + echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
113 | + ?> |
|
114 | 114 | </div> |
115 | 115 | <div class="t-content"> |
116 | 116 | <p> |
@@ -134,20 +134,20 @@ discard block |
||
134 | 134 | </div> |
135 | 135 | </div> |
136 | 136 | <?php |
137 | - }else{ |
|
138 | - $installed_plugins = get_plugins(); |
|
137 | + }else{ |
|
138 | + $installed_plugins = get_plugins(); |
|
139 | 139 | $addon_obj = new WPInv_Admin_Addons(); |
140 | - if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
141 | - ?> |
|
140 | + if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
141 | + ?> |
|
142 | 142 | <ul class="wpi-products"><?php foreach ( $addons as $addon ) : |
143 | 143 | if(965==$addon->info->id){continue;}// don't show quote add on |
144 | - ?><li class="wpi-product"> |
|
144 | + ?><li class="wpi-product"> |
|
145 | 145 | <div class="wpi-product-title"> |
146 | 146 | <h3><?php |
147 | - if ( ! empty( $addon->info->excerpt) ){ |
|
148 | - echo wpi_help_tip( $addon->info->excerpt ); |
|
149 | - } |
|
150 | - echo esc_html( $addon->info->title ); ?></h3> |
|
147 | + if ( ! empty( $addon->info->excerpt) ){ |
|
148 | + echo wpi_help_tip( $addon->info->excerpt ); |
|
149 | + } |
|
150 | + echo esc_html( $addon->info->title ); ?></h3> |
|
151 | 151 | </div> |
152 | 152 | |
153 | 153 | <span class="wpi-product-image"> |
@@ -155,27 +155,27 @@ discard block |
||
155 | 155 | <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
156 | 156 | <?php endif; |
157 | 157 | |
158 | - if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
159 | - echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&TB_iframe=true&width=770&height=660" class="thickbox" >'; |
|
160 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
161 | - echo '</a>'; |
|
162 | - }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
163 | - if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
164 | - $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&TB_iframe=true&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com'); |
|
165 | - }else{ |
|
166 | - // if installed show activation link |
|
167 | - if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
168 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
169 | - }else{ |
|
170 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
171 | - } |
|
172 | - } |
|
173 | - echo '<a href="'.$url.'" class="thickbox">'; |
|
174 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
175 | - echo '</a>'; |
|
176 | - } |
|
177 | - |
|
178 | - ?> |
|
158 | + if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
159 | + echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&TB_iframe=true&width=770&height=660" class="thickbox" >'; |
|
160 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
161 | + echo '</a>'; |
|
162 | + }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
163 | + if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
164 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&TB_iframe=true&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com'); |
|
165 | + }else{ |
|
166 | + // if installed show activation link |
|
167 | + if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
168 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
169 | + }else{ |
|
170 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
171 | + } |
|
172 | + } |
|
173 | + echo '<a href="'.$url.'" class="thickbox">'; |
|
174 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
175 | + echo '</a>'; |
|
176 | + } |
|
177 | + |
|
178 | + ?> |
|
179 | 179 | |
180 | 180 | </span> |
181 | 181 | |
@@ -183,15 +183,15 @@ discard block |
||
183 | 183 | <span class="wpi-product-button"> |
184 | 184 | <?php |
185 | 185 | $addon_obj->output_button( $addon ); |
186 | - ?> |
|
186 | + ?> |
|
187 | 187 | </span> |
188 | 188 | |
189 | 189 | <span class="wpi-price"><?php //print_r($addon); //echo wp_kses_post( $addon->price ); ?></span></li><?php endforeach; ?></ul> |
190 | 190 | <?php endif; |
191 | - } |
|
191 | + } |
|
192 | 192 | |
193 | - } |
|
194 | - ?> |
|
193 | + } |
|
194 | + ?> |
|
195 | 195 | |
196 | 196 | |
197 | 197 | <div class="clearfix" ></div> |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key",'invoicing');?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install",'invoicing');?></button> |
211 | 211 | <br> |
212 | 212 | <?php |
213 | - echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
214 | - ?> |
|
213 | + echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
214 | + ?> |
|
215 | 215 | </span> |
216 | 216 | </div> |
217 | 217 |
@@ -12,125 +12,125 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class WPInv_Session_Handler extends WPInv_Session { |
14 | 14 | |
15 | - /** |
|
16 | - * Cookie name used for the session. |
|
17 | - * |
|
18 | - * @var string cookie name |
|
19 | - */ |
|
20 | - protected $_cookie; |
|
21 | - |
|
22 | - /** |
|
23 | - * Stores session expiry. |
|
24 | - * |
|
25 | - * @var string session due to expire timestamp |
|
26 | - */ |
|
27 | - protected $_session_expiring; |
|
28 | - |
|
29 | - /** |
|
30 | - * Stores session due to expire timestamp. |
|
31 | - * |
|
32 | - * @var string session expiration timestamp |
|
33 | - */ |
|
34 | - protected $_session_expiration; |
|
35 | - |
|
36 | - /** |
|
37 | - * True when the cookie exists. |
|
38 | - * |
|
39 | - * @var bool Based on whether a cookie exists. |
|
40 | - */ |
|
41 | - protected $_has_cookie = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * Table name for session data. |
|
45 | - * |
|
46 | - * @var string Custom session table name |
|
47 | - */ |
|
48 | - protected $_table; |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor for the session class. |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - |
|
55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
15 | + /** |
|
16 | + * Cookie name used for the session. |
|
17 | + * |
|
18 | + * @var string cookie name |
|
19 | + */ |
|
20 | + protected $_cookie; |
|
21 | + |
|
22 | + /** |
|
23 | + * Stores session expiry. |
|
24 | + * |
|
25 | + * @var string session due to expire timestamp |
|
26 | + */ |
|
27 | + protected $_session_expiring; |
|
28 | + |
|
29 | + /** |
|
30 | + * Stores session due to expire timestamp. |
|
31 | + * |
|
32 | + * @var string session expiration timestamp |
|
33 | + */ |
|
34 | + protected $_session_expiration; |
|
35 | + |
|
36 | + /** |
|
37 | + * True when the cookie exists. |
|
38 | + * |
|
39 | + * @var bool Based on whether a cookie exists. |
|
40 | + */ |
|
41 | + protected $_has_cookie = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * Table name for session data. |
|
45 | + * |
|
46 | + * @var string Custom session table name |
|
47 | + */ |
|
48 | + protected $_table; |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor for the session class. |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + |
|
55 | + $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
56 | 56 | add_action( 'init', array( $this, 'init' ), -1 ); |
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Init hooks and session data. |
|
61 | - * |
|
62 | - * @since 3.3.0 |
|
63 | - */ |
|
64 | - public function init() { |
|
65 | - $this->init_session_cookie(); |
|
66 | - |
|
67 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
68 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
69 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
70 | - |
|
71 | - if ( ! is_user_logged_in() ) { |
|
72 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Setup cookie and customer ID. |
|
78 | - * |
|
79 | - * @since 3.6.0 |
|
80 | - */ |
|
81 | - public function init_session_cookie() { |
|
82 | - $cookie = $this->get_session_cookie(); |
|
83 | - |
|
84 | - if ( $cookie ) { |
|
85 | - $this->_customer_id = $cookie[0]; |
|
86 | - $this->_session_expiration = $cookie[1]; |
|
87 | - $this->_session_expiring = $cookie[2]; |
|
88 | - $this->_has_cookie = true; |
|
89 | - $this->_data = $this->get_session_data(); |
|
90 | - |
|
91 | - // If the user logs in, update session. |
|
92 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
93 | - $this->_customer_id = get_current_user_id(); |
|
94 | - $this->_dirty = true; |
|
95 | - $this->save_data(); |
|
96 | - $this->set_customer_session_cookie( true ); |
|
97 | - } |
|
98 | - |
|
99 | - // Update session if its close to expiring. |
|
100 | - if ( time() > $this->_session_expiring ) { |
|
101 | - $this->set_session_expiration(); |
|
102 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
103 | - } |
|
104 | - } else { |
|
105 | - $this->set_session_expiration(); |
|
106 | - $this->_customer_id = $this->generate_customer_id(); |
|
107 | - $this->_data = $this->get_session_data(); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
113 | - * |
|
114 | - * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
115 | - * |
|
116 | - * Warning: Cookies will only be set if this is called before the headers are sent. |
|
117 | - * |
|
118 | - * @param bool $set Should the session cookie be set. |
|
119 | - */ |
|
120 | - public function set_customer_session_cookie( $set ) { |
|
121 | - if ( $set ) { |
|
122 | - $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
123 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
124 | - $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
125 | - $this->_has_cookie = true; |
|
126 | - |
|
127 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
128 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Init hooks and session data. |
|
61 | + * |
|
62 | + * @since 3.3.0 |
|
63 | + */ |
|
64 | + public function init() { |
|
65 | + $this->init_session_cookie(); |
|
66 | + |
|
67 | + add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
68 | + add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
69 | + add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
70 | + |
|
71 | + if ( ! is_user_logged_in() ) { |
|
72 | + add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Setup cookie and customer ID. |
|
78 | + * |
|
79 | + * @since 3.6.0 |
|
80 | + */ |
|
81 | + public function init_session_cookie() { |
|
82 | + $cookie = $this->get_session_cookie(); |
|
83 | + |
|
84 | + if ( $cookie ) { |
|
85 | + $this->_customer_id = $cookie[0]; |
|
86 | + $this->_session_expiration = $cookie[1]; |
|
87 | + $this->_session_expiring = $cookie[2]; |
|
88 | + $this->_has_cookie = true; |
|
89 | + $this->_data = $this->get_session_data(); |
|
90 | + |
|
91 | + // If the user logs in, update session. |
|
92 | + if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
93 | + $this->_customer_id = get_current_user_id(); |
|
94 | + $this->_dirty = true; |
|
95 | + $this->save_data(); |
|
96 | + $this->set_customer_session_cookie( true ); |
|
97 | + } |
|
98 | + |
|
99 | + // Update session if its close to expiring. |
|
100 | + if ( time() > $this->_session_expiring ) { |
|
101 | + $this->set_session_expiration(); |
|
102 | + $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
103 | + } |
|
104 | + } else { |
|
105 | + $this->set_session_expiration(); |
|
106 | + $this->_customer_id = $this->generate_customer_id(); |
|
107 | + $this->_data = $this->get_session_data(); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
113 | + * |
|
114 | + * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
115 | + * |
|
116 | + * Warning: Cookies will only be set if this is called before the headers are sent. |
|
117 | + * |
|
118 | + * @param bool $set Should the session cookie be set. |
|
119 | + */ |
|
120 | + public function set_customer_session_cookie( $set ) { |
|
121 | + if ( $set ) { |
|
122 | + $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
123 | + $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
124 | + $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
125 | + $this->_has_cookie = true; |
|
126 | + |
|
127 | + if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
128 | + $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
134 | 134 | if ( ! headers_sent() ) { |
135 | 135 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
136 | 136 | } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
@@ -139,96 +139,96 @@ discard block |
||
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | - /** |
|
143 | - * Should the session cookie be secure? |
|
144 | - * |
|
145 | - * @since 3.6.0 |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - protected function use_secure_cookie() { |
|
142 | + /** |
|
143 | + * Should the session cookie be secure? |
|
144 | + * |
|
145 | + * @since 3.6.0 |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + protected function use_secure_cookie() { |
|
149 | 149 | $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
150 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
155 | - * |
|
156 | - * @return bool |
|
157 | - */ |
|
158 | - public function has_session() { |
|
159 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Set session expiration. |
|
164 | - */ |
|
165 | - public function set_session_expiration() { |
|
166 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
167 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Generate a unique customer ID for guests, or return user ID if logged in. |
|
172 | - * |
|
173 | - * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID. |
|
174 | - * |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - public function generate_customer_id() { |
|
178 | - $customer_id = ''; |
|
179 | - |
|
180 | - if ( is_user_logged_in() ) { |
|
181 | - $customer_id = get_current_user_id(); |
|
182 | - } |
|
183 | - |
|
184 | - if ( empty( $customer_id ) ) { |
|
150 | + return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
155 | + * |
|
156 | + * @return bool |
|
157 | + */ |
|
158 | + public function has_session() { |
|
159 | + return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Set session expiration. |
|
164 | + */ |
|
165 | + public function set_session_expiration() { |
|
166 | + $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
167 | + $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Generate a unique customer ID for guests, or return user ID if logged in. |
|
172 | + * |
|
173 | + * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID. |
|
174 | + * |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + public function generate_customer_id() { |
|
178 | + $customer_id = ''; |
|
179 | + |
|
180 | + if ( is_user_logged_in() ) { |
|
181 | + $customer_id = get_current_user_id(); |
|
182 | + } |
|
183 | + |
|
184 | + if ( empty( $customer_id ) ) { |
|
185 | 185 | $customer_id = wp_create_nonce('wpinv-session-customer-id'); |
186 | - } |
|
187 | - |
|
188 | - return $customer_id; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Get the session cookie, if set. Otherwise return false. |
|
193 | - * |
|
194 | - * Session cookies without a customer ID are invalid. |
|
195 | - * |
|
196 | - * @return bool|array |
|
197 | - */ |
|
198 | - public function get_session_cookie() { |
|
199 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
200 | - |
|
201 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
202 | - return false; |
|
203 | - } |
|
204 | - |
|
205 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
206 | - |
|
207 | - if ( empty( $customer_id ) ) { |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - // Validate hash. |
|
212 | - $to_hash = $customer_id . '|' . $session_expiration; |
|
213 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
214 | - |
|
215 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
216 | - return false; |
|
217 | - } |
|
218 | - |
|
219 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Get session data. |
|
224 | - * |
|
225 | - * @return array |
|
226 | - */ |
|
227 | - public function get_session_data() { |
|
228 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
229 | - } |
|
230 | - |
|
231 | - public function generate_key($customer_id){ |
|
186 | + } |
|
187 | + |
|
188 | + return $customer_id; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Get the session cookie, if set. Otherwise return false. |
|
193 | + * |
|
194 | + * Session cookies without a customer ID are invalid. |
|
195 | + * |
|
196 | + * @return bool|array |
|
197 | + */ |
|
198 | + public function get_session_cookie() { |
|
199 | + $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
200 | + |
|
201 | + if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
202 | + return false; |
|
203 | + } |
|
204 | + |
|
205 | + list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
206 | + |
|
207 | + if ( empty( $customer_id ) ) { |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + // Validate hash. |
|
212 | + $to_hash = $customer_id . '|' . $session_expiration; |
|
213 | + $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
214 | + |
|
215 | + if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
216 | + return false; |
|
217 | + } |
|
218 | + |
|
219 | + return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Get session data. |
|
224 | + * |
|
225 | + * @return array |
|
226 | + */ |
|
227 | + public function get_session_data() { |
|
228 | + return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
229 | + } |
|
230 | + |
|
231 | + public function generate_key($customer_id){ |
|
232 | 232 | if(!$customer_id){ |
233 | 233 | return; |
234 | 234 | } |
@@ -236,62 +236,62 @@ discard block |
||
236 | 236 | return 'wpi_trans_'.$customer_id; |
237 | 237 | } |
238 | 238 | |
239 | - /** |
|
240 | - * Save data. |
|
241 | - */ |
|
242 | - public function save_data() { |
|
243 | - // Dirty if something changed - prevents saving nothing new. |
|
244 | - if ( $this->_dirty && $this->has_session() ) { |
|
239 | + /** |
|
240 | + * Save data. |
|
241 | + */ |
|
242 | + public function save_data() { |
|
243 | + // Dirty if something changed - prevents saving nothing new. |
|
244 | + if ( $this->_dirty && $this->has_session() ) { |
|
245 | 245 | |
246 | 246 | set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
247 | 247 | |
248 | - $this->_dirty = false; |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Destroy all session data. |
|
254 | - */ |
|
255 | - public function destroy_session() { |
|
256 | - $this->delete_session( $this->_customer_id ); |
|
257 | - $this->forget_session(); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Forget all session data without destroying it. |
|
262 | - */ |
|
263 | - public function forget_session() { |
|
264 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
265 | - |
|
266 | - wpinv_empty_cart(); |
|
267 | - |
|
268 | - $this->_data = array(); |
|
269 | - $this->_dirty = false; |
|
270 | - $this->_customer_id = $this->generate_customer_id(); |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
275 | - * |
|
276 | - * @param int $uid User ID. |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - public function nonce_user_logged_out( $uid ) { |
|
280 | - return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Returns the session. |
|
285 | - * |
|
286 | - * @param string $customer_id Customer ID. |
|
287 | - * @param mixed $default Default session value. |
|
288 | - * @return string|array |
|
289 | - */ |
|
290 | - public function get_session( $customer_id, $default = false ) { |
|
291 | - |
|
292 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
293 | - return false; |
|
294 | - } |
|
248 | + $this->_dirty = false; |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Destroy all session data. |
|
254 | + */ |
|
255 | + public function destroy_session() { |
|
256 | + $this->delete_session( $this->_customer_id ); |
|
257 | + $this->forget_session(); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Forget all session data without destroying it. |
|
262 | + */ |
|
263 | + public function forget_session() { |
|
264 | + $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
265 | + |
|
266 | + wpinv_empty_cart(); |
|
267 | + |
|
268 | + $this->_data = array(); |
|
269 | + $this->_dirty = false; |
|
270 | + $this->_customer_id = $this->generate_customer_id(); |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
275 | + * |
|
276 | + * @param int $uid User ID. |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + public function nonce_user_logged_out( $uid ) { |
|
280 | + return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Returns the session. |
|
285 | + * |
|
286 | + * @param string $customer_id Customer ID. |
|
287 | + * @param mixed $default Default session value. |
|
288 | + * @return string|array |
|
289 | + */ |
|
290 | + public function get_session( $customer_id, $default = false ) { |
|
291 | + |
|
292 | + if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
293 | + return false; |
|
294 | + } |
|
295 | 295 | |
296 | 296 | if ( !is_user_logged_in() ) { |
297 | 297 | if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){ |
@@ -306,32 +306,32 @@ discard block |
||
306 | 306 | $value = $default; |
307 | 307 | } |
308 | 308 | |
309 | - return maybe_unserialize( $value ); |
|
310 | - } |
|
309 | + return maybe_unserialize( $value ); |
|
310 | + } |
|
311 | 311 | |
312 | - /** |
|
313 | - * Delete the session from the cache and database. |
|
314 | - * |
|
315 | - * @param int $customer_id Customer ID. |
|
316 | - */ |
|
317 | - public function delete_session( $customer_id ) { |
|
312 | + /** |
|
313 | + * Delete the session from the cache and database. |
|
314 | + * |
|
315 | + * @param int $customer_id Customer ID. |
|
316 | + */ |
|
317 | + public function delete_session( $customer_id ) { |
|
318 | 318 | |
319 | 319 | $key = $this->generate_key($customer_id); |
320 | 320 | |
321 | - delete_transient($key); |
|
322 | - } |
|
321 | + delete_transient($key); |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * Update the session expiry timestamp. |
|
326 | - * |
|
327 | - * @param string $customer_id Customer ID. |
|
328 | - * @param int $timestamp Timestamp to expire the cookie. |
|
329 | - */ |
|
330 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
324 | + /** |
|
325 | + * Update the session expiry timestamp. |
|
326 | + * |
|
327 | + * @param string $customer_id Customer ID. |
|
328 | + * @param int $timestamp Timestamp to expire the cookie. |
|
329 | + */ |
|
330 | + public function update_session_timestamp( $customer_id, $timestamp ) { |
|
331 | 331 | |
332 | 332 | set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp); |
333 | 333 | |
334 | - } |
|
334 | + } |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | global $wpi_session; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | */ |
5 | 5 | |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -12,112 +12,112 @@ discard block |
||
12 | 12 | */ |
13 | 13 | abstract class WPInv_Session { |
14 | 14 | |
15 | - /** |
|
16 | - * Customer ID. |
|
17 | - * |
|
18 | - * @var int $_customer_id Customer ID. |
|
19 | - */ |
|
20 | - protected $_customer_id; |
|
15 | + /** |
|
16 | + * Customer ID. |
|
17 | + * |
|
18 | + * @var int $_customer_id Customer ID. |
|
19 | + */ |
|
20 | + protected $_customer_id; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Session Data. |
|
24 | - * |
|
25 | - * @var array $_data Data array. |
|
26 | - */ |
|
27 | - protected $_data = array(); |
|
22 | + /** |
|
23 | + * Session Data. |
|
24 | + * |
|
25 | + * @var array $_data Data array. |
|
26 | + */ |
|
27 | + protected $_data = array(); |
|
28 | 28 | |
29 | - /** |
|
30 | - * Dirty when the session needs saving. |
|
31 | - * |
|
32 | - * @var bool $_dirty When something changes |
|
33 | - */ |
|
34 | - protected $_dirty = false; |
|
29 | + /** |
|
30 | + * Dirty when the session needs saving. |
|
31 | + * |
|
32 | + * @var bool $_dirty When something changes |
|
33 | + */ |
|
34 | + protected $_dirty = false; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Init hooks and session data. Extended by child classes. |
|
38 | - * |
|
39 | - * @since 3.3.0 |
|
40 | - */ |
|
41 | - public function init() {} |
|
36 | + /** |
|
37 | + * Init hooks and session data. Extended by child classes. |
|
38 | + * |
|
39 | + * @since 3.3.0 |
|
40 | + */ |
|
41 | + public function init() {} |
|
42 | 42 | |
43 | - /** |
|
44 | - * Cleanup session data. Extended by child classes. |
|
45 | - */ |
|
46 | - public function cleanup_sessions() {} |
|
43 | + /** |
|
44 | + * Cleanup session data. Extended by child classes. |
|
45 | + */ |
|
46 | + public function cleanup_sessions() {} |
|
47 | 47 | |
48 | - /** |
|
49 | - * Magic get method. |
|
50 | - * |
|
51 | - * @param mixed $key Key to get. |
|
52 | - * @return mixed |
|
53 | - */ |
|
54 | - public function __get( $key ) { |
|
55 | - return $this->get( $key ); |
|
56 | - } |
|
48 | + /** |
|
49 | + * Magic get method. |
|
50 | + * |
|
51 | + * @param mixed $key Key to get. |
|
52 | + * @return mixed |
|
53 | + */ |
|
54 | + public function __get( $key ) { |
|
55 | + return $this->get( $key ); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Magic set method. |
|
60 | - * |
|
61 | - * @param mixed $key Key to set. |
|
62 | - * @param mixed $value Value to set. |
|
63 | - */ |
|
64 | - public function __set( $key, $value ) { |
|
65 | - $this->set( $key, $value ); |
|
66 | - } |
|
58 | + /** |
|
59 | + * Magic set method. |
|
60 | + * |
|
61 | + * @param mixed $key Key to set. |
|
62 | + * @param mixed $value Value to set. |
|
63 | + */ |
|
64 | + public function __set( $key, $value ) { |
|
65 | + $this->set( $key, $value ); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Magic isset method. |
|
70 | - * |
|
71 | - * @param mixed $key Key to check. |
|
72 | - * @return bool |
|
73 | - */ |
|
74 | - public function __isset( $key ) { |
|
75 | - return isset( $this->_data[ sanitize_title( $key ) ] ); |
|
76 | - } |
|
68 | + /** |
|
69 | + * Magic isset method. |
|
70 | + * |
|
71 | + * @param mixed $key Key to check. |
|
72 | + * @return bool |
|
73 | + */ |
|
74 | + public function __isset( $key ) { |
|
75 | + return isset( $this->_data[ sanitize_title( $key ) ] ); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Magic unset method. |
|
80 | - * |
|
81 | - * @param mixed $key Key to unset. |
|
82 | - */ |
|
83 | - public function __unset( $key ) { |
|
84 | - if ( isset( $this->_data[ $key ] ) ) { |
|
85 | - unset( $this->_data[ $key ] ); |
|
86 | - $this->_dirty = true; |
|
87 | - } |
|
88 | - } |
|
78 | + /** |
|
79 | + * Magic unset method. |
|
80 | + * |
|
81 | + * @param mixed $key Key to unset. |
|
82 | + */ |
|
83 | + public function __unset( $key ) { |
|
84 | + if ( isset( $this->_data[ $key ] ) ) { |
|
85 | + unset( $this->_data[ $key ] ); |
|
86 | + $this->_dirty = true; |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Get a session variable. |
|
92 | - * |
|
93 | - * @param string $key Key to get. |
|
94 | - * @param mixed $default used if the session variable isn't set. |
|
95 | - * @return array|string value of session variable |
|
96 | - */ |
|
97 | - public function get( $key, $default = null ) { |
|
98 | - $key = sanitize_key( $key ); |
|
99 | - return isset( $this->_data[ $key ] ) ? maybe_unserialize( $this->_data[ $key ] ) : $default; |
|
100 | - } |
|
90 | + /** |
|
91 | + * Get a session variable. |
|
92 | + * |
|
93 | + * @param string $key Key to get. |
|
94 | + * @param mixed $default used if the session variable isn't set. |
|
95 | + * @return array|string value of session variable |
|
96 | + */ |
|
97 | + public function get( $key, $default = null ) { |
|
98 | + $key = sanitize_key( $key ); |
|
99 | + return isset( $this->_data[ $key ] ) ? maybe_unserialize( $this->_data[ $key ] ) : $default; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Set a session variable. |
|
104 | - * |
|
105 | - * @param string $key Key to set. |
|
106 | - * @param mixed $value Value to set. |
|
107 | - */ |
|
108 | - public function set( $key, $value ) { |
|
109 | - if ( $value !== $this->get( $key ) ) { |
|
110 | - $this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value ); |
|
111 | - $this->_dirty = true; |
|
112 | - } |
|
113 | - } |
|
102 | + /** |
|
103 | + * Set a session variable. |
|
104 | + * |
|
105 | + * @param string $key Key to set. |
|
106 | + * @param mixed $value Value to set. |
|
107 | + */ |
|
108 | + public function set( $key, $value ) { |
|
109 | + if ( $value !== $this->get( $key ) ) { |
|
110 | + $this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value ); |
|
111 | + $this->_dirty = true; |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Get customer ID. |
|
117 | - * |
|
118 | - * @return int |
|
119 | - */ |
|
120 | - public function get_customer_id() { |
|
121 | - return $this->_customer_id; |
|
122 | - } |
|
115 | + /** |
|
116 | + * Get customer ID. |
|
117 | + * |
|
118 | + * @return int |
|
119 | + */ |
|
120 | + public function get_customer_id() { |
|
121 | + return $this->_customer_id; |
|
122 | + } |
|
123 | 123 | } |
@@ -11,231 +11,231 @@ discard block |
||
11 | 11 | $this->method_title = '3-D Secure Payment Gateway by CardinalCommerce'; |
12 | 12 | |
13 | 13 | $this->currencies = array( |
14 | - 'ADP' => '020', |
|
15 | - 'AED' => '784', |
|
16 | - 'AFA' => '004', |
|
17 | - 'AFN' => '971', |
|
18 | - 'ALL' => '008', |
|
19 | - 'AMD' => '051', |
|
20 | - 'ANG' => '532', |
|
21 | - 'AOA' => '973', |
|
22 | - 'AON' => '024', |
|
23 | - 'ARS' => '032', |
|
24 | - 'ATS' => '040', |
|
25 | - 'AUD' => '036', |
|
26 | - 'AWG' => '533', |
|
27 | - 'AZM' => '031', |
|
28 | - 'AZN' => '944', |
|
29 | - 'BAM' => '977', |
|
30 | - 'BBD' => '052', |
|
31 | - 'BDT' => '050', |
|
32 | - 'BEF' => '056', |
|
33 | - 'BGL' => '100', |
|
34 | - 'BGN' => '975', |
|
35 | - 'BHD' => '048', |
|
36 | - 'BIF' => '108', |
|
37 | - 'BMD' => '060', |
|
38 | - 'BND' => '096', |
|
39 | - 'BOB' => '068', |
|
40 | - 'BOV' => '984', |
|
41 | - 'BRL' => '986', |
|
42 | - 'BSD' => '044', |
|
43 | - 'BTN' => '064', |
|
44 | - 'BWP' => '072', |
|
45 | - 'BYR' => '974', |
|
46 | - 'BZD' => '084', |
|
47 | - 'CAD' => '124', |
|
48 | - 'CDF' => '976', |
|
49 | - 'CHE' => '947', |
|
50 | - 'CHF' => '756', |
|
51 | - 'CHW' => '948', |
|
52 | - 'CLF' => '990', |
|
53 | - 'CLP' => '152', |
|
54 | - 'CNY' => '156', |
|
55 | - 'COP' => '170', |
|
56 | - 'COU' => '970', |
|
57 | - 'CRC' => '188', |
|
58 | - 'CSD' => '891', |
|
59 | - 'CUC' => '931', |
|
60 | - 'CUP' => '192', |
|
61 | - 'CVE' => '132', |
|
62 | - 'CYP' => '196', |
|
63 | - 'CZK' => '203', |
|
64 | - 'DEM' => '276', |
|
65 | - 'DJF' => '262', |
|
66 | - 'DKK' => '208', |
|
67 | - 'DOP' => '214', |
|
68 | - 'DZD' => '012', |
|
69 | - 'EEK' => '233', |
|
70 | - 'EGP' => '818', |
|
71 | - 'ERN' => '232', |
|
72 | - 'ESP' => '724', |
|
73 | - 'ETB' => '230', |
|
74 | - 'EUR' => '978', |
|
75 | - 'FIM' => '246', |
|
76 | - 'FJD' => '242', |
|
77 | - 'FKP' => '238', |
|
78 | - 'FRF' => '250', |
|
79 | - 'GBP' => '826', |
|
80 | - 'GEL' => '981', |
|
81 | - 'GHC' => '288', |
|
82 | - 'GHS' => '936', |
|
83 | - 'GIP' => '292', |
|
84 | - 'GMD' => '270', |
|
85 | - 'GNF' => '324', |
|
86 | - 'GTQ' => '320', |
|
87 | - 'GWP' => '624', |
|
88 | - 'GYD' => '328', |
|
89 | - 'HKD' => '344', |
|
90 | - 'HNL' => '340', |
|
91 | - 'HRK' => '191', |
|
92 | - 'HTG' => '332', |
|
93 | - 'HUF' => '348', |
|
94 | - 'IDR' => '360', |
|
95 | - 'IEP' => '372', |
|
96 | - 'ILS' => '376', |
|
97 | - 'INR' => '356', |
|
98 | - 'IQD' => '368', |
|
99 | - 'IRR' => '364', |
|
100 | - 'ISK' => '352', |
|
101 | - 'ITL' => '380', |
|
102 | - 'JMD' => '388', |
|
103 | - 'JOD' => '400', |
|
104 | - 'JPY' => '392', |
|
105 | - 'KES' => '404', |
|
106 | - 'KGS' => '417', |
|
107 | - 'KHR' => '116', |
|
108 | - 'KMF' => '174', |
|
109 | - 'KPW' => '408', |
|
110 | - 'KRW' => '410', |
|
111 | - 'KWD' => '414', |
|
112 | - 'KYD' => '136', |
|
113 | - 'KZT' => '398', |
|
114 | - 'LAK' => '418', |
|
115 | - 'LBP' => '422', |
|
116 | - 'LKR' => '144', |
|
117 | - 'LRD' => '430', |
|
118 | - 'LSL' => '426', |
|
119 | - 'LTL' => '440', |
|
120 | - 'LUF' => '442', |
|
121 | - 'LVL' => '428', |
|
122 | - 'LYD' => '434', |
|
123 | - 'MAD' => '504', |
|
124 | - 'MDL' => '498', |
|
125 | - 'MGA' => '969', |
|
126 | - 'MGF' => '450', |
|
127 | - 'MKD' => '807', |
|
128 | - 'MMK' => '104', |
|
129 | - 'MNT' => '496', |
|
130 | - 'MOP' => '446', |
|
131 | - 'MRO' => '478', |
|
132 | - 'MTL' => '470', |
|
133 | - 'MUR' => '480', |
|
134 | - 'MVR' => '462', |
|
135 | - 'MWK' => '454', |
|
136 | - 'MXN' => '484', |
|
137 | - 'MXV' => '979', |
|
138 | - 'MYR' => '458', |
|
139 | - 'MZM' => '508', |
|
140 | - 'MZN' => '943', |
|
141 | - 'NAD' => '516', |
|
142 | - 'NGN' => '566', |
|
143 | - 'NIO' => '558', |
|
144 | - 'NLG' => '528', |
|
145 | - 'NOK' => '578', |
|
146 | - 'NPR' => '524', |
|
147 | - 'NZD' => '554', |
|
148 | - 'OMR' => '512', |
|
149 | - 'PAB' => '590', |
|
150 | - 'PEN' => '604', |
|
151 | - 'PGK' => '598', |
|
152 | - 'PHP' => '608', |
|
153 | - 'PKR' => '586', |
|
154 | - 'PLN' => '985', |
|
155 | - 'PTE' => '620', |
|
156 | - 'PYG' => '600', |
|
157 | - 'QAR' => '634', |
|
158 | - 'ROL' => '642', |
|
159 | - 'RON' => '946', |
|
160 | - 'RSD' => '941', |
|
161 | - 'RUB' => '643', |
|
162 | - 'RUR' => '810', |
|
163 | - 'RWF' => '646', |
|
164 | - 'SAR' => '682', |
|
165 | - 'SBD' => '090', |
|
166 | - 'SCR' => '690', |
|
167 | - 'SDD' => '736', |
|
168 | - 'SDG' => '938', |
|
169 | - 'SEK' => '752', |
|
170 | - 'SGD' => '702', |
|
171 | - 'SHP' => '654', |
|
172 | - 'SIT' => '705', |
|
173 | - 'SKK' => '703', |
|
174 | - 'SLL' => '694', |
|
175 | - 'SOS' => '706', |
|
176 | - 'SRD' => '968', |
|
177 | - 'SRG' => '740', |
|
178 | - 'SSP' => '728', |
|
179 | - 'STD' => '678', |
|
180 | - 'SVC' => '222', |
|
181 | - 'SYP' => '760', |
|
182 | - 'SZL' => '748', |
|
183 | - 'THB' => '764', |
|
184 | - 'TJS' => '972', |
|
185 | - 'TMM' => '795', |
|
186 | - 'TMT' => '934', |
|
187 | - 'TND' => '788', |
|
188 | - 'TOP' => '776', |
|
189 | - 'TPE' => '626', |
|
190 | - 'TRL' => '792', |
|
191 | - 'TRY' => '949', |
|
192 | - 'TTD' => '780', |
|
193 | - 'TWD' => '901', |
|
194 | - 'TZS' => '834', |
|
195 | - 'UAH' => '980', |
|
196 | - 'UGX' => '800', |
|
197 | - 'USD' => '840', |
|
198 | - 'USN' => '997', |
|
199 | - 'UYI' => '940', |
|
200 | - 'UYU' => '858', |
|
201 | - 'UZS' => '860', |
|
202 | - 'VEB' => '862', |
|
203 | - 'VEF' => '937', |
|
204 | - 'VND' => '704', |
|
205 | - 'VUV' => '548', |
|
206 | - 'WST' => '882', |
|
207 | - 'XAF' => '950', |
|
208 | - 'XCD' => '951', |
|
209 | - 'XOF' => '952', |
|
210 | - 'XPF' => '953', |
|
211 | - 'XXX' => '999', |
|
212 | - 'YER' => '886', |
|
213 | - 'YUM' => '891', |
|
214 | - 'ZAR' => '710', |
|
215 | - 'ZMK' => '894', |
|
216 | - 'ZMW' => '967', |
|
217 | - 'ZWD' => '716', |
|
218 | - 'ZWL' => '932', |
|
14 | + 'ADP' => '020', |
|
15 | + 'AED' => '784', |
|
16 | + 'AFA' => '004', |
|
17 | + 'AFN' => '971', |
|
18 | + 'ALL' => '008', |
|
19 | + 'AMD' => '051', |
|
20 | + 'ANG' => '532', |
|
21 | + 'AOA' => '973', |
|
22 | + 'AON' => '024', |
|
23 | + 'ARS' => '032', |
|
24 | + 'ATS' => '040', |
|
25 | + 'AUD' => '036', |
|
26 | + 'AWG' => '533', |
|
27 | + 'AZM' => '031', |
|
28 | + 'AZN' => '944', |
|
29 | + 'BAM' => '977', |
|
30 | + 'BBD' => '052', |
|
31 | + 'BDT' => '050', |
|
32 | + 'BEF' => '056', |
|
33 | + 'BGL' => '100', |
|
34 | + 'BGN' => '975', |
|
35 | + 'BHD' => '048', |
|
36 | + 'BIF' => '108', |
|
37 | + 'BMD' => '060', |
|
38 | + 'BND' => '096', |
|
39 | + 'BOB' => '068', |
|
40 | + 'BOV' => '984', |
|
41 | + 'BRL' => '986', |
|
42 | + 'BSD' => '044', |
|
43 | + 'BTN' => '064', |
|
44 | + 'BWP' => '072', |
|
45 | + 'BYR' => '974', |
|
46 | + 'BZD' => '084', |
|
47 | + 'CAD' => '124', |
|
48 | + 'CDF' => '976', |
|
49 | + 'CHE' => '947', |
|
50 | + 'CHF' => '756', |
|
51 | + 'CHW' => '948', |
|
52 | + 'CLF' => '990', |
|
53 | + 'CLP' => '152', |
|
54 | + 'CNY' => '156', |
|
55 | + 'COP' => '170', |
|
56 | + 'COU' => '970', |
|
57 | + 'CRC' => '188', |
|
58 | + 'CSD' => '891', |
|
59 | + 'CUC' => '931', |
|
60 | + 'CUP' => '192', |
|
61 | + 'CVE' => '132', |
|
62 | + 'CYP' => '196', |
|
63 | + 'CZK' => '203', |
|
64 | + 'DEM' => '276', |
|
65 | + 'DJF' => '262', |
|
66 | + 'DKK' => '208', |
|
67 | + 'DOP' => '214', |
|
68 | + 'DZD' => '012', |
|
69 | + 'EEK' => '233', |
|
70 | + 'EGP' => '818', |
|
71 | + 'ERN' => '232', |
|
72 | + 'ESP' => '724', |
|
73 | + 'ETB' => '230', |
|
74 | + 'EUR' => '978', |
|
75 | + 'FIM' => '246', |
|
76 | + 'FJD' => '242', |
|
77 | + 'FKP' => '238', |
|
78 | + 'FRF' => '250', |
|
79 | + 'GBP' => '826', |
|
80 | + 'GEL' => '981', |
|
81 | + 'GHC' => '288', |
|
82 | + 'GHS' => '936', |
|
83 | + 'GIP' => '292', |
|
84 | + 'GMD' => '270', |
|
85 | + 'GNF' => '324', |
|
86 | + 'GTQ' => '320', |
|
87 | + 'GWP' => '624', |
|
88 | + 'GYD' => '328', |
|
89 | + 'HKD' => '344', |
|
90 | + 'HNL' => '340', |
|
91 | + 'HRK' => '191', |
|
92 | + 'HTG' => '332', |
|
93 | + 'HUF' => '348', |
|
94 | + 'IDR' => '360', |
|
95 | + 'IEP' => '372', |
|
96 | + 'ILS' => '376', |
|
97 | + 'INR' => '356', |
|
98 | + 'IQD' => '368', |
|
99 | + 'IRR' => '364', |
|
100 | + 'ISK' => '352', |
|
101 | + 'ITL' => '380', |
|
102 | + 'JMD' => '388', |
|
103 | + 'JOD' => '400', |
|
104 | + 'JPY' => '392', |
|
105 | + 'KES' => '404', |
|
106 | + 'KGS' => '417', |
|
107 | + 'KHR' => '116', |
|
108 | + 'KMF' => '174', |
|
109 | + 'KPW' => '408', |
|
110 | + 'KRW' => '410', |
|
111 | + 'KWD' => '414', |
|
112 | + 'KYD' => '136', |
|
113 | + 'KZT' => '398', |
|
114 | + 'LAK' => '418', |
|
115 | + 'LBP' => '422', |
|
116 | + 'LKR' => '144', |
|
117 | + 'LRD' => '430', |
|
118 | + 'LSL' => '426', |
|
119 | + 'LTL' => '440', |
|
120 | + 'LUF' => '442', |
|
121 | + 'LVL' => '428', |
|
122 | + 'LYD' => '434', |
|
123 | + 'MAD' => '504', |
|
124 | + 'MDL' => '498', |
|
125 | + 'MGA' => '969', |
|
126 | + 'MGF' => '450', |
|
127 | + 'MKD' => '807', |
|
128 | + 'MMK' => '104', |
|
129 | + 'MNT' => '496', |
|
130 | + 'MOP' => '446', |
|
131 | + 'MRO' => '478', |
|
132 | + 'MTL' => '470', |
|
133 | + 'MUR' => '480', |
|
134 | + 'MVR' => '462', |
|
135 | + 'MWK' => '454', |
|
136 | + 'MXN' => '484', |
|
137 | + 'MXV' => '979', |
|
138 | + 'MYR' => '458', |
|
139 | + 'MZM' => '508', |
|
140 | + 'MZN' => '943', |
|
141 | + 'NAD' => '516', |
|
142 | + 'NGN' => '566', |
|
143 | + 'NIO' => '558', |
|
144 | + 'NLG' => '528', |
|
145 | + 'NOK' => '578', |
|
146 | + 'NPR' => '524', |
|
147 | + 'NZD' => '554', |
|
148 | + 'OMR' => '512', |
|
149 | + 'PAB' => '590', |
|
150 | + 'PEN' => '604', |
|
151 | + 'PGK' => '598', |
|
152 | + 'PHP' => '608', |
|
153 | + 'PKR' => '586', |
|
154 | + 'PLN' => '985', |
|
155 | + 'PTE' => '620', |
|
156 | + 'PYG' => '600', |
|
157 | + 'QAR' => '634', |
|
158 | + 'ROL' => '642', |
|
159 | + 'RON' => '946', |
|
160 | + 'RSD' => '941', |
|
161 | + 'RUB' => '643', |
|
162 | + 'RUR' => '810', |
|
163 | + 'RWF' => '646', |
|
164 | + 'SAR' => '682', |
|
165 | + 'SBD' => '090', |
|
166 | + 'SCR' => '690', |
|
167 | + 'SDD' => '736', |
|
168 | + 'SDG' => '938', |
|
169 | + 'SEK' => '752', |
|
170 | + 'SGD' => '702', |
|
171 | + 'SHP' => '654', |
|
172 | + 'SIT' => '705', |
|
173 | + 'SKK' => '703', |
|
174 | + 'SLL' => '694', |
|
175 | + 'SOS' => '706', |
|
176 | + 'SRD' => '968', |
|
177 | + 'SRG' => '740', |
|
178 | + 'SSP' => '728', |
|
179 | + 'STD' => '678', |
|
180 | + 'SVC' => '222', |
|
181 | + 'SYP' => '760', |
|
182 | + 'SZL' => '748', |
|
183 | + 'THB' => '764', |
|
184 | + 'TJS' => '972', |
|
185 | + 'TMM' => '795', |
|
186 | + 'TMT' => '934', |
|
187 | + 'TND' => '788', |
|
188 | + 'TOP' => '776', |
|
189 | + 'TPE' => '626', |
|
190 | + 'TRL' => '792', |
|
191 | + 'TRY' => '949', |
|
192 | + 'TTD' => '780', |
|
193 | + 'TWD' => '901', |
|
194 | + 'TZS' => '834', |
|
195 | + 'UAH' => '980', |
|
196 | + 'UGX' => '800', |
|
197 | + 'USD' => '840', |
|
198 | + 'USN' => '997', |
|
199 | + 'UYI' => '940', |
|
200 | + 'UYU' => '858', |
|
201 | + 'UZS' => '860', |
|
202 | + 'VEB' => '862', |
|
203 | + 'VEF' => '937', |
|
204 | + 'VND' => '704', |
|
205 | + 'VUV' => '548', |
|
206 | + 'WST' => '882', |
|
207 | + 'XAF' => '950', |
|
208 | + 'XCD' => '951', |
|
209 | + 'XOF' => '952', |
|
210 | + 'XPF' => '953', |
|
211 | + 'XXX' => '999', |
|
212 | + 'YER' => '886', |
|
213 | + 'YUM' => '891', |
|
214 | + 'ZAR' => '710', |
|
215 | + 'ZMK' => '894', |
|
216 | + 'ZMW' => '967', |
|
217 | + 'ZWD' => '716', |
|
218 | + 'ZWL' => '932', |
|
219 | 219 | ); |
220 | 220 | |
221 | 221 | $this->instances = array( |
222 | - 'STAG' => 'centineltest.cardinalcommerce.com', |
|
223 | - 'CYBERSOURCE' => 'cybersource.cardinalcommerce.com', |
|
224 | - 'FIRSTDATA' => 'production.altpayfirstdata.com', |
|
225 | - 'FIRSTDATA_TEST' => 'test.altpayfirstdata.com', |
|
226 | - 'PAYMENTECH' => 'paymentech.cardinalcommerce.com', |
|
227 | - 'PAYPAL' => 'paypal.cardinalcommerce.com', |
|
228 | - '200' => 'centinel.cardinalcommerce.com', |
|
229 | - '300' => 'centinel300.cardinalcommerce.com', |
|
230 | - '400' => 'centinel400.cardinalcommerce.com', |
|
231 | - 'PROD' => 'centinel600.cardinalcommerce.com', |
|
232 | - '800' => 'centinel800.cardinalcommerce.com', |
|
233 | - '1000' => 'centinel1000.cardinalcommerce.com', |
|
234 | - '1200' => 'centinel1200.cardinalcommerce.com', |
|
222 | + 'STAG' => 'centineltest.cardinalcommerce.com', |
|
223 | + 'CYBERSOURCE' => 'cybersource.cardinalcommerce.com', |
|
224 | + 'FIRSTDATA' => 'production.altpayfirstdata.com', |
|
225 | + 'FIRSTDATA_TEST' => 'test.altpayfirstdata.com', |
|
226 | + 'PAYMENTECH' => 'paymentech.cardinalcommerce.com', |
|
227 | + 'PAYPAL' => 'paypal.cardinalcommerce.com', |
|
228 | + '200' => 'centinel.cardinalcommerce.com', |
|
229 | + '300' => 'centinel300.cardinalcommerce.com', |
|
230 | + '400' => 'centinel400.cardinalcommerce.com', |
|
231 | + 'PROD' => 'centinel600.cardinalcommerce.com', |
|
232 | + '800' => 'centinel800.cardinalcommerce.com', |
|
233 | + '1000' => 'centinel1000.cardinalcommerce.com', |
|
234 | + '1200' => 'centinel1200.cardinalcommerce.com', |
|
235 | 235 | ); |
236 | 236 | |
237 | - add_filter( 'wp_enqueue_scripts', array($this, 'register_scripts') ); |
|
238 | - add_filter( 'wpinv_purchase_form_before_submit', array($this, 'purchase_form_before_submit') ); |
|
237 | + add_filter( 'wp_enqueue_scripts', array($this, 'register_scripts') ); |
|
238 | + add_filter( 'wpinv_purchase_form_before_submit', array($this, 'purchase_form_before_submit') ); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | wp_register_script( |
251 | 251 | 'cardinalcommerce-oneconnect', WPINV_PLUGIN_URL.'assets/js/cardinalcommerce-oneconnect.js', |
252 | 252 | array('jquery', 'cardinalcommerce-oneconnect-songbird'), |
253 | - WPINV_VERSION, true); |
|
253 | + WPINV_VERSION, true); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | private static function base64_encode_urlsafe($source) { |
@@ -323,10 +323,10 @@ discard block |
||
323 | 323 | |
324 | 324 | public function purchase_form_before_submit() { |
325 | 325 | wp_enqueue_script('cardinalcommerce-oneconnect'); |
326 | - $invoice = wpinv_get_invoice_cart(); |
|
327 | - $jwt = $this->generate_cruise_jwt($invoice); |
|
328 | - $this->hidden_input('CardinalOneConnectJWT', $jwt); |
|
329 | - $this->hidden_input('CardinalOneConnectLoggingLevel','verbose'); |
|
326 | + $invoice = wpinv_get_invoice_cart(); |
|
327 | + $jwt = $this->generate_cruise_jwt($invoice); |
|
328 | + $this->hidden_input('CardinalOneConnectJWT', $jwt); |
|
329 | + $this->hidden_input('CardinalOneConnectLoggingLevel','verbose'); |
|
330 | 330 | |
331 | 331 | $id = 'CardinalOneConnectResult'; |
332 | 332 | $merchant_content = 'Consumer Messaging'; |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | |
425 | 425 | public function reject_with_error($message, $permanent = false) { |
426 | 426 | wpinv_set_error('wpinv_error', "{$this->method_title}: {$message}"); |
427 | - wpinv_send_back_to_checkout( '?payment-mode=paypalpro' ); |
|
427 | + wpinv_send_back_to_checkout( '?payment-mode=paypalpro' ); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | public function order_add($invoice, $key, $value) { |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | } |
438 | 438 | |
439 | 439 | public function status_message($invoice, $message, $amount = null, |
440 | - $error = null) { |
|
440 | + $error = null) { |
|
441 | 441 | if (!$amount) { |
442 | 442 | $amount = $invoice->get_total(); |
443 | 443 | } |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | } |
451 | 451 | |
452 | 452 | public function process_payment( $invoice_id ) { |
453 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
453 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
454 | 454 | |
455 | 455 | $cruise_result_json = $_POST['CardinalOneConnectResult']; |
456 | 456 | if ( ! $cruise_result_json ) { |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | $this->reject_with_error('data and Payload ActionCode do not match'); |
501 | 501 | } |
502 | 502 | |
503 | - $invoiceid = $payload->AuthorizationProcessor->ProcessorOrderId; |
|
503 | + $invoiceid = $payload->AuthorizationProcessor->ProcessorOrderId; |
|
504 | 504 | $cca = $payload->Payment->ExtendedData; |
505 | 505 | $eci = isset($cca->ECIFlag) ? $cca->ECIFlag : ''; |
506 | 506 | $cavv = isset($cca->CAVV) ? $cca->CAVV : ''; |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | |
621 | 621 | public function create_request_order_object($invoice) { |
622 | 622 | $currency = $invoice->get_currency(); |
623 | - $currency_alpha = $this->currencies[$currency]; |
|
623 | + $currency_alpha = $this->currencies[$currency]; |
|
624 | 624 | $raw_amount = self::raw_amount($invoice->get_total(), $currency_alpha); |
625 | 625 | |
626 | 626 | $request_order_object = array( |