PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / trunk
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts vtrunk
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
← All changes | includes/class.helpers.php +170 -211 2.4.5trunk View file →
@@ -1,11 +1,9 @@
1 1 <?php
2 2 /**
3 3 * Helpers tools
4 4 *
5 - * @author Webcraftic <wordpress.webraftic@gmail.com>
6 - * @copyright (c) 09.11.2017, Webcraftic
7 - * @version 1.0
5 + * @package Woody_Code_Snippets
8 6 */
9 7
10 8 // Exit if accessed directly
11 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -16,14 +14,35 @@
16 14
17 15 private static $meta_options = [];
18 16
19 17 /**
18 + * Get initialized WordPress filesystem instance.
19 + *
20 + * @return WP_Filesystem_Base|false
21 + */
22 + public static function get_wp_filesystem() {
23 + global $wp_filesystem;
24 +
25 + if ( ! function_exists( 'WP_Filesystem' ) ) {
26 + require_once ABSPATH . 'wp-admin/includes/file.php';
27 + }
28 +
29 + WP_Filesystem();
30 +
31 + if ( ! ( $wp_filesystem instanceof WP_Filesystem_Base ) ) {
32 + return false;
33 + }
34 +
35 + return $wp_filesystem;
36 + }
37 +
38 + /**
20 39 * @return bool
21 40 */
22 41 public static function is_safe_mode() {
23 42 global $wbcr_inp_safe_mode;
24 43
25 - if ( ! WINP_Plugin::app()->currentUserCan() ) {
44 + if ( ! current_user_can( 'manage_options' ) ) {
26 45 return false;
27 46 }
28 47
29 48 if ( $wbcr_inp_safe_mode || isset( $_COOKIE['wbcr-php-snippets-safe-mode'] ) ) {
@@ -38,15 +57,15 @@
38 57 */
39 58 public static function enable_safe_mode() {
40 59 global $wbcr_inp_safe_mode;
41 60
42 - if ( ! WINP_Plugin::app()->currentUserCan() ) {
61 + if ( ! current_user_can( 'manage_options' ) ) {
43 62 return false;
44 63 }
45 64
46 65 if ( ( ! $wbcr_inp_safe_mode || ! isset( $_COOKIE['wbcr-php-snippets-safe-mode'] ) ) ) {
47 66 $wbcr_inp_safe_mode = true;
48 - setcookie( "wbcr-php-snippets-safe-mode", 1, time() + 3600, '/' );
67 + setcookie( 'wbcr-php-snippets-safe-mode', 1, time() + 3600, '/' );
49 68
50 69 return true;
51 70 }
52 71
@@ -58,9 +77,9 @@
58 77 */
59 78 public static function disable_safe_mode() {
60 79 global $wbcr_inp_safe_mode;
61 80
62 - if ( ! WINP_Plugin::app()->currentUserCan() ) {
81 + if ( ! current_user_can( 'manage_options' ) ) {
63 82 return false;
64 83 }
65 84
66 85 if ( $wbcr_inp_safe_mode || isset( $_COOKIE['wbcr-php-snippets-safe-mode'] ) ) {
@@ -77,27 +96,8 @@
77 96 return false;
78 97 }
79 98
80 99 /**
81 - * Should show a page about the plugin or not.
82 - *
83 - * @return bool
84 - */
85 - public static function is_need_show_about_page() {
86 - $need_show_about = (int) get_option( WINP_Plugin::app()->getOptionName( 'what_new_210' ) );
87 -
88 - $is_ajax = WINP_Helper::doing_ajax();
89 - $is_cron = WINP_Helper::doing_cron();
90 - $is_rest = WINP_Helper::doing_rest_api();
91 -
92 - if ( $need_show_about && ! $is_ajax && ! $is_cron && ! $is_rest ) {
93 - return true;
94 - }
95 -
96 - return false;
97 - }
98 -
99 - /**
100 100 * Gets and verified available attributes for snippets shortcodes.
101 101 *
102 102 * @param bool $tinymce
103 103 *
@@ -104,24 +104,26 @@
104 104 * @return mixed|void
105 105 */
106 106 public static function get_shortcode_data( $tinymce = false ) {
107 107
108 - $snippets = get_posts( [
109 - 'post_type' => WINP_SNIPPETS_POST_TYPE,
110 - 'meta_query' => [
111 - 'relation' => 'AND',
112 - [
113 - 'key' => WINP_Plugin::app()->getPrefix() . 'snippet_scope',
114 - 'value' => 'shortcode'
108 + $snippets = get_posts(
109 + [
110 + 'post_type' => WINP_SNIPPETS_POST_TYPE,
111 + 'meta_query' => [
112 + 'relation' => 'AND',
113 + [
114 + 'key' => 'wbcr_inp_snippet_scope',
115 + 'value' => 'shortcode',
116 + ],
117 + [
118 + 'key' => 'wbcr_inp_snippet_activate',
119 + 'value' => 1,
120 + ],
115 121 ],
116 - [
117 - 'key' => WINP_Plugin::app()->getPrefix() . 'snippet_activate',
118 - 'value' => 1
119 - ]
120 - ],
121 - 'post_status' => 'publish',
122 - 'numberposts' => - 1
123 - ] );
122 + 'post_status' => 'publish',
123 + 'numberposts' => - 1,
124 + ]
125 + );
124 126
125 127 $result = [];
126 128
127 129 if ( ! empty( $snippets ) ) {
@@ -126,22 +128,20 @@
126 128
127 129 if ( ! empty( $snippets ) ) {
128 130 foreach ( (array) $snippets as $snippet ) {
129 131 $tag_names = [ 'id' ];
130 - $snippet_type = WINP_Helper::get_snippet_type( $snippet->ID );
132 + $snippet_type = self::get_snippet_type( $snippet->ID );
131 133
132 - $available_tags = WINP_Helper::getMetaOption( $snippet->ID, 'snippet_tags' );
133 - $available_tags = trim( rtrim( $available_tags ) );
134 + $available_tags = self::getMetaOption( $snippet->ID, 'snippet_tags' );
135 + $available_tags = ! empty( $available_tags ) ? trim( rtrim( $available_tags ) ) : '';
134 136
135 137 if ( ! empty( $available_tags ) ) {
136 138 $available_tags = array_map( 'trim', explode( ',', $available_tags ) );
137 139 $available_tags = array_unique( $available_tags );
140 + } elseif ( $snippet_type !== 'text' && $snippet_type !== 'advert' ) {
141 + $available_tags = [ 'id', 'title' ];
138 142 } else {
139 - if ( $snippet_type !== 'text' && $snippet_type !== 'advert' ) {
140 - $available_tags = [ 'id', 'title' ];
141 - } else {
142 - $available_tags = [ 'id' ];
143 - }
143 + $available_tags = [ 'id' ];
144 144 }
145 145
146 146 $tags = [
147 147 'id' => $snippet->ID,
@@ -146,9 +146,9 @@
146 146 $tags = [
147 147 'id' => $snippet->ID,
148 148 'type' => $snippet_type,
149 149 'name' => $snippet_type == WINP_SNIPPET_TYPE_UNIVERSAL ? 'wbcr_snippet' : 'wbcr_' . $snippet_type . '_snippet',
150 - 'title' => empty( $snippet->post_title ) ? '(no titled, ID=' . $snippet->ID . ')' : $snippet->post_title
150 + 'title' => empty( $snippet->post_title ) ? '(no titled, ID=' . $snippet->ID . ')' : $snippet->post_title,
151 151 ];
152 152
153 153 if ( ! empty( $available_tags ) ) {
154 154 foreach ( (array) $available_tags as $tag ) {
@@ -155,11 +155,11 @@
155 155 if ( '' != $tag ) {
156 156 if ( 'title' == $tag ) {
157 157 $tags['title'] = empty( $snippet->post_title ) ? '(no titled, ID=' . $snippet->ID . ')' : $snippet->post_title;
158 158 $tag_names[] = 'title';
159 - } else if ( 'id' != $tag ) {
159 + } elseif ( 'id' != $tag ) {
160 160 $tag = preg_replace( '/[^a-zA-Z0-9_\x7f-\xff]/', '', $tag );
161 - $tags[ $tag ] = "";
161 + $tags[ $tag ] = '';
162 162 $tag_names[] = $tag;
163 163 }
164 164 }
165 165 }
@@ -176,11 +176,11 @@
176 176
177 177 /**
178 178 * Get snippet type
179 179 *
180 - * @param null $post_id
180 + * @param mixed $post_id Post ID.
181 181 *
182 - * @return array|mixed|string
182 + * @return string|false Snippet type string, or false if post is not a valid snippet post type or not found.
183 183 */
184 184 public static function get_snippet_type( $post_id = null ) {
185 185 global $post;
186 186
@@ -185,10 +185,10 @@
185 185 global $post;
186 186
187 187 $_post = $post;
188 188
189 - $snippet_type = WINP_Plugin::app()->request->get( 'winp_item', WINP_SNIPPET_TYPE_PHP, 'sanitize_key' );
190 - $get_post = WINP_Plugin::app()->request->get( 'post', '' );
189 + $snippet_type = WINP_HTTP::get( 'winp_item', WINP_SNIPPET_TYPE_PHP, 'sanitize_key' );
190 + $get_post = WINP_HTTP::get( 'post', '' );
191 191
192 192 if ( empty( $post_id ) && ! empty( $get_post ) && ! is_array( $get_post ) ) {
193 193 $post_id = esc_attr( $get_post );
194 194 }
@@ -194,12 +194,18 @@
194 194 }
195 195
196 196 if ( ! empty( $post_id ) ) {
197 197 $_post = get_post( $post_id );
198 +
199 + // Security: Validate that the post belongs to the snippet post type
200 + // to prevent arbitrary post content execution via shortcodes.
201 + if ( empty( $_post ) || WINP_SNIPPETS_POST_TYPE !== $_post->post_type ) {
202 + return false;
203 + }
198 204 }
199 205
200 206 if ( ! empty( $_post ) && WINP_SNIPPETS_POST_TYPE === $_post->post_type ) {
201 - $_snippet_type = get_post_meta( $_post->ID, WINP_Plugin::app()->getPrefix() . 'snippet_type', true );
207 + $_snippet_type = get_post_meta( $_post->ID, 'wbcr_inp_snippet_type', true );
202 208 $snippet_type = $_snippet_type ? $_snippet_type : $snippet_type;
203 209 }
204 210
205 211 return $snippet_type;
@@ -218,19 +224,23 @@
218 224 * @return boolean
219 225 */
220 226 public static function doing_rest_api() {
221 227 $prefix = rest_get_url_prefix();
222 - $rest_route = WINP_Plugin::app()->request->get( 'rest_route', null );
228 + $rest_route = WINP_HTTP::get( 'rest_route', null );
223 229 if ( defined( 'REST_REQUEST' ) && REST_REQUEST // (#1)
224 - || ! is_null( $rest_route ) // (#2)
225 - && strpos( trim( $rest_route, '\\/' ), $prefix, 0 ) === 0 ) {
230 + || ! is_null( $rest_route ) // (#2)
231 + && strpos( trim( $rest_route, '\\/' ), $prefix, 0 ) === 0 ) {
226 232 return true;
227 233 }
228 234
229 235 // (#3)
230 236 $rest_url = wp_parse_url( site_url( $prefix ) );
231 - $current_url = wp_parse_url( add_query_arg( [] ) );
237 + $current_url = wp_parse_url( esc_url( add_query_arg( [] ) ) );
232 238
239 + if ( empty( $rest_url['path'] ) || empty( $current_url['path'] ) ) {
240 + return false;
241 + }
242 +
233 243 return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
234 244 }
235 245
236 246 /**
@@ -266,15 +276,13 @@
266 276 *
267 277 * @param WP_Post $post
268 278 *
269 279 * @return string snippet code
270 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
271 280 * @since 2.2.1
272 - *
273 281 */
274 282 public static function get_snippet_code( $post ) {
275 283 if ( empty( $post->post_content ) ) {
276 - return WINP_Helper::getMetaOption( $post->ID, 'snippet_code' );
284 + return self::getMetaOption( $post->ID, 'snippet_code' );
277 285 }
278 286
279 287 return $post->post_content;
280 288 }
@@ -281,11 +289,11 @@
281 289
282 290 /**
283 291 * Get meta option
284 292 *
285 - * @param int $post_id
293 + * @param int $post_id
286 294 * @param string $option_name
287 - * @param mixed $default
295 + * @param mixed $default
288 296 *
289 297 * @return mixed|array
290 298 */
291 299 public static function getMetaOption( $post_id, $option_name, $default = null ) {
@@ -300,17 +308,17 @@
300 308 }
301 309 }
302 310 }
303 311
304 - return isset( self::$meta_options[ $post_id ][ WINP_Plugin::app()->getPrefix() . $option_name ] ) ? self::$meta_options[ $post_id ][ WINP_Plugin::app()->getPrefix() . $option_name ] : $default;
312 + return isset( self::$meta_options[ $post_id ][ 'wbcr_inp_' . $option_name ] ) ? self::$meta_options[ $post_id ][ 'wbcr_inp_' . $option_name ] : $default;
305 313 }
306 314
307 315 /**
308 316 * Udpdate meta option
309 317 *
310 - * @param int $post_id
318 + * @param int $post_id
311 319 * @param string $option_name
312 - * @param mixed $option_value
320 + * @param mixed $option_value
313 321 *
314 322 * @return bool|int
315 323 */
316 324 public static function updateMetaOption( $post_id, $option_name, $option_value ) {
@@ -315,29 +323,14 @@
315 323 */
316 324 public static function updateMetaOption( $post_id, $option_name, $option_value ) {
317 325 $post_id = (int) $post_id;
318 326
319 - return update_post_meta( $post_id, WINP_Plugin::app()->getPrefix() . $option_name, $option_value );
327 + return update_post_meta( $post_id, 'wbcr_inp_' . $option_name, $option_value );
320 328 }
321 329
322 330 /**
323 - * Remove meta option
324 - *
325 - * @param int $post_id
326 - * @param string $option_name
327 - *
328 - * @return bool|int
329 - */
330 - public static function removeMetaOption( $post_id, $option_name ) {
331 - $post_id = (int) $post_id;
332 -
333 - return delete_post_meta( $post_id, WINP_Plugin::app()->getPrefix() . $option_name );
334 - }
335 -
336 - /**
337 331 * Check capabilities for snippets post type.
338 332 *
339 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
340 333 * @since 2.2.0
341 334 */
342 335 public static function has_post_capabilities() {
343 336 $role = get_role( 'administrator' );
@@ -351,9 +344,8 @@
351 344
352 345 /**
353 346 * Set capabilities for snippets post type.
354 347 *
355 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
356 348 * @since 2.2.0
357 349 */
358 350 public static function set_post_capabilities() {
359 351 $role = get_role( 'administrator' );
@@ -377,18 +369,18 @@
377 369 * Create a demo snippets with examples of use
378 370 */
379 371 public static function create_demo_snippets() {
380 372
381 - update_option( WINP_Plugin::app()->getOptionName( 'activate_by_default' ), 1 );
382 - update_option( WINP_Plugin::app()->getOptionName( 'complete_uninstall' ), 0 );
383 - update_option( WINP_Plugin::app()->getOptionName( 'code_editor_theme' ), 'default' );
384 - update_option( WINP_Plugin::app()->getOptionName( 'code_editor_indent_with_tabs' ), 1 );
385 - update_option( WINP_Plugin::app()->getOptionName( 'code_editor_tab_size' ), 4 );
386 - update_option( WINP_Plugin::app()->getOptionName( 'code_editor_indent_unit' ), 4 );
387 - update_option( WINP_Plugin::app()->getOptionName( 'code_editor_wrap_lines' ), 1 );
388 - update_option( WINP_Plugin::app()->getOptionName( 'code_editor_line_numbers' ), 1 );
389 - update_option( WINP_Plugin::app()->getOptionName( 'code_editor_auto_close_brackets' ), 1 );
390 - update_option( WINP_Plugin::app()->getOptionName( 'code_editor_highlight_selection_matches' ), 0 );
373 + update_option( 'wbcr_inp_activate_by_default', 1 );
374 + update_option( 'wbcr_inp_complete_uninstall', 0 );
375 + update_option( 'wbcr_inp_code_editor_theme', 'default' );
376 + update_option( 'wbcr_inp_code_editor_indent_with_tabs', 1 );
377 + update_option( 'wbcr_inp_code_editor_tab_size', 4 );
378 + update_option( 'wbcr_inp_code_editor_indent_unit', 4 );
379 + update_option( 'wbcr_inp_code_editor_wrap_lines', 1 );
380 + update_option( 'wbcr_inp_code_editor_line_numbers', 1 );
381 + update_option( 'wbcr_inp_code_editor_auto_close_brackets', 1 );
382 + update_option( 'wbcr_inp_code_editor_highlight_selection_matches', 0 );
391 383
392 384 $posts = [
393 385 [
394 386 'post_title' => __( 'Simple universal snippet: Google analytics tracking', 'insert-php' ),
@@ -395,13 +387,13 @@
395 387 'post_name' => 'simple-universal-snippet',
396 388 'post_content' => self::get_simple_universal_snippet(),
397 389 'meta' => [
398 390 'type' => WINP_SNIPPET_TYPE_UNIVERSAL,
399 - 'description' => __( 'Google analytics tracking code will be added to all pages before the &lt;/head&gt; tag. Please remember to set the Tracking ID before activating the snippet.' ),
391 + 'description' => __( 'Google analytics tracking code will be added to all pages before the &lt;/head&gt; tag. Please remember to set the Tracking ID before activating the snippet.', 'insert-php' ),
400 392 'filters' => 'a:1:{i:0;O:8:"stdClass":2:{s:10:"conditions";a:1:{i:0;O:8:"stdClass":2:{s:4:"type";s:5:"scope";s:10:"conditions";a:1:{i:0;O:8:"stdClass":4:{s:5:"param";s:18:"location-some-page";s:8:"operator";s:6:"equals";s:4:"type";s:6:"select";s:5:"value";s:8:"base_web";}}}}s:4:"type";s:6:"showif";}}',
401 393 'tags' => [ 'universal', 'tracking' ],
402 - 'priority' => 10
403 - ]
394 + 'priority' => 10,
395 + ],
404 396 ],
405 397 [
406 398 'post_title' => __( 'Simple text snippet: What is Lorem Ipsum?', 'insert-php' ),
407 399 'post_name' => 'simple-text-snippet',
@@ -407,13 +399,13 @@
407 399 'post_name' => 'simple-text-snippet',
408 400 'post_content' => self::get_simple_text_snippet(),
409 401 'meta' => [
410 402 'type' => WINP_SNIPPET_TYPE_TEXT,
411 - 'description' => __( 'This ordinary maintenance text. With this snippet, you can fill your pages with meaningless English text.', 'insert-php' ),
403 + 'description' => __( 'This is ordinary maintenance text. With this snippet, you can fill your pages with meaningless English text.', 'insert-php' ),
412 404 'filters' => 'a:1:{i:0;O:8:"stdClass":2:{s:10:"conditions";a:2:{i:0;O:8:"stdClass":2:{s:4:"type";s:5:"scope";s:10:"conditions";a:1:{i:0;O:8:"stdClass":4:{s:5:"param";s:18:"location-some-page";s:8:"operator";s:6:"equals";s:4:"type";s:6:"select";s:5:"value";s:9:"base_sing";}}}i:1;O:8:"stdClass":2:{s:4:"type";s:5:"scope";s:10:"conditions";a:2:{i:0;O:8:"stdClass":4:{s:5:"param";s:18:"location-post-type";s:8:"operator";s:6:"equals";s:4:"type";s:6:"select";s:5:"value";s:4:"post";}i:1;O:8:"stdClass":4:{s:5:"param";s:18:"location-post-type";s:8:"operator";s:6:"equals";s:4:"type";s:6:"select";s:5:"value";s:4:"page";}}}}s:4:"type";s:6:"showif";}}',
413 405 'tags' => [ 'text', 'lorem ipsum' ],
414 - 'priority' => 20
415 - ]
406 + 'priority' => 20,
407 + ],
416 408 ],
417 409 [
418 410 'post_title' => __( 'Simple php snippet: Disable emojis', 'insert-php' ),
419 411 'post_name' => 'simple-php-snippet',
@@ -419,12 +411,12 @@
419 411 'post_name' => 'simple-php-snippet',
420 412 'post_content' => self::get_simple_php_snippet(),
421 413 'meta' => [
422 414 'type' => WINP_SNIPPET_TYPE_PHP,
423 - 'description' => __( 'Emojis are little icons used to express ideas or emotions. While these icons are fun and all, are they really necessary for your WordPress site? This snippet to disable emojis on your site to make it faster.', 'insert-php' ),
415 + 'description' => __( 'Emojis are little icons used to express ideas or emotions. While these icons are useful, they may not be necessary for your WordPress site. Use this snippet to disable emojis on your site and make it faster.', 'insert-php' ),
424 416 'tags' => [ 'php', 'disable features' ],
425 - 'priority' => 30
426 - ]
417 + 'priority' => 30,
418 + ],
427 419 ],
428 420 [
429 421 'post_title' => __( 'Add Facebook Pixel to the Order success page', 'insert-php' ),
430 422 'post_name' => 'simple-uni-snippet-for-woocommerce',
@@ -433,46 +425,48 @@
433 425 'type' => WINP_SNIPPET_TYPE_UNIVERSAL,
434 426 'description' => __( 'Add Facebook Pixel to the Order success page.', 'insert-php' ),
435 427 'filters' => 'a:1:{i:0;O:8:"stdClass":2:{s:10:"conditions";a:1:{i:0;O:8:"stdClass":2:{s:4:"type";s:5:"scope";s:10:"conditions";a:1:{i:0;O:8:"stdClass":4:{s:5:"param";s:18:"location-some-page";s:8:"operator";s:6:"equals";s:4:"type";s:6:"select";s:5:"value";s:16:"woo_checkout_pay";}}}}s:4:"type";s:6:"showif";}}',
436 428 'tags' => [ 'woocommerce' ],
437 - 'priority' => 40
438 - ]
429 + 'priority' => 40,
430 + ],
439 431 ],
440 432 ];
441 433
442 434 foreach ( $posts as $post ) {
443 435 // '@' here is to hide unexpected output while plugin activation
444 - $post_id = @wp_insert_post( [
445 - 'post_content' => $post['post_content'],
446 - 'post_title' => $post['post_title'],
447 - 'post_status' => 'publish',
448 - 'post_type' => WINP_SNIPPETS_POST_TYPE
449 - ] );
436 + $post_id = @wp_insert_post(
437 + [
438 + 'post_content' => $post['post_content'],
439 + 'post_title' => $post['post_title'],
440 + 'post_status' => 'publish',
441 + 'post_type' => WINP_SNIPPETS_POST_TYPE,
442 + ]
443 + );
450 444
451 445 if ( ! is_wp_error( $post_id ) ) {
452 446 if ( isset( $post['meta']['type'] ) ) {
453 - WINP_Helper::updateMetaOption( $post_id, 'snippet_type', $post['meta']['type'] );
447 + self::updateMetaOption( $post_id, 'snippet_type', $post['meta']['type'] );
454 448
455 449 if ( $post['meta']['type'] == WINP_SNIPPET_TYPE_PHP ) {
456 - WINP_Helper::updateMetaOption( $post_id, 'snippet_scope', 'evrywhere' );
450 + self::updateMetaOption( $post_id, 'snippet_scope', 'evrywhere' );
457 451 }
458 452 if ( $post['meta']['type'] == WINP_SNIPPET_TYPE_TEXT ) {
459 - WINP_Helper::updateMetaOption( $post_id, 'snippet_scope', 'shortcode' );
453 + self::updateMetaOption( $post_id, 'snippet_scope', 'shortcode' );
460 454 }
461 455 if ( $post['meta']['type'] == WINP_SNIPPET_TYPE_UNIVERSAL ) {
462 - WINP_Helper::updateMetaOption( $post_id, 'snippet_scope', 'auto' );
463 - WINP_Helper::updateMetaOption( $post_id, 'snippet_location', 'header' );
456 + self::updateMetaOption( $post_id, 'snippet_scope', 'auto' );
457 + self::updateMetaOption( $post_id, 'snippet_location', 'header' );
464 458 }
465 459 }
466 460
467 461 if ( isset( $post['meta']['description'] ) ) {
468 - WINP_Helper::updateMetaOption( $post_id, 'snippet_description', $post['meta']['description'] );
462 + self::updateMetaOption( $post_id, 'snippet_description', $post['meta']['description'] );
469 463 }
470 464
471 465 if ( isset( $post['meta']['filters'] ) && is_serialized( $post['meta']['filters'] ) ) {
472 466 $unserialized_filters = unserialize( $post['meta']['filters'] );
473 - WINP_Helper::updateMetaOption( $post_id, 'snippet_filters', $unserialized_filters );
474 - WINP_Helper::updateMetaOption( $post_id, 'changed_filters', 1 );
467 + self::updateMetaOption( $post_id, 'snippet_filters', $unserialized_filters );
468 + self::updateMetaOption( $post_id, 'changed_filters', 1 );
475 469 }
476 470
477 471 if ( isset( $post['meta']['tags'] ) && ! empty( $post['meta']['tags'] ) ) {
478 472 if ( ! taxonomy_exists( WINP_SNIPPETS_TAXONOMY ) ) {
@@ -482,14 +476,14 @@
482 476 wp_set_post_terms( $post_id, $post['meta']['tags'], WINP_SNIPPETS_TAXONOMY, true );
483 477 }
484 478
485 479 if ( isset( $post['meta']['priority'] ) ) {
486 - WINP_Helper::updateMetaOption( $post_id, 'snippet_priority', $post['meta']['priority'] );
480 + self::updateMetaOption( $post_id, 'snippet_priority', $post['meta']['priority'] );
487 481 }
488 482 }
489 483 }
490 484
491 - update_option( WINP_Plugin::app()->getOptionName( 'demo_snippets_created' ), 1 );
485 + update_option( 'wbcr_inp_demo_snippets_created', 1 );
492 486 }
493 487
494 488 /**
495 489 * Returns an example php snippet content
@@ -496,12 +490,12 @@
496 490 *
497 491 * @return string
498 492 */
499 493 protected static function get_simple_php_snippet() {
500 - $output = "/**" . PHP_EOL;
501 - $output .= "* Disable WP 4.2 emoji" . PHP_EOL;
502 - $output .= "*/" . PHP_EOL;
503 - $output .= "function ace_remove_emoji() {" . PHP_EOL;
494 + $output = '/**' . PHP_EOL;
495 + $output .= '* Disable WP 4.2 emoji' . PHP_EOL;
496 + $output .= '*/' . PHP_EOL;
497 + $output .= 'function ace_remove_emoji() {' . PHP_EOL;
504 498 $output .= "\tadd_filter( 'emoji_svg_url', '__return_false' );" . PHP_EOL;
505 499 $output .= "\tremove_action( 'admin_print_styles', 'print_emoji_styles' );" . PHP_EOL;
506 500 $output .= "\tremove_action( 'wp_head', 'print_emoji_detection_script', 7 );" . PHP_EOL;
507 501 $output .= "\tremove_action( 'admin_print_scripts', 'print_emoji_detection_script' );" . PHP_EOL;
@@ -510,17 +504,17 @@
510 504 $output .= "\tremove_filter( 'the_content_feed', 'wp_staticize_emoji' );" . PHP_EOL;
511 505 $output .= "\tremove_filter( 'comment_text_rss', 'wp_staticize_emoji' );" . PHP_EOL;
512 506 $output .= "\t// filter to remove TinyMCE emojis" . PHP_EOL;
513 507 $output .= "\tadd_filter( 'tiny_mce_plugins', 'ace_disable_emoji_tinymce' );" . PHP_EOL;
514 - $output .= "}" . PHP_EOL;
508 + $output .= '}' . PHP_EOL;
515 509 $output .= "add_action( 'init', 'ace_remove_emoji' );" . PHP_EOL;
516 - $output .= "/**" . PHP_EOL;
517 - $output .= "* Remove tinyMCE emoji" . PHP_EOL;
518 - $output .= "*/" . PHP_EOL;
519 - $output .= "function ace_disable_emoji_tinymce( \$plugins ) {" . PHP_EOL;
510 + $output .= '/**' . PHP_EOL;
511 + $output .= '* Remove tinyMCE emoji' . PHP_EOL;
512 + $output .= '*/' . PHP_EOL;
513 + $output .= 'function ace_disable_emoji_tinymce( $plugins ) {' . PHP_EOL;
520 514 $output .= "\tunset( \$plugins['wpemoji'] );" . PHP_EOL;
521 515 $output .= "\treturn \$plugins;" . PHP_EOL;
522 - $output .= "}" . PHP_EOL;
516 + $output .= '}' . PHP_EOL;
523 517
524 518 return $output;
525 519 }
526 520
@@ -529,10 +523,10 @@
529 523 *
530 524 * @return string
531 525 */
532 526 protected static function get_simple_text_snippet() {
533 - $output = '<h3>What is Lorem Ipsum?</h3>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';
534 - $output .= PHP_EOL . "{{SNIPPET_CONTENT}}" . PHP_EOL;
527 + $output = '<h3>What is Lorem Ipsum?</h3>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';
528 + $output .= PHP_EOL . '{{SNIPPET_CONTENT}}' . PHP_EOL;
535 529
536 530 return $output;
537 531 }
538 532
@@ -541,17 +535,17 @@
541 535 *
542 536 * @return string
543 537 */
544 538 protected static function get_simple_universal_snippet() {
545 - $output = "<!-- Global Site Tag (gtag.js) - Google Analytics -->" . PHP_EOL;
546 - $output .= "<script async src=\"https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID\"></script>" . PHP_EOL;
547 - $output .= "<script>" . PHP_EOL;
539 + $output = '<!-- Global Site Tag (gtag.js) - Google Analytics -->' . PHP_EOL;
540 + $output .= '<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>' . PHP_EOL;
541 + $output .= '<script>' . PHP_EOL;
548 542 $output .= "\twindow.dataLayer = window.dataLayer || [];" . PHP_EOL;
549 543 $output .= "\tfunction gtag(){dataLayer.push(arguments);}" . PHP_EOL;
550 544 $output .= "\tgtag('js', new Date());" . PHP_EOL;
551 545 $output .= "\tgtag('config', 'GA_TRACKING_ID');" . PHP_EOL;
552 - $output .= "</script>" . PHP_EOL;
553 - $output .= "<!-- End global Site Tag (gtag.js) - Google Analytics -->" . PHP_EOL;
546 + $output .= '</script>' . PHP_EOL;
547 + $output .= '<!-- End global Site Tag (gtag.js) - Google Analytics -->' . PHP_EOL;
554 548
555 549 return $output;
556 550 }
557 551
@@ -560,9 +554,9 @@
560 554 *
561 555 * @return string
562 556 */
563 557 protected static function get_woo_snippet() {
564 - $output = <<<SCRIPT
558 + $output = <<<'SCRIPT'
565 559 <script type="text/javascript">
566 560 var pixel_id = ''; // Add you FB pixel ID!
567 561 !function (f, b, e, v, n, t, s) {
568 562 if (f.fbq) return; n = f.fbq = function () {
@@ -586,74 +580,39 @@
586 580 *
587 581 * @param $name
588 582 * @param $obj
589 583 */
590 - public static function register_shortcode( $name, $obj ) {
591 - Wbcr_FactoryShortcodes332::register( $name, $obj );
592 - }
593 -
594 584 /**
595 - * Wrapper for get factory class for container
585 + * Register a shortcode class
596 586 *
597 - * @return string
598 - */
599 - public static function get_factory_class() {
600 - return "factory-bootstrap-457 factory-fontawesome-000";
601 - }
602 -
603 - /**
604 - * Wrapper for Wbcr_FactoryForms453_OptionsValueProvider object
587 + * @param string $name Shortcode class name.
588 + * @param object $obj Plugin object.
605 589 *
606 - * @param $plugin
607 - *
608 - * @return Wbcr_FactoryForms453_OptionsValueProvider
590 + * @return void
609 591 */
610 - public static function get_options_value_provider( $plugin ) {
611 - return new Wbcr_FactoryForms453_OptionsValueProvider( $plugin );
592 + public static function register_shortcode( $name, $obj ) {
593 + if ( class_exists( $name ) ) {
594 + new $name( $obj );
595 + }
612 596 }
613 597
614 598 /**
615 - * Wrapper for get factory form object
616 - *
617 - * @param $options
618 - * @param $plugin
619 - *
620 - * @return Wbcr_FactoryForms453_Form
621 - */
622 - public static function get_factory_form( $options, $plugin ) {
623 - return new Wbcr_FactoryForms453_Form( $options, $plugin );
624 - }
625 -
626 - /**
627 - * Wrapper for register factory metaboxes
628 - *
629 - * @param $class_name_or_object
630 - * @param $post_type
631 - * @param $plugin
632 - */
633 - public static function register_factory_metaboxes( $class_name_or_object, $post_type, $plugin ) {
634 - Wbcr_FactoryMetaboxes412::registerFor( $class_name_or_object, $post_type, $plugin );
635 - }
636 -
637 - /**
638 599 * Render html for purchase button
639 600 */
640 601 public static function get_purchase_button( $utm_tracking_location = 'snippet-library-page' ) {
641 - $price_url = WINP_Plugin::app()->get_support()->get_pricing_url( true, $utm_tracking_location );
642 - $price = WINP_Plugin::app()->premium->get_price();
643 - $price = empty( $price ) ? 19 : $price;
602 + $price_url = tsdk_utmify( WINP_UPGRADE, 'upsell_button', $utm_tracking_location );
644 603 ?>
645 - <p class="winp-purchase-button">
646 - <a class="button" id="winp-library-buy-button" href="<?php echo esc_url( $price_url ) ?>" target="_blank">
647 - <span><?php echo __( 'Purchase premium for', 'insert-php' ) . ' $' . esc_attr( $price ); ?></span>
648 - </a>
649 - </p>
604 + <p class="winp-purchase-button">
605 + <a class="button" id="winp-library-buy-button" href="<?php echo esc_url( $price_url ); ?>" target="_blank">
606 + <span><?php _e( 'Upgrade to Pro', 'insert-php' ); ?></span>
607 + </a>
608 + </p>
650 609 <?php
651 610 }
652 611
653 612 /**
654 613 * Check if current user is admin or editor
655 - * todo: удалить этот метод, потому что он дублирует функционал WINP_Plugin::app()->currentUserCan
614 + * todo: удалить этот метод, потому что он дублирует функционал WINP_Plugin::app()->current_user_car
656 615 *
657 616 * @return bool
658 617 */
659 618 public static function winp_check_user_admin() {
@@ -660,12 +619,12 @@
660 619 return current_user_can( 'manage_options' ) || current_user_can( 'administrator' );
661 620 }
662 621
663 622 /*
664 - * Flushes as many page cache plugin's caches as possible.
665 - *
666 - * @return void
667 - */
623 + * Flushes as many page cache plugin's caches as possible.
624 + *
625 + * @return void
626 + */
668 627 public static function flush_page_cache() {
669 628 if ( function_exists( 'wp_cache_clear_cache' ) ) {
670 629 if ( is_multisite() ) {
671 630 $blog_id = get_current_blog_id();
@@ -672,24 +631,24 @@
672 631 wp_cache_clear_cache( $blog_id );
673 632 } else {
674 633 wp_cache_clear_cache();
675 634 }
676 - } else if ( has_action( 'cachify_flush_cache' ) ) {
635 + } elseif ( has_action( 'cachify_flush_cache' ) ) {
677 636 do_action( 'cachify_flush_cache' );
678 - } else if ( function_exists( 'w3tc_pgcache_flush' ) ) {
637 + } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) {
679 638 w3tc_pgcache_flush();
680 - } else if ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
639 + } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
681 640 wp_fast_cache_bulk_delete_all();
682 - } else if ( class_exists( 'WpFastestCache' ) ) {
641 + } elseif ( class_exists( 'WpFastestCache' ) ) {
683 642 $wpfc = new WpFastestCache();
684 643 $wpfc->deleteCache();
685 - } else if ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
644 + } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
686 645 c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache
687 - } else if ( class_exists( 'zencache' ) ) {
646 + } elseif ( class_exists( 'zencache' ) ) {
688 647 zencache::clear();
689 - } else if ( class_exists( 'comet_cache' ) ) {
648 + } elseif ( class_exists( 'comet_cache' ) ) {
690 649 comet_cache::clear();
691 - } else if ( class_exists( 'WpeCommon' ) ) {
650 + } elseif ( class_exists( 'WpeCommon' ) ) {
692 651 // WPEngine cache purge/flush methods to call by default
693 652 $wpe_methods = [
694 653 'purge_varnish_cache',
695 654 ];
@@ -706,11 +665,11 @@
706 665 if ( method_exists( 'WpeCommon', $wpe_method ) ) {
707 666 WpeCommon::$wpe_method();
708 667 }
709 668 }
710 - } else if ( function_exists( 'sg_cachepress_purge_cache' ) ) {
669 + } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) {
711 670 sg_cachepress_purge_cache();
712 - } else if ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
671 + } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
713 672 // fallback for WP-Super-Cache
714 673 global $cache_path;
715 674 if ( is_multisite() ) {
716 675 $blog_id = get_current_blog_id();
@@ -727,18 +686,17 @@
727 686 * @param $post WP_Post
728 687 *
729 688 * @return string
730 689 * @since 2.4.0
731 - *
732 690 */
733 691 public static function get_where_use_text( $post ) {
734 692 global $winp_snippets_locations;
735 693 $snippet_scope = self::getMetaOption( $post->ID, 'snippet_scope' );
736 - $result = "";
694 + $result = '';
737 695
738 696 if ( $snippet_scope == 'evrywhere' ) {
739 697 $result = __( 'Run everywhere', 'insert-php' );
740 - } else if ( $snippet_scope == 'auto' ) {
698 + } elseif ( $snippet_scope == 'auto' ) {
741 699 $items = $winp_snippets_locations->getList();
742 700
743 701 $snippet_location = self::getMetaOption( $post->ID, 'snippet_location', '' );
744 702
@@ -775,12 +733,14 @@
775 733 */
776 734 public static function get_next_snippet_priority() {
777 735 global $wpdb;
778 736
779 - $max_priority = $wpdb->get_var( "
737 + $max_priority = $wpdb->get_var(
738 + "
780 739 SELECT MAX(CAST(meta_value AS UNSIGNED))
781 740 FROM {$wpdb->postmeta}
782 - WHERE meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_priority'" );
741 + WHERE meta_key = 'wbcr_inp_snippet_priority'"
742 + );
783 743
784 744 if ( is_null( $max_priority ) ) {
785 745 $max_priority = 0;
786 746 } else {
@@ -797,6 +757,5 @@
797 757 */
798 758 public static function is_woo_active() {
799 759 return is_plugin_active( 'woocommerce/woocommerce.php' );
800 760 }
801 -
802 761 }