PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.1
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 +137 -209 2.4.42.7.1 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' ) ) {
@@ -21,9 +19,9 @@
21 19 */
22 20 public static function is_safe_mode() {
23 21 global $wbcr_inp_safe_mode;
24 22
25 - if ( ! WINP_Plugin::app()->currentUserCan() ) {
23 + if ( ! current_user_can( 'manage_options' ) ) {
26 24 return false;
27 25 }
28 26
29 27 if ( $wbcr_inp_safe_mode || isset( $_COOKIE['wbcr-php-snippets-safe-mode'] ) ) {
@@ -38,15 +36,15 @@
38 36 */
39 37 public static function enable_safe_mode() {
40 38 global $wbcr_inp_safe_mode;
41 39
42 - if ( ! WINP_Plugin::app()->currentUserCan() ) {
40 + if ( ! current_user_can( 'manage_options' ) ) {
43 41 return false;
44 42 }
45 43
46 44 if ( ( ! $wbcr_inp_safe_mode || ! isset( $_COOKIE['wbcr-php-snippets-safe-mode'] ) ) ) {
47 45 $wbcr_inp_safe_mode = true;
48 - setcookie( "wbcr-php-snippets-safe-mode", 1, time() + 3600, '/' );
46 + setcookie( 'wbcr-php-snippets-safe-mode', 1, time() + 3600, '/' );
49 47
50 48 return true;
51 49 }
52 50
@@ -58,9 +56,9 @@
58 56 */
59 57 public static function disable_safe_mode() {
60 58 global $wbcr_inp_safe_mode;
61 59
62 - if ( ! WINP_Plugin::app()->currentUserCan() ) {
60 + if ( ! current_user_can( 'manage_options' ) ) {
63 61 return false;
64 62 }
65 63
66 64 if ( $wbcr_inp_safe_mode || isset( $_COOKIE['wbcr-php-snippets-safe-mode'] ) ) {
@@ -77,27 +75,8 @@
77 75 return false;
78 76 }
79 77
80 78 /**
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 79 * Gets and verified available attributes for snippets shortcodes.
101 80 *
102 81 * @param bool $tinymce
103 82 *
@@ -104,24 +83,26 @@
104 83 * @return mixed|void
105 84 */
106 85 public static function get_shortcode_data( $tinymce = false ) {
107 86
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'
87 + $snippets = get_posts(
88 + [
89 + 'post_type' => WINP_SNIPPETS_POST_TYPE,
90 + 'meta_query' => [
91 + 'relation' => 'AND',
92 + [
93 + 'key' => 'wbcr_inp_snippet_scope',
94 + 'value' => 'shortcode',
95 + ],
96 + [
97 + 'key' => 'wbcr_inp_snippet_activate',
98 + 'value' => 1,
99 + ],
115 100 ],
116 - [
117 - 'key' => WINP_Plugin::app()->getPrefix() . 'snippet_activate',
118 - 'value' => 1
119 - ]
120 - ],
121 - 'post_status' => 'publish',
122 - 'numberposts' => - 1
123 - ] );
101 + 'post_status' => 'publish',
102 + 'numberposts' => - 1,
103 + ]
104 + );
124 105
125 106 $result = [];
126 107
127 108 if ( ! empty( $snippets ) ) {
@@ -126,22 +107,20 @@
126 107
127 108 if ( ! empty( $snippets ) ) {
128 109 foreach ( (array) $snippets as $snippet ) {
129 110 $tag_names = [ 'id' ];
130 - $snippet_type = WINP_Helper::get_snippet_type( $snippet->ID );
111 + $snippet_type = self::get_snippet_type( $snippet->ID );
131 112
132 - $available_tags = WINP_Helper::getMetaOption( $snippet->ID, 'snippet_tags' );
113 + $available_tags = self::getMetaOption( $snippet->ID, 'snippet_tags' );
133 114 $available_tags = trim( rtrim( $available_tags ) );
134 115
135 116 if ( ! empty( $available_tags ) ) {
136 117 $available_tags = array_map( 'trim', explode( ',', $available_tags ) );
137 118 $available_tags = array_unique( $available_tags );
119 + } elseif ( $snippet_type !== 'text' && $snippet_type !== 'advert' ) {
120 + $available_tags = [ 'id', 'title' ];
138 121 } else {
139 - if ( $snippet_type !== 'text' && $snippet_type !== 'advert' ) {
140 - $available_tags = [ 'id', 'title' ];
141 - } else {
142 - $available_tags = [ 'id' ];
143 - }
122 + $available_tags = [ 'id' ];
144 123 }
145 124
146 125 $tags = [
147 126 'id' => $snippet->ID,
@@ -146,9 +125,9 @@
146 125 $tags = [
147 126 'id' => $snippet->ID,
148 127 'type' => $snippet_type,
149 128 '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
129 + 'title' => empty( $snippet->post_title ) ? '(no titled, ID=' . $snippet->ID . ')' : $snippet->post_title,
151 130 ];
152 131
153 132 if ( ! empty( $available_tags ) ) {
154 133 foreach ( (array) $available_tags as $tag ) {
@@ -155,11 +134,11 @@
155 134 if ( '' != $tag ) {
156 135 if ( 'title' == $tag ) {
157 136 $tags['title'] = empty( $snippet->post_title ) ? '(no titled, ID=' . $snippet->ID . ')' : $snippet->post_title;
158 137 $tag_names[] = 'title';
159 - } else if ( 'id' != $tag ) {
138 + } elseif ( 'id' != $tag ) {
160 139 $tag = preg_replace( '/[^a-zA-Z0-9_\x7f-\xff]/', '', $tag );
161 - $tags[ $tag ] = "";
140 + $tags[ $tag ] = '';
162 141 $tag_names[] = $tag;
163 142 }
164 143 }
165 144 }
@@ -176,9 +155,9 @@
176 155
177 156 /**
178 157 * Get snippet type
179 158 *
180 - * @param null $post_id
159 + * @param mixed $post_id Post ID.
181 160 *
182 161 * @return array|mixed|string
183 162 */
184 163 public static function get_snippet_type( $post_id = null ) {
@@ -185,10 +164,10 @@
185 164 global $post;
186 165
187 166 $_post = $post;
188 167
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', '' );
168 + $snippet_type = WINP_HTTP::get( 'winp_item', WINP_SNIPPET_TYPE_PHP, 'sanitize_key' );
169 + $get_post = WINP_HTTP::get( 'post', '' );
191 170
192 171 if ( empty( $post_id ) && ! empty( $get_post ) && ! is_array( $get_post ) ) {
193 172 $post_id = esc_attr( $get_post );
194 173 }
@@ -197,9 +176,9 @@
197 176 $_post = get_post( $post_id );
198 177 }
199 178
200 179 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 );
180 + $_snippet_type = get_post_meta( $_post->ID, 'wbcr_inp_snippet_type', true );
202 181 $snippet_type = $_snippet_type ? $_snippet_type : $snippet_type;
203 182 }
204 183
205 184 return $snippet_type;
@@ -218,18 +197,18 @@
218 197 * @return boolean
219 198 */
220 199 public static function doing_rest_api() {
221 200 $prefix = rest_get_url_prefix();
222 - $rest_route = WINP_Plugin::app()->request->get( 'rest_route', null );
201 + $rest_route = WINP_HTTP::get( 'rest_route', null );
223 202 if ( defined( 'REST_REQUEST' ) && REST_REQUEST // (#1)
224 - || ! is_null( $rest_route ) // (#2)
225 - && strpos( trim( $rest_route, '\\/' ), $prefix, 0 ) === 0 ) {
203 + || ! is_null( $rest_route ) // (#2)
204 + && strpos( trim( $rest_route, '\\/' ), $prefix, 0 ) === 0 ) {
226 205 return true;
227 206 }
228 207
229 208 // (#3)
230 209 $rest_url = wp_parse_url( site_url( $prefix ) );
231 - $current_url = wp_parse_url( add_query_arg( [] ) );
210 + $current_url = wp_parse_url( esc_url( add_query_arg( [] ) ) );
232 211
233 212 return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
234 213 }
235 214
@@ -266,15 +245,13 @@
266 245 *
267 246 * @param WP_Post $post
268 247 *
269 248 * @return string snippet code
270 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
271 249 * @since 2.2.1
272 - *
273 250 */
274 251 public static function get_snippet_code( $post ) {
275 252 if ( empty( $post->post_content ) ) {
276 - return WINP_Helper::getMetaOption( $post->ID, 'snippet_code' );
253 + return self::getMetaOption( $post->ID, 'snippet_code' );
277 254 }
278 255
279 256 return $post->post_content;
280 257 }
@@ -281,11 +258,11 @@
281 258
282 259 /**
283 260 * Get meta option
284 261 *
285 - * @param int $post_id
262 + * @param int $post_id
286 263 * @param string $option_name
287 - * @param mixed $default
264 + * @param mixed $default
288 265 *
289 266 * @return mixed|array
290 267 */
291 268 public static function getMetaOption( $post_id, $option_name, $default = null ) {
@@ -300,17 +277,17 @@
300 277 }
301 278 }
302 279 }
303 280
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;
281 + return isset( self::$meta_options[ $post_id ][ 'wbcr_inp_' . $option_name ] ) ? self::$meta_options[ $post_id ][ 'wbcr_inp_' . $option_name ] : $default;
305 282 }
306 283
307 284 /**
308 285 * Udpdate meta option
309 286 *
310 - * @param int $post_id
287 + * @param int $post_id
311 288 * @param string $option_name
312 - * @param mixed $option_value
289 + * @param mixed $option_value
313 290 *
314 291 * @return bool|int
315 292 */
316 293 public static function updateMetaOption( $post_id, $option_name, $option_value ) {
@@ -315,29 +292,14 @@
315 292 */
316 293 public static function updateMetaOption( $post_id, $option_name, $option_value ) {
317 294 $post_id = (int) $post_id;
318 295
319 - return update_post_meta( $post_id, WINP_Plugin::app()->getPrefix() . $option_name, $option_value );
296 + return update_post_meta( $post_id, 'wbcr_inp_' . $option_name, $option_value );
320 297 }
321 298
322 299 /**
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 300 * Check capabilities for snippets post type.
338 301 *
339 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
340 302 * @since 2.2.0
341 303 */
342 304 public static function has_post_capabilities() {
343 305 $role = get_role( 'administrator' );
@@ -351,9 +313,8 @@
351 313
352 314 /**
353 315 * Set capabilities for snippets post type.
354 316 *
355 - * @author Alexander Kovalev <alex.kovalevv@gmail.com>
356 317 * @since 2.2.0
357 318 */
358 319 public static function set_post_capabilities() {
359 320 $role = get_role( 'administrator' );
@@ -377,18 +338,18 @@
377 338 * Create a demo snippets with examples of use
378 339 */
379 340 public static function create_demo_snippets() {
380 341
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 );
342 + update_option( 'wbcr_inp_activate_by_default', 1 );
343 + update_option( 'wbcr_inp_complete_uninstall', 0 );
344 + update_option( 'wbcr_inp_code_editor_theme', 'default' );
345 + update_option( 'wbcr_inp_code_editor_indent_with_tabs', 1 );
346 + update_option( 'wbcr_inp_code_editor_tab_size', 4 );
347 + update_option( 'wbcr_inp_code_editor_indent_unit', 4 );
348 + update_option( 'wbcr_inp_code_editor_wrap_lines', 1 );
349 + update_option( 'wbcr_inp_code_editor_line_numbers', 1 );
350 + update_option( 'wbcr_inp_code_editor_auto_close_brackets', 1 );
351 + update_option( 'wbcr_inp_code_editor_highlight_selection_matches', 0 );
391 352
392 353 $posts = [
393 354 [
394 355 'post_title' => __( 'Simple universal snippet: Google analytics tracking', 'insert-php' ),
@@ -395,13 +356,13 @@
395 356 'post_name' => 'simple-universal-snippet',
396 357 'post_content' => self::get_simple_universal_snippet(),
397 358 'meta' => [
398 359 '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.' ),
360 + '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 361 '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 362 'tags' => [ 'universal', 'tracking' ],
402 - 'priority' => 10
403 - ]
363 + 'priority' => 10,
364 + ],
404 365 ],
405 366 [
406 367 'post_title' => __( 'Simple text snippet: What is Lorem Ipsum?', 'insert-php' ),
407 368 'post_name' => 'simple-text-snippet',
@@ -407,13 +368,13 @@
407 368 'post_name' => 'simple-text-snippet',
408 369 'post_content' => self::get_simple_text_snippet(),
409 370 'meta' => [
410 371 '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' ),
372 + 'description' => __( 'This is ordinary maintenance text. With this snippet, you can fill your pages with meaningless English text.', 'insert-php' ),
412 373 '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 374 'tags' => [ 'text', 'lorem ipsum' ],
414 - 'priority' => 20
415 - ]
375 + 'priority' => 20,
376 + ],
416 377 ],
417 378 [
418 379 'post_title' => __( 'Simple php snippet: Disable emojis', 'insert-php' ),
419 380 'post_name' => 'simple-php-snippet',
@@ -419,12 +380,12 @@
419 380 'post_name' => 'simple-php-snippet',
420 381 'post_content' => self::get_simple_php_snippet(),
421 382 'meta' => [
422 383 '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' ),
384 + '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 385 'tags' => [ 'php', 'disable features' ],
425 - 'priority' => 30
426 - ]
386 + 'priority' => 30,
387 + ],
427 388 ],
428 389 [
429 390 'post_title' => __( 'Add Facebook Pixel to the Order success page', 'insert-php' ),
430 391 'post_name' => 'simple-uni-snippet-for-woocommerce',
@@ -433,46 +394,48 @@
433 394 'type' => WINP_SNIPPET_TYPE_UNIVERSAL,
434 395 'description' => __( 'Add Facebook Pixel to the Order success page.', 'insert-php' ),
435 396 '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 397 'tags' => [ 'woocommerce' ],
437 - 'priority' => 40
438 - ]
398 + 'priority' => 40,
399 + ],
439 400 ],
440 401 ];
441 402
442 403 foreach ( $posts as $post ) {
443 404 // '@' 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 - ] );
405 + $post_id = @wp_insert_post(
406 + [
407 + 'post_content' => $post['post_content'],
408 + 'post_title' => $post['post_title'],
409 + 'post_status' => 'publish',
410 + 'post_type' => WINP_SNIPPETS_POST_TYPE,
411 + ]
412 + );
450 413
451 414 if ( ! is_wp_error( $post_id ) ) {
452 415 if ( isset( $post['meta']['type'] ) ) {
453 - WINP_Helper::updateMetaOption( $post_id, 'snippet_type', $post['meta']['type'] );
416 + self::updateMetaOption( $post_id, 'snippet_type', $post['meta']['type'] );
454 417
455 418 if ( $post['meta']['type'] == WINP_SNIPPET_TYPE_PHP ) {
456 - WINP_Helper::updateMetaOption( $post_id, 'snippet_scope', 'evrywhere' );
419 + self::updateMetaOption( $post_id, 'snippet_scope', 'evrywhere' );
457 420 }
458 421 if ( $post['meta']['type'] == WINP_SNIPPET_TYPE_TEXT ) {
459 - WINP_Helper::updateMetaOption( $post_id, 'snippet_scope', 'shortcode' );
422 + self::updateMetaOption( $post_id, 'snippet_scope', 'shortcode' );
460 423 }
461 424 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' );
425 + self::updateMetaOption( $post_id, 'snippet_scope', 'auto' );
426 + self::updateMetaOption( $post_id, 'snippet_location', 'header' );
464 427 }
465 428 }
466 429
467 430 if ( isset( $post['meta']['description'] ) ) {
468 - WINP_Helper::updateMetaOption( $post_id, 'snippet_description', $post['meta']['description'] );
431 + self::updateMetaOption( $post_id, 'snippet_description', $post['meta']['description'] );
469 432 }
470 433
471 434 if ( isset( $post['meta']['filters'] ) && is_serialized( $post['meta']['filters'] ) ) {
472 435 $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 );
436 + self::updateMetaOption( $post_id, 'snippet_filters', $unserialized_filters );
437 + self::updateMetaOption( $post_id, 'changed_filters', 1 );
475 438 }
476 439
477 440 if ( isset( $post['meta']['tags'] ) && ! empty( $post['meta']['tags'] ) ) {
478 441 if ( ! taxonomy_exists( WINP_SNIPPETS_TAXONOMY ) ) {
@@ -482,14 +445,14 @@
482 445 wp_set_post_terms( $post_id, $post['meta']['tags'], WINP_SNIPPETS_TAXONOMY, true );
483 446 }
484 447
485 448 if ( isset( $post['meta']['priority'] ) ) {
486 - WINP_Helper::updateMetaOption( $post_id, 'snippet_priority', $post['meta']['priority'] );
449 + self::updateMetaOption( $post_id, 'snippet_priority', $post['meta']['priority'] );
487 450 }
488 451 }
489 452 }
490 453
491 - update_option( WINP_Plugin::app()->getOptionName( 'demo_snippets_created' ), 1 );
454 + update_option( 'wbcr_inp_demo_snippets_created', 1 );
492 455 }
493 456
494 457 /**
495 458 * Returns an example php snippet content
@@ -496,12 +459,12 @@
496 459 *
497 460 * @return string
498 461 */
499 462 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;
463 + $output = '/**' . PHP_EOL;
464 + $output .= '* Disable WP 4.2 emoji' . PHP_EOL;
465 + $output .= '*/' . PHP_EOL;
466 + $output .= 'function ace_remove_emoji() {' . PHP_EOL;
504 467 $output .= "\tadd_filter( 'emoji_svg_url', '__return_false' );" . PHP_EOL;
505 468 $output .= "\tremove_action( 'admin_print_styles', 'print_emoji_styles' );" . PHP_EOL;
506 469 $output .= "\tremove_action( 'wp_head', 'print_emoji_detection_script', 7 );" . PHP_EOL;
507 470 $output .= "\tremove_action( 'admin_print_scripts', 'print_emoji_detection_script' );" . PHP_EOL;
@@ -510,17 +473,17 @@
510 473 $output .= "\tremove_filter( 'the_content_feed', 'wp_staticize_emoji' );" . PHP_EOL;
511 474 $output .= "\tremove_filter( 'comment_text_rss', 'wp_staticize_emoji' );" . PHP_EOL;
512 475 $output .= "\t// filter to remove TinyMCE emojis" . PHP_EOL;
513 476 $output .= "\tadd_filter( 'tiny_mce_plugins', 'ace_disable_emoji_tinymce' );" . PHP_EOL;
514 - $output .= "}" . PHP_EOL;
477 + $output .= '}' . PHP_EOL;
515 478 $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;
479 + $output .= '/**' . PHP_EOL;
480 + $output .= '* Remove tinyMCE emoji' . PHP_EOL;
481 + $output .= '*/' . PHP_EOL;
482 + $output .= 'function ace_disable_emoji_tinymce( $plugins ) {' . PHP_EOL;
520 483 $output .= "\tunset( \$plugins['wpemoji'] );" . PHP_EOL;
521 484 $output .= "\treturn \$plugins;" . PHP_EOL;
522 - $output .= "}" . PHP_EOL;
485 + $output .= '}' . PHP_EOL;
523 486
524 487 return $output;
525 488 }
526 489
@@ -529,10 +492,10 @@
529 492 *
530 493 * @return string
531 494 */
532 495 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;
496 + $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.';
497 + $output .= PHP_EOL . '{{SNIPPET_CONTENT}}' . PHP_EOL;
535 498
536 499 return $output;
537 500 }
538 501
@@ -541,17 +504,17 @@
541 504 *
542 505 * @return string
543 506 */
544 507 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;
508 + $output = '<!-- Global Site Tag (gtag.js) - Google Analytics -->' . PHP_EOL;
509 + $output .= '<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>' . PHP_EOL;
510 + $output .= '<script>' . PHP_EOL;
548 511 $output .= "\twindow.dataLayer = window.dataLayer || [];" . PHP_EOL;
549 512 $output .= "\tfunction gtag(){dataLayer.push(arguments);}" . PHP_EOL;
550 513 $output .= "\tgtag('js', new Date());" . PHP_EOL;
551 514 $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;
515 + $output .= '</script>' . PHP_EOL;
516 + $output .= '<!-- End global Site Tag (gtag.js) - Google Analytics -->' . PHP_EOL;
554 517
555 518 return $output;
556 519 }
557 520
@@ -560,9 +523,9 @@
560 523 *
561 524 * @return string
562 525 */
563 526 protected static function get_woo_snippet() {
564 - $output = <<<SCRIPT
527 + $output = <<<'SCRIPT'
565 528 <script type="text/javascript">
566 529 var pixel_id = ''; // Add you FB pixel ID!
567 530 !function (f, b, e, v, n, t, s) {
568 531 if (f.fbq) return; n = f.fbq = function () {
@@ -586,74 +549,39 @@
586 549 *
587 550 * @param $name
588 551 * @param $obj
589 552 */
590 - public static function register_shortcode( $name, $obj ) {
591 - Wbcr_FactoryShortcodes329::register( $name, $obj );
592 - }
593 -
594 553 /**
595 - * Wrapper for get factory class for container
554 + * Register a shortcode class
596 555 *
597 - * @return string
598 - */
599 - public static function get_factory_class() {
600 - return "factory-bootstrap-454 factory-fontawesome-000";
601 - }
602 -
603 - /**
604 - * Wrapper for Wbcr_FactoryForms450_OptionsValueProvider object
556 + * @param string $name Shortcode class name.
557 + * @param object $obj Plugin object.
605 558 *
606 - * @param $plugin
607 - *
608 - * @return Wbcr_FactoryForms450_OptionsValueProvider
559 + * @return void
609 560 */
610 - public static function get_options_value_provider( $plugin ) {
611 - return new Wbcr_FactoryForms450_OptionsValueProvider( $plugin );
561 + public static function register_shortcode( $name, $obj ) {
562 + if ( class_exists( $name ) ) {
563 + new $name( $obj );
564 + }
612 565 }
613 566
614 567 /**
615 - * Wrapper for get factory form object
616 - *
617 - * @param $options
618 - * @param $plugin
619 - *
620 - * @return Wbcr_FactoryForms450_Form
621 - */
622 - public static function get_factory_form( $options, $plugin ) {
623 - return new Wbcr_FactoryForms450_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_FactoryMetaboxes409::registerFor( $class_name_or_object, $post_type, $plugin );
635 - }
636 -
637 - /**
638 568 * Render html for purchase button
639 569 */
640 570 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;
571 + $price_url = tsdk_utmify( WINP_UPGRADE, 'upsell_button', $utm_tracking_location );
644 572 ?>
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>
573 + <p class="winp-purchase-button">
574 + <a class="button" id="winp-library-buy-button" href="<?php echo esc_url( $price_url ); ?>" target="_blank">
575 + <span><?php _e( 'Upgrade to Pro', 'insert-php' ); ?></span>
576 + </a>
577 + </p>
650 578 <?php
651 579 }
652 580
653 581 /**
654 582 * Check if current user is admin or editor
655 - * todo: удалить этот метод, потому что он дублирует функционал WINP_Plugin::app()->currentUserCan
583 + * todo: удалить этот метод, потому что он дублирует функционал WINP_Plugin::app()->current_user_car
656 584 *
657 585 * @return bool
658 586 */
659 587 public static function winp_check_user_admin() {
@@ -660,12 +588,12 @@
660 588 return current_user_can( 'manage_options' ) || current_user_can( 'administrator' );
661 589 }
662 590
663 591 /*
664 - * Flushes as many page cache plugin's caches as possible.
665 - *
666 - * @return void
667 - */
592 + * Flushes as many page cache plugin's caches as possible.
593 + *
594 + * @return void
595 + */
668 596 public static function flush_page_cache() {
669 597 if ( function_exists( 'wp_cache_clear_cache' ) ) {
670 598 if ( is_multisite() ) {
671 599 $blog_id = get_current_blog_id();
@@ -672,24 +600,24 @@
672 600 wp_cache_clear_cache( $blog_id );
673 601 } else {
674 602 wp_cache_clear_cache();
675 603 }
676 - } else if ( has_action( 'cachify_flush_cache' ) ) {
604 + } elseif ( has_action( 'cachify_flush_cache' ) ) {
677 605 do_action( 'cachify_flush_cache' );
678 - } else if ( function_exists( 'w3tc_pgcache_flush' ) ) {
606 + } elseif ( function_exists( 'w3tc_pgcache_flush' ) ) {
679 607 w3tc_pgcache_flush();
680 - } else if ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
608 + } elseif ( function_exists( 'wp_fast_cache_bulk_delete_all' ) ) {
681 609 wp_fast_cache_bulk_delete_all();
682 - } else if ( class_exists( 'WpFastestCache' ) ) {
610 + } elseif ( class_exists( 'WpFastestCache' ) ) {
683 611 $wpfc = new WpFastestCache();
684 612 $wpfc->deleteCache();
685 - } else if ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
613 + } elseif ( class_exists( 'c_ws_plugin__qcache_purging_routines' ) ) {
686 614 c_ws_plugin__qcache_purging_routines::purge_cache_dir(); // quick cache
687 - } else if ( class_exists( 'zencache' ) ) {
615 + } elseif ( class_exists( 'zencache' ) ) {
688 616 zencache::clear();
689 - } else if ( class_exists( 'comet_cache' ) ) {
617 + } elseif ( class_exists( 'comet_cache' ) ) {
690 618 comet_cache::clear();
691 - } else if ( class_exists( 'WpeCommon' ) ) {
619 + } elseif ( class_exists( 'WpeCommon' ) ) {
692 620 // WPEngine cache purge/flush methods to call by default
693 621 $wpe_methods = [
694 622 'purge_varnish_cache',
695 623 ];
@@ -706,11 +634,11 @@
706 634 if ( method_exists( 'WpeCommon', $wpe_method ) ) {
707 635 WpeCommon::$wpe_method();
708 636 }
709 637 }
710 - } else if ( function_exists( 'sg_cachepress_purge_cache' ) ) {
638 + } elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) {
711 639 sg_cachepress_purge_cache();
712 - } else if ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
640 + } elseif ( file_exists( WP_CONTENT_DIR . '/wp-cache-config.php' ) && function_exists( 'prune_super_cache' ) ) {
713 641 // fallback for WP-Super-Cache
714 642 global $cache_path;
715 643 if ( is_multisite() ) {
716 644 $blog_id = get_current_blog_id();
@@ -727,18 +655,17 @@
727 655 * @param $post WP_Post
728 656 *
729 657 * @return string
730 658 * @since 2.4.0
731 - *
732 659 */
733 660 public static function get_where_use_text( $post ) {
734 661 global $winp_snippets_locations;
735 662 $snippet_scope = self::getMetaOption( $post->ID, 'snippet_scope' );
736 - $result = "";
663 + $result = '';
737 664
738 665 if ( $snippet_scope == 'evrywhere' ) {
739 666 $result = __( 'Run everywhere', 'insert-php' );
740 - } else if ( $snippet_scope == 'auto' ) {
667 + } elseif ( $snippet_scope == 'auto' ) {
741 668 $items = $winp_snippets_locations->getList();
742 669
743 670 $snippet_location = self::getMetaOption( $post->ID, 'snippet_location', '' );
744 671
@@ -775,12 +702,14 @@
775 702 */
776 703 public static function get_next_snippet_priority() {
777 704 global $wpdb;
778 705
779 - $max_priority = $wpdb->get_var( "
706 + $max_priority = $wpdb->get_var(
707 + "
780 708 SELECT MAX(CAST(meta_value AS UNSIGNED))
781 709 FROM {$wpdb->postmeta}
782 - WHERE meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_priority'" );
710 + WHERE meta_key = 'wbcr_inp_snippet_priority'"
711 + );
783 712
784 713 if ( is_null( $max_priority ) ) {
785 714 $max_priority = 0;
786 715 } else {
@@ -797,6 +726,5 @@
797 726 */
798 727 public static function is_woo_active() {
799 728 return is_plugin_active( 'woocommerce/woocommerce.php' );
800 729 }
801 -
802 730 }