PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.2.7
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.2.7
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.execute.snippet.php +77 -351 2.4.62.2.7 View file →
@@ -1,11 +1,11 @@
1 1 <?php
2 2 /**
3 3 * Execute snippet
4 4 *
5 - * @author Artem Prihodko <webtemyk@yandex.ru>
6 - * @copyright (c) 2020, CreativeMotion
7 - * @version 2.4
5 + * @author Webcraftic <wordpress.webraftic@gmail.com>
6 + * @copyright (c) 16.11.2018, Webcraftic
7 + * @version 1.0
8 8 */
9 9
10 10 // Exit if accessed directly
11 11 if ( ! defined( 'ABSPATH' ) ) {
@@ -14,36 +14,11 @@
14 14
15 15 class WINP_Execute_Snippet {
16 16
17 17 /**
18 - * @var self
19 - */
20 - private static $instance;
21 -
22 - /**
23 - * @var array
24 - */
25 - public $snippets;
26 -
27 - /**
28 - * @var WINP_Insertion_Locations
29 - */
30 - public $snippets_locations;
31 -
32 - public static function app() {
33 - if ( self::$instance === null ) {
34 - self::$instance = new self();
35 - }
36 -
37 - return self::$instance;
38 - }
39 -
40 - /**
41 18 * WINP_Execute_Snippet constructor.
42 19 */
43 20 public function __construct() {
44 - self::$instance = $this;
45 -
46 21 if ( ! defined( 'WINP_UPLOAD_DIR' ) ) {
47 22 $dir = wp_upload_dir();
48 23 define( 'WINP_UPLOAD_DIR', $dir['basedir'] . '/winp-css-js' );
49 24 }
@@ -51,28 +26,8 @@
51 26 if ( ! defined( 'WINP_UPLOAD_URL' ) ) {
52 27 $dir = wp_upload_dir();
53 28 define( 'WINP_UPLOAD_URL', $dir['baseurl'] . '/winp-css-js' );
54 29 }
55 - global $wpdb;
56 -
57 - $sql = "SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_content, p2.meta_value as priority
58 - FROM {$wpdb->posts}
59 - INNER JOIN {$wpdb->postmeta} p1 ON ({$wpdb->posts}.ID = p1.post_id)
60 - INNER JOIN {$wpdb->postmeta} p2 ON ({$wpdb->posts}.ID = p2.post_id)
61 - INNER JOIN {$wpdb->postmeta} p3 ON ({$wpdb->posts}.ID = p3.post_id)
62 - WHERE (( p1.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_scope' AND p1.meta_value = '%s')
63 - AND
64 - ( p3.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_activate' AND p3.meta_value = '1')
65 - AND p2.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_priority' )
66 - AND {$wpdb->posts}.post_type = '" . WINP_SNIPPETS_POST_TYPE . "'
67 - AND ({$wpdb->posts}.post_status = 'publish')
68 - ORDER BY CAST(priority AS UNSIGNED) %s";
69 -
70 - $this->snippets['evrywhere'] = $wpdb->get_results( sprintf( $sql, 'evrywhere', 'DESC' ) );
71 - $this->snippets['auto'] = $wpdb->get_results( sprintf( $sql, 'auto', 'ASC' ) );
72 -
73 - global $winp_snippets_locations;
74 - $this->snippets_locations = new WINP_Insertion_Locations();
75 30 }
76 31
77 32 /**
78 33 * Register hooks
@@ -85,21 +40,14 @@
85 40 add_action( 'wp_footer', [ $this, 'executeFooterSnippets' ] );
86 41 add_filter( 'the_post', [ $this, 'executePostSnippets' ], 10, 2 );
87 42 add_filter( 'the_content', [ $this, 'executeContentSnippets' ] );
88 43 add_filter( 'the_excerpt', [ $this, 'executeExcerptSnippets' ] );
89 - // Бесполезный хук, который вызывается на каждый комментарий. Если их много, увеличивается нагрузка
90 - //add_filter( 'wp_list_comments_args', [ $this, 'executeListCommentsSnippets' ] );
91 -
92 - //add_action( 'wp_head', [ $this, 'executeWoocommerceSnippets' ] );
93 -
94 - if ( ! empty( $this->snippets_locations->getInsertion( 'custom' ) ) ) {
95 - add_action( 'wp_head', [ $this, 'executeCustomSnippets' ] );
96 - }
44 + add_filter( 'wp_list_comments_args', [ $this, 'executeListCommentsSnippets' ] );
97 45 }
98 46 }
99 47
100 48 /**
101 - * Execute the everywhere snippets once the plugins are loaded
49 + * Execute the evrywhere snippets once the plugins are loaded
102 50 */
103 51 public function executeEverywhereSnippets() {
104 52 echo $this->executeActiveSnippets( 'evrywhere' );
105 53 }
@@ -107,9 +55,9 @@
107 55 /**
108 56 * Execute the snippets in header of page once the plugins are loaded
109 57 */
110 58 public function executeHeaderSnippets() {
111 - echo $this->executeActiveSnippets( 'auto', 'header' );
59 + echo $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_HEADER );
112 60 }
113 61
114 62 /**
115 63 * Execute the snippets in footer of page once the plugins are loaded
@@ -114,9 +62,9 @@
114 62 /**
115 63 * Execute the snippets in footer of page once the plugins are loaded
116 64 */
117 65 public function executeFooterSnippets() {
118 - echo $this->executeActiveSnippets( 'auto', 'footer' );
66 + echo $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_FOOTER );
119 67 }
120 68
121 69 /**
122 70 * Execute the snippets before post
@@ -132,22 +80,21 @@
132 80 $post_type = ! empty( $post ) ? $post->post_type : get_post( $data->ID )->post_type;
133 81 if ( is_singular( [ $post_type ] ) && $post->ID == $data->ID ) {
134 82 if ( did_action( 'get_header' ) ) {
135 83 // Перед заголовком
136 - $content = $this->executeActiveSnippets( 'auto', 'before_post' );
84 + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_POST );
137 85 }
138 - }
139 - else {
86 + } else {
140 87 if ( $query->post_count > 0 ) {
141 88 if ( $query->post_count > 1 && $query->current_post > 0 && $query->post_count > $query->current_post ) {
142 89 // Между записями
143 - $content = $this->executeActiveSnippets( 'auto', 'between_posts' );
90 + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BETWEEN_POSTS );
144 91 }
145 92 // Перед записью
146 - $content .= $this->executeActiveSnippets( 'auto', 'before_posts', '', $query );
93 + $content .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_POSTS, '', $query );
147 94
148 95 // После записи
149 - $content .= $this->executeActiveSnippets( 'auto', 'after_posts', '', $query );
96 + $content .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_POSTS, '', $query );
150 97 }
151 98 }
152 99
153 100 echo $content;
@@ -165,10 +112,9 @@
165 112 */
166 113 private function handleParagraphContent( $content, $snippet_content, $paragraph_number, $type = 'before' ) {
167 114 if ( 'before' == $type ) {
168 115 preg_match_all( "/<p(.*?)>/", $content, $matches );
169 - }
170 - else {
116 + } else {
171 117 preg_match_all( "/<\/p>/", $content, $matches );
172 118 }
173 119 $paragraphs = $matches[0];
174 120
@@ -183,15 +129,13 @@
183 129 // Если указанный номер параграфа совпадает с текущим
184 130 if ( $paragraph_key + 1 == $paragraph_number ) {
185 131 if ( 'before' == $type ) {
186 132 $content = substr( $content, 0, $position ) . $snippet_content . substr( $content, $position );
187 - }
188 - else {
133 + } else {
189 134 $content = substr( $content, 0, $position + 4 ) . $snippet_content . substr( $content, $position + 4 );
190 135 }
191 136 break;
192 - }
193 - else {
137 + } else {
194 138 $offset = $position + 1;
195 139 }
196 140 }
197 141 }
@@ -201,13 +145,13 @@
201 145
202 146 /**
203 147 * Handle posts content
204 148 *
205 - * @param string $content
206 - * @param string $snippet_content
149 + * @param string $content
150 + * @param string $snippet_content
207 151 * @param integer $post_number
208 - * @param string $type
209 - * @param object $query
152 + * @param string $type
153 + * @param object $query
210 154 *
211 155 * @return mixed
212 156 */
213 157 private function handlePostsContent( $content, $snippet_content, $post_number, $type, $query ) {
@@ -218,17 +162,15 @@
218 162 }
219 163
220 164 if ( 'before' == $type && $query->current_post + 1 == $post_number ) {
221 165 return $snippet_content;
222 - }
223 - else if ( 'after' == $type ) {
166 + } else if ( 'after' == $type ) {
224 167 // Номер поста совпадает
225 168 if ( $query->current_post == $post_number ) {
226 169 return $snippet_content;
227 170 // Если это последний пост и указанный номер поста больше общего количества постов,
228 171 // то нужно сохранить контент сниппета для вывода в конце данного поста
229 - }
230 - else if ( $query->current_post + 1 == $query->post_count && $post_number >= $query->post_count ) {
172 + } else if ( $query->current_post + 1 == $query->post_count && $post_number >= $query->post_count ) {
231 173 $winp_after_post_content[ $query->post->ID ] = $snippet_content;
232 174 }
233 175 }
234 176 }
@@ -249,35 +191,34 @@
249 191 $post_type = ! empty( $post ) ? $post->post_type : false;
250 192
251 193 if ( is_category() || is_archive() || is_tag() || is_tax() || is_search() ) {
252 194 // Перед коротким описанием
253 - $content = $this->executeActiveSnippets( 'auto', 'before_excerpt' ) . $content;
195 + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_EXCERPT ) . $content;
254 196
255 197 // После короткого описания
256 - $content .= $this->executeActiveSnippets( 'auto', 'after_excerpt' );
198 + $content .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_EXCERPT );
257 199 }
258 200
259 201 if ( is_singular( [ $post_type ] ) ) {
260 202 // Перед параграфом
261 - $content = $this->executeActiveSnippets( 'auto', 'before_paragraph', $content );
203 + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_PARAGRAPH, $content );
262 204
263 205 // После параграфа
264 - $content = $this->executeActiveSnippets( 'auto', 'after_paragraph', $content );
206 + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_PARAGRAPH, $content );
265 207
266 208 // После заголовка
267 - $content = $this->executeActiveSnippets( 'auto', 'before_content' ) . $content;
209 + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_CONTENT ) . $content;
268 210
269 211 // После текста
270 - $content .= $this->executeActiveSnippets( 'auto', 'after_content' );
212 + $content .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_CONTENT );
271 213
272 214 // После поста
273 - $content .= $this->executeActiveSnippets( 'auto', 'after_post' );
215 + $content .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_POST );
274 216
275 217 if ( ! comments_open( $post->ID ) && ! get_comments_number( $post->ID ) ) {
276 218 remove_filter( 'wp_list_comments_args', [ $this, 'executeListCommentsSnippets' ] );
277 219 }
278 - }
279 - else if ( ! is_null( $post ) && isset( $winp_after_post_content[ $post->ID ] ) ) {
220 + } else if ( ! is_null( $post ) && isset( $winp_after_post_content[ $post->ID ] ) ) {
280 221 // После последнего поста в списке
281 222 $content .= $winp_after_post_content[ $post->ID ];
282 223 unset( $winp_after_post_content[ $post->ID ] );
283 224 }
@@ -294,12 +235,12 @@
294 235 */
295 236 public function executeExcerptSnippets( $excerpt ) {
296 237 if ( is_category() || is_archive() || is_tag() || is_tax() || is_search() ) {
297 238 // Перед коротким описанием
298 - $excerpt = $this->executeActiveSnippets( 'auto', 'before_excerpt' ) . $excerpt;
239 + $excerpt = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_BEFORE_EXCERPT ) . $excerpt;
299 240
300 241 // После короткого описания
301 - $excerpt .= $this->executeActiveSnippets( 'auto', 'after_excerpt' );
242 + $excerpt .= $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_EXCERPT );
302 243 }
303 244
304 245 return $excerpt;
305 246 }
@@ -338,9 +279,9 @@
338 279
339 280 $post_type = ! empty( $post ) ? $post->post_type : false;
340 281 if ( is_singular( [ $post_type ] ) ) {
341 282 // После комментариев
342 - $content = $this->executeActiveSnippets( 'auto', 'after_post' );
283 + $content = $this->executeActiveSnippets( 'auto', WINP_SNIPPET_AUTO_AFTER_POST );
343 284 }
344 285
345 286 echo $content;
346 287 }
@@ -345,124 +286,24 @@
345 286 echo $content;
346 287 }
347 288
348 289 /**
349 - * Execute the custom snippets
350 - *
351 - * @since 2.4
352 - */
353 - public function executeCustomSnippets() {
354 - $locations = $this->snippets_locations->getInsertion( 'custom' );
355 - foreach ( $locations as $location => $data ) {
356 - $this->executeActiveSnippets( 'auto', $location );
357 - }
358 - }
359 -
360 - /**
361 - * Execute Woocommerce actions/hooks
362 - *
363 - * @param $location
364 - * @param $snippet_content
365 - *
366 - * @since 2.4
367 - */
368 - public function woocommerce_actions( $location, $snippet_content = '' ) {
369 - $action = function () use ( $location, $snippet_content ) {
370 - echo $snippet_content;
371 - };
372 -
373 - switch ( $location ) {
374 - case 'woo_before_shop_loop':
375 - add_filter( 'woocommerce_product_loop_start', function ( $content ) use ( $snippet_content ) {
376 - return $snippet_content . $content;
377 - } );
378 - break;
379 - case 'woo_after_shop_loop':
380 - add_filter( 'woocommerce_product_loop_end', function ( $content ) use ( $snippet_content ) {
381 - return $content . $snippet_content;
382 - } );
383 - break;
384 - case 'woo_before_single_product':
385 - add_action( 'woocommerce_before_single_product', $action, 10, 2 );
386 - break;
387 - case 'woo_after_single_product':
388 - add_action( 'woocommerce_after_single_product', $action, 10, 2 );
389 - break;
390 - case 'woo_before_single_product_summary':
391 - add_action( 'woocommerce_before_single_product_summary', $action, 10, 2 );
392 - break;
393 - case 'woo_after_single_product_summary':
394 - add_action( 'woocommerce_after_single_product_summary', $action, 10, 2 );
395 - break;
396 - case 'woo_single_product_summary_title':
397 - add_action( 'woocommerce_single_product_summary', $action, 6, 2 );
398 - break;
399 - case 'woo_single_product_summary_price':
400 - add_action( 'woocommerce_single_product_summary', $action, 15, 2 );
401 - break;
402 - case 'woo_single_product_summary_excerpt':
403 - add_action( 'woocommerce_single_product_summary', $action, 25, 2 );
404 - break;
405 - default:
406 - break;
407 - }
408 - }
409 -
410 - /**
411 - * Execute Woocommerce actions/hooks
412 - *
413 - * @param $location
414 - * @param $snippet_content
415 - *
416 - * @since 2.4
417 - */
418 - public function custom_actions( $location, $snippet_content = '' ) {
419 - if ( ! empty( $this->snippets_locations->getLocation( $location ) ) ) {
420 - /**
421 - * Action for a custom location applied in 'wbcr/woody/add_custom_location' filter
422 - *
423 - * @param array $location Slug of the location.
424 - * @param string $snippet_content Rendered snippet content
425 - *
426 - * @since 2.4
427 - */
428 - do_action( "wbcr/woody/do_custom_location/{$location}", $snippet_content );
429 - }
430 - }
431 -
432 - /**
433 290 * Execute the snippets once the plugins are loaded
434 291 *
435 292 * @param string $scope
436 - * @param string $location
293 + * @param string $auto
437 294 * @param string $content
438 - * @param array $custom_params
295 + * @param array $custom_params
439 296 *
440 297 * @return string
441 298 */
442 - public function executeActiveSnippets( $scope = 'evrywhere', $location = '', $content = '', $custom_params = [] ) {
443 - /*
299 + public function executeActiveSnippets( $scope = 'evrywhere', $auto = '', $content = '', $custom_params = [] ) {
444 300 global $wpdb;
445 301
446 - if ( $scope == 'evrywhere' ) {
447 - $sort = 'DESC';
448 - } else {
449 - $sort = 'ASC';
450 - }
451 - $snippets = $wpdb->get_results( "SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_content, p2.meta_value as priority
302 + $snippets = $wpdb->get_results( "SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_content
452 303 FROM {$wpdb->posts}
453 - INNER JOIN {$wpdb->postmeta} p1 ON ({$wpdb->posts}.ID = p1.post_id)
454 - INNER JOIN {$wpdb->postmeta} p2 ON ({$wpdb->posts}.ID = p2.post_id)
455 - INNER JOIN {$wpdb->postmeta} p3 ON ({$wpdb->posts}.ID = p3.post_id)
456 - WHERE (( p1.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_scope' AND p1.meta_value = '{$scope}')
457 - AND
458 - ( p3.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_activate' AND p3.meta_value = '1')
459 - AND p2.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_priority' )
460 - AND {$wpdb->posts}.post_type = '" . WINP_SNIPPETS_POST_TYPE . "'
461 - AND ({$wpdb->posts}.post_status = 'publish')
462 - ORDER BY CAST(priority AS UNSIGNED) {$sort}" );
463 - */
464 - $snippets = $this->snippets[ $scope ] ?? [];
304 + INNER JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id )
305 + WHERE ( ( {$wpdb->postmeta}.meta_key = '" . WINP_Plugin::app()->getPrefix() . "snippet_scope' AND {$wpdb->postmeta}.meta_value = '{$scope}' ) ) AND {$wpdb->posts}.post_type = '" . WINP_SNIPPETS_POST_TYPE . "' AND ( ({$wpdb->posts}.post_status = 'publish') )" );
465 306
466 307 if ( empty( $snippets ) ) {
467 308 return $content;
468 309 }
@@ -468,16 +309,17 @@
468 309 }
469 310
470 311 foreach ( (array) $snippets as $snippet ) {
471 312 $id = (int) $snippet->ID;
472 - //$is_active = (int) WINP_Helper::getMetaOption( $id, 'snippet_activate', 0 );
313 +
314 + $is_active = (int) WINP_Helper::getMetaOption( $id, 'snippet_activate', 0 );
473 315 // Если это сниппет с автовставкой и выбранное место подходит под активный action
474 - $avail_place = ( 'auto' == $scope ? $location == WINP_Helper::getMetaOption( $id, 'snippet_location', '' ) : true );
475 - // Если условие отображения сниппета выполняется
316 + $avail_place = ( 'auto' == $scope ? $auto == WINP_Helper::getMetaOption( $id, 'snippet_location', '' ) : true );
317 + // Если условие отображения сниппена выполняется
476 318 $snippet_type = WINP_Helper::getMetaOption( $id, 'snippet_type', WINP_SNIPPET_TYPE_PHP );
477 319 $is_condition = $snippet_type != WINP_SNIPPET_TYPE_PHP ? $this->checkCondition( $id ) : true;
478 320
479 - if ( $avail_place && $is_condition ) {
321 + if ( $is_active && $avail_place && $is_condition ) {
480 322 $post_id = (int) WINP_Plugin::app()->request->post( 'post_ID', 0 );
481 323
482 324 if ( isset( $_POST['wbcr_inp_snippet_scope'] ) && $post_id === $id && WINP_Plugin::app()->currentUserCan() ) {
483 325 return $content;
@@ -486,39 +328,17 @@
486 328 if ( WINP_Helper::is_safe_mode() ) {
487 329 return $content;
488 330 }
489 331
490 - // WPML Compatibility
491 - if ( defined( 'WPML_PLUGIN_FILE' ) ) {
492 - $wpml_langs = WINP_Helper::getMetaOption( $id, 'snippet_wpml_lang', '' );
493 - if ( $wpml_langs !== '' && defined( 'ICL_LANGUAGE_CODE' ) ) {
494 - if ( ! in_array( ICL_LANGUAGE_CODE, explode( ',', $wpml_langs ) ) ) {
495 - continue;
496 - }
497 - }
498 - }
499 -
500 332 $snippet_code = WINP_Helper::get_snippet_code( $snippet );
501 333
502 - /**
503 - * Filter snippet code before execute
504 - */
505 - $snippet_code = apply_filters( 'wbcr/inp/execute_snippet/snippet_code', $snippet_code, $id );
506 -
507 - if ( WINP_Plugin::app()->getOption( 'execute_shortcode' ) ) {
508 - $snippet_code = do_shortcode( $snippet_code );
509 - }
510 -
511 - if ( $snippet_type === WINP_SNIPPET_TYPE_TEXT || $snippet_type === WINP_SNIPPET_TYPE_AD ) {
512 - $snippet_content = '<div class="winp-text-snippet-container">' . $snippet_code . '</div>';
513 - }
514 - else if ( $snippet_type === WINP_SNIPPET_TYPE_CSS || $snippet_type === WINP_SNIPPET_TYPE_JS ) {
334 + if ( $snippet_type === WINP_SNIPPET_TYPE_TEXT ) {
335 + $snippet_content = '<div class="winp-text-snippet-contanier">' . $snippet_code . '</div>';
336 + } else if ( $snippet_type === WINP_SNIPPET_TYPE_CSS || $snippet_type === WINP_SNIPPET_TYPE_JS ) {
515 337 $snippet_content = self::getJsCssSnippetData( $id );
516 - }
517 - else if ( $snippet_type === WINP_SNIPPET_TYPE_HTML ) {
338 + } else if ( $snippet_type === WINP_SNIPPET_TYPE_HTML ) {
518 339 $snippet_content = $snippet_code;
519 - }
520 - else {
340 + } else {
521 341 $code = $this->prepareCode( $snippet_code, $id );
522 342 ob_start();
523 343 $this->executeSnippet( $code, $id, false );
524 344 $snippet_content = ob_get_contents();
@@ -525,22 +345,22 @@
525 345 ob_end_clean();
526 346 }
527 347
528 348 if ( 'auto' == $scope ) {
529 - switch ( $location ) {
530 - case 'before_paragraph': // Перед параграфом
349 + switch ( $auto ) {
350 + case WINP_SNIPPET_AUTO_BEFORE_PARAGRAPH: // Перед параграфом
531 351 $location_number = WINP_Helper::getMetaOption( $id, 'snippet_p_number', 0 );
532 352 $content = $this->handleParagraphContent( $content, $snippet_content, $location_number );
533 353 break;
534 - case 'after_paragraph': // После параграфа
354 + case WINP_SNIPPET_AUTO_AFTER_PARAGRAPH: // После параграфа
535 355 $location_number = WINP_Helper::getMetaOption( $id, 'snippet_p_number', 0 );
536 356 $content = $this->handleParagraphContent( $content, $snippet_content, $location_number, 'after' );
537 357 break;
538 - case 'before_posts': // Перед записью
358 + case WINP_SNIPPET_AUTO_BEFORE_POSTS: // Перед записью
539 359 $location_number = WINP_Helper::getMetaOption( $id, 'snippet_p_number', 0 );
540 360 $content = $this->handlePostsContent( $content, $snippet_content, $location_number, 'before', $custom_params );
541 361 break;
542 - case 'after_posts': // После записи
362 + case WINP_SNIPPET_AUTO_AFTER_POSTS: // После записи
543 363 $location_number = WINP_Helper::getMetaOption( $id, 'snippet_p_number', 0 );
544 364 $content = $this->handlePostsContent( $content, $snippet_content, $location_number, 'after', $custom_params );
545 365 break;
546 366 default:
@@ -545,23 +365,9 @@
545 365 break;
546 366 default:
547 367 $content = $snippet_content . $content;
548 368 }
549 -
550 - /**
551 - * Action for woo actions
552 - *
553 - * @param array $location Slug of the location.
554 - * @param string $snippet_content Rendered snippet content
555 - *
556 - * @since 2.4
557 - */
558 - do_action( "wbcr/woody/do_woocommerce_actions", $location, $snippet_content );
559 -
560 - //$this->woocommerce_actions( $location, $snippet_content );
561 - $this->custom_actions( $location, $snippet_content );
562 - }
563 - else {
369 + } else {
564 370 $content = $snippet_content . $content;
565 371 }
566 372 }
567 373 }
@@ -616,11 +422,11 @@
616 422 *
617 423 * Code must NOT be escaped, as
618 424 * it will be executed directly
619 425 *
620 - * @param string $code The snippet code to execute
621 - * @param int $id The snippet ID
622 - * @param bool $catch_output Whether to attempt to suppress the output of execution using buffers
426 + * @param string $code The snippet code to execute
427 + * @param int $id The snippet ID
428 + * @param bool $catch_output Whether to attempt to suppress the output of execution using buffers
623 429 *
624 430 * @return mixed The result of the code execution
625 431 */
626 432 public function executeSnippet( $code, $id = 0, $catch_output = true ) {
@@ -643,13 +449,11 @@
643 449 $snippet_type = WINP_Helper::getMetaOption( $id, 'snippet_type', true );
644 450
645 451 if ( $snippet_type == WINP_SNIPPET_TYPE_UNIVERSAL ) {
646 452 $result = eval( "?>" . $code . "<?php " );
647 - }
648 - else if ( $snippet_type == WINP_SNIPPET_TYPE_PHP ) {
453 + } else if ( $snippet_type == WINP_SNIPPET_TYPE_PHP ) {
649 454 $result = eval( $code );
650 - }
651 - else {
455 + } else {
652 456 $result = ! empty( $code );
653 457 }
654 458
655 459 if ( $catch_output ) {
@@ -669,10 +473,9 @@
669 473 */
670 474 private function getPropertyValue( $value, $property ) {
671 475 if ( is_object( $value ) ) {
672 476 return $value->$property;
673 - }
674 - else if ( isset( $value[ $property ] ) ) {
477 + } else if ( isset( $value[ $property ] ) ) {
675 478 return $value[ $property ];
676 479 }
677 480
678 481 return null;
@@ -739,10 +542,9 @@
739 542 */
740 543 private function call_method( $method_name, $operator, $value ) {
741 544 if ( method_exists( $this, $method_name ) ) {
742 545 return $this->$method_name( $operator, $value );
743 - }
744 - else {
546 + } else {
745 547 return apply_filters( 'wbcr/inp/execute/check_condition', false, $method_name, $operator, $value );
746 548 }
747 549 }
748 550
@@ -784,9 +586,9 @@
784 586
785 587 /**
786 588 * Prepare the code by removing php tags from beginning and end
787 589 *
788 - * @param string $code
590 + * @param string $code
789 591 * @param integer $snippet_id
790 592 *
791 593 * @return string
792 594 */
@@ -845,21 +647,11 @@
845 647 */
846 648 public function checkByOperator( $operation, $first, $second, $third = false ) {
847 649 switch ( $operation ) {
848 650 case 'equals':
849 - if ( is_array( $second ) ) {
850 - return in_array( $first, $second );
851 - }
852 - else {
853 - return $first === $second;
854 - }
651 + return $first === $second;
855 652 case 'notequal':
856 - if ( is_array( $second ) ) {
857 - return ! in_array( $first, $second );
858 - }
859 - else {
860 - return $first !== $second;
861 - }
653 + return $first !== $second;
862 654 case 'less':
863 655 case 'older':
864 656 return $first > $second;
865 657 case 'greater':
@@ -887,10 +679,9 @@
887 679 */
888 680 private function user_role( $operator, $value ) {
889 681 if ( ! is_user_logged_in() ) {
890 682 return $this->checkByOperator( $operator, $value, 'guest' );
891 - }
892 - else {
683 + } else {
893 684 $current_user = wp_get_current_user();
894 685 if ( ! ( $current_user instanceof WP_User ) ) {
895 686 return false;
896 687 }
@@ -938,10 +729,9 @@
938 729 */
939 730 public function getDateTimestamp( $value ) {
940 731 if ( is_object( $value ) ) {
941 732 return ( current_time( 'timestamp' ) - $this->getTimestamp( $value->units, $value->unitsCount ) ) * 1000;
942 - }
943 - else {
733 + } else {
944 734 return $value;
945 735 }
946 736 }
947 737
@@ -956,10 +746,9 @@
956 746 */
957 747 private function user_registered( $operator, $value ) {
958 748 if ( ! is_user_logged_in() ) {
959 749 return false;
960 - }
961 - else {
750 + } else {
962 751 $user = wp_get_current_user();
963 752 $registered = strtotime( $user->data->user_registered ) * 1000;
964 753
965 754 if ( $operator == 'equals' || $operator == 'notequal' ) {
@@ -966,16 +755,14 @@
966 755 $registered = $registered / 1000;
967 756 $timestamp = round( $this->getDateTimestamp( $value ) / 1000 );
968 757
969 758 return $this->checkByOperator( $operator, date( "Y-m-d", $timestamp ), date( "Y-m-d", $registered ) );
970 - }
971 - else if ( $operator == 'between' ) {
759 + } else if ( $operator == 'between' ) {
972 760 $start_timestamp = $this->getDateTimestamp( $value->start );
973 761 $end_timestamp = $this->getDateTimestamp( $value->end );
974 762
975 763 return $this->checkByOperator( $operator, $start_timestamp, $registered, $end_timestamp );
976 - }
977 - else {
764 + } else {
978 765 $timestamp = $this->getDateTimestamp( $value );
979 766
980 767 return $this->checkByOperator( $operator, $timestamp, $registered );
981 768 }
@@ -996,10 +783,9 @@
996 783 $useragent = $_SERVER['HTTP_USER_AGENT'];
997 784
998 785 if ( preg_match( '/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent ) || preg_match( '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr( $useragent, 0, 4 ) ) ) {
999 786 return $operator === 'equals' && $value === 'yes' || $operator === 'notequal' && $value === 'no';
1000 - }
1001 - else {
787 + } else {
1002 788 return $operator === 'notequal' && $value === 'yes' || $operator === 'equals' && $value === 'no';
1003 789 }
1004 790 }
1005 791
@@ -1013,10 +799,9 @@
1013 799 */
1014 800 private function user_cookie_name( $operator, $value ) {
1015 801 if ( isset( $_COOKIE[ $value ] ) ) {
1016 802 return $operator === 'equals';
1017 - }
1018 - else {
803 + } else {
1019 804 return $operator === 'notequal';
1020 805 }
1021 806 }
1022 807
@@ -1093,37 +878,11 @@
1093 878 }
1094 879 break;
1095 880
1096 881 default:
1097 - $result = false;
882 + $result = true;
1098 883 }
1099 884
1100 - if ( WINP_Helper::is_woo_active() ) {
1101 - switch ( $value ) {
1102 - case 'woo_product':
1103 - $result = is_product();
1104 - break;
1105 - case 'woo_arch':
1106 - $result = is_shop();
1107 - break;
1108 - case 'woo_cart':
1109 - $result = is_cart();
1110 - break;
1111 - case 'woo_checkout':
1112 - $result = is_checkout();
1113 - break;
1114 - case 'woo_checkout_pay':
1115 - $result = is_checkout_pay_page();
1116 - break;
1117 - case 'woo_cat':
1118 - $result = is_product_category();
1119 - break;
1120 - case 'woo_tag':
1121 - $result = is_product_tag();
1122 - break;
1123 - }
1124 - }
1125 -
1126 885 return $this->checkByOperator( $operator, $result, true );
1127 886 }
1128 887
1129 888 /**
@@ -1170,56 +929,23 @@
1170 929 return false;
1171 930 }
1172 931
1173 932 /**
1174 - * A taxonomy page
933 + * A taxonomy of the current page
1175 934 *
1176 935 * @param $operator
1177 936 * @param $value
1178 937 *
1179 938 * @return boolean
1180 - * @since 2.2.8 The bug is fixed, the condition was not checked
1181 - * for tachonomies, only posts.
1182 - *
1183 939 */
1184 940 private function location_taxonomy( $operator, $value ) {
1185 - $term_id = null;
941 + global $post;
1186 942
1187 - if ( is_tax() || is_tag() || is_category() ) {
1188 - $term_id = get_queried_object()->term_id;
1189 -
1190 - if ( $term_id ) {
1191 - return $this->checkByOperator( $operator, intval( $value ), $term_id );
1192 - }
943 + $post_cat = get_the_category( $post->ID );
944 + if ( isset( $post_cat[0] ) ) {
945 + return $this->checkByOperator( $operator, intval( $value ), $post_cat[0]->term_id );
1193 946 }
1194 947
1195 948 return false;
1196 949 }
1197 950
1198 - /**
1199 - * A taxonomy of the current page
1200 - *
1201 - * @param $operator
1202 - * @param $value
1203 - *
1204 - * @return boolean
1205 - * @since 2.4.0
1206 - */
1207 - private function page_taxonomy( $operator, $value ) {
1208 - $term_id = null;
1209 -
1210 - if ( is_singular() ) {
1211 - $post_cat = get_the_category( get_the_ID() );
1212 - if ( is_array( $post_cat ) ) {
1213 - foreach ( $post_cat as $item ) {
1214 - $term_id[] = $item->term_id;
1215 - }
1216 - }
1217 - }
1218 -
1219 - if ( $term_id ) {
1220 - return $this->checkByOperator( $operator, intval( $value ), $term_id );
1221 - }
1222 -
1223 - return false;
1224 - }
1225 951 }