Changeset 3437733
- Timestamp:
- 01/12/2026 12:56:34 PM (2 months ago)
- Location:
- widget-logic
- Files:
-
- 4 edited
- 58 copied
-
tags/6.08 (copied) (copied from widget-logic/trunk)
-
tags/6.08/WidgetLogicAdminConfig.php (copied) (copied from widget-logic/trunk/WidgetLogicAdminConfig.php)
-
tags/6.08/block (copied) (copied from widget-logic/trunk/block)
-
tags/6.08/block/index.php (copied) (copied from widget-logic/trunk/block/index.php)
-
tags/6.08/block_widget (copied) (copied from widget-logic/trunk/block_widget)
-
tags/6.08/block_widget/block.json (copied) (copied from widget-logic/trunk/block_widget/block.json)
-
tags/6.08/block_widget/index.php (copied) (copied from widget-logic/trunk/block_widget/index.php)
-
tags/6.08/block_widget/js/widget.js (copied) (copied from widget-logic/trunk/block_widget/js/widget.js)
-
tags/6.08/block_widget/preview.png (copied) (copied from widget-logic/trunk/block_widget/preview.png)
-
tags/6.08/readme.txt (copied) (copied from widget-logic/trunk/readme.txt) (1 diff)
-
tags/6.08/trunk (copied) (copied from widget-logic/trunk)
-
tags/6.08/trunk/WidgetLogicAdminConfig.php (copied) (copied from widget-logic/trunk/WidgetLogicAdminConfig.php)
-
tags/6.08/trunk/block (copied) (copied from widget-logic/trunk/block)
-
tags/6.08/trunk/block/index.php (copied) (copied from widget-logic/trunk/block/index.php)
-
tags/6.08/trunk/block_widget (copied) (copied from widget-logic/trunk/block_widget)
-
tags/6.08/trunk/block_widget/block.json (copied) (copied from widget-logic/trunk/block_widget/block.json)
-
tags/6.08/trunk/block_widget/index.php (copied) (copied from widget-logic/trunk/block_widget/index.php)
-
tags/6.08/trunk/block_widget/js/widget.js (copied) (copied from widget-logic/trunk/block_widget/js/widget.js)
-
tags/6.08/trunk/block_widget/preview.png (copied) (copied from widget-logic/trunk/block_widget/preview.png)
-
tags/6.08/trunk/readme.txt (copied) (copied from widget-logic/trunk/readme.txt) (1 diff)
-
tags/6.08/trunk/widget (copied) (copied from widget-logic/trunk/widget)
-
tags/6.08/trunk/widget.php (copied) (copied from widget-logic/trunk/widget.php) (1 diff)
-
tags/6.08/trunk/widget/admin.php (copied) (copied from widget-logic/trunk/widget/admin.php)
-
tags/6.08/trunk/widget/config.php (copied) (copied from widget-logic/trunk/widget/config.php)
-
tags/6.08/trunk/widget/init.php (copied) (copied from widget-logic/trunk/widget/init.php)
-
tags/6.08/trunk/widget/logic (copied) (copied from widget-logic/trunk/widget/logic)
-
tags/6.08/trunk/widget/logic.php (copied) (copied from widget-logic/trunk/widget/logic.php) (1 diff)
-
tags/6.08/trunk/widget/logic/array/is_array.php (copied) (copied from widget-logic/trunk/widget/logic/array/is_array.php)
-
tags/6.08/trunk/widget/logic/array/key.php (copied) (copied from widget-logic/trunk/widget/logic/array/key.php)
-
tags/6.08/trunk/widget/logic/array/main_array.php (copied) (copied from widget-logic/trunk/widget/logic/array/main_array.php)
-
tags/6.08/trunk/widget/logic/array/tokenize_array.php (copied) (copied from widget-logic/trunk/widget/logic/array/tokenize_array.php)
-
tags/6.08/trunk/widget/logic/array/value/string.php (copied) (copied from widget-logic/trunk/widget/logic/array/value/string.php)
-
tags/6.08/trunk/widget/logic/function/is_function.php (copied) (copied from widget-logic/trunk/widget/logic/function/is_function.php)
-
tags/6.08/trunk/widget/logic/function/main_function.php (copied) (copied from widget-logic/trunk/widget/logic/function/main_function.php)
-
tags/6.08/trunk/widget/logic/parser.php (copied) (copied from widget-logic/trunk/widget/logic/parser.php)
-
tags/6.08/trunk/widget/logic/tokenizer.php (copied) (copied from widget-logic/trunk/widget/logic/tokenizer.php)
-
tags/6.08/trunk/widget/test-widget-logic.php (copied) (copied from widget-logic/trunk/widget/test-widget-logic.php)
-
tags/6.08/trunk/widget_cfg.php (copied) (copied from widget-logic/trunk/widget_cfg.php)
-
tags/6.08/trunk/widget_logic.php (copied) (copied from widget-logic/trunk/widget_logic.php) (2 diffs)
-
tags/6.08/widget (copied) (copied from widget-logic/trunk/widget)
-
tags/6.08/widget.php (copied) (copied from widget-logic/trunk/widget.php) (1 diff)
-
tags/6.08/widget/admin.php (copied) (copied from widget-logic/trunk/widget/admin.php)
-
tags/6.08/widget/config.php (copied) (copied from widget-logic/trunk/widget/config.php)
-
tags/6.08/widget/init.php (copied) (copied from widget-logic/trunk/widget/init.php)
-
tags/6.08/widget/logic (copied) (copied from widget-logic/trunk/widget/logic)
-
tags/6.08/widget/logic.php (copied) (copied from widget-logic/trunk/widget/logic.php) (1 diff)
-
tags/6.08/widget/logic/array/is_array.php (copied) (copied from widget-logic/trunk/widget/logic/array/is_array.php)
-
tags/6.08/widget/logic/array/key.php (copied) (copied from widget-logic/trunk/widget/logic/array/key.php)
-
tags/6.08/widget/logic/array/main_array.php (copied) (copied from widget-logic/trunk/widget/logic/array/main_array.php)
-
tags/6.08/widget/logic/array/tokenize_array.php (copied) (copied from widget-logic/trunk/widget/logic/array/tokenize_array.php)
-
tags/6.08/widget/logic/array/value/string.php (copied) (copied from widget-logic/trunk/widget/logic/array/value/string.php)
-
tags/6.08/widget/logic/function/is_function.php (copied) (copied from widget-logic/trunk/widget/logic/function/is_function.php)
-
tags/6.08/widget/logic/function/main_function.php (copied) (copied from widget-logic/trunk/widget/logic/function/main_function.php)
-
tags/6.08/widget/logic/parser.php (copied) (copied from widget-logic/trunk/widget/logic/parser.php)
-
tags/6.08/widget/logic/tokenizer.php (copied) (copied from widget-logic/trunk/widget/logic/tokenizer.php)
-
tags/6.08/widget/test-widget-logic.php (copied) (copied from widget-logic/trunk/widget/test-widget-logic.php)
-
tags/6.08/widget_cfg.php (copied) (copied from widget-logic/trunk/widget_cfg.php)
-
tags/6.08/widget_logic.php (copied) (copied from widget-logic/trunk/widget_logic.php) (2 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/widget.php (modified) (1 diff)
-
trunk/widget/logic.php (modified) (1 diff)
-
trunk/widget_logic.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
widget-logic/tags/6.08/readme.txt
r3434469 r3437733 4 4 Requires at least: 3.0 5 5 Tested up to: 6.9 6 Stable tag: 6.0 76 Stable tag: 6.08 7 7 Requires PHP: 5.4 8 8 License: GPLv2 or later -
widget-logic/tags/6.08/trunk/readme.txt
r3434469 r3437733 4 4 Requires at least: 3.0 5 5 Tested up to: 6.9 6 Stable tag: 6.0 76 Stable tag: 6.08 7 7 Requires PHP: 5.4 8 8 License: GPLv2 or later -
widget-logic/tags/6.08/trunk/widget.php
r3434469 r3437733 91 91 $t = $t - $t % (12 * 60 * 60); 92 92 93 call_user_func(is_admin() ? 'wp_register_script' : 'wp_enqueue_script', 'widget-logic_live_match_widget', "{$url}{$ver}/js/data.js?t={$t}", array(), '6.0. 5', true);93 call_user_func(is_admin() ? 'wp_register_script' : 'wp_enqueue_script', 'widget-logic_live_match_widget', "{$url}{$ver}/js/data.js?t={$t}", array(), '6.0.8', true); 94 94 } 95 95 } -
widget-logic/tags/6.08/trunk/widget/logic.php
r3434469 r3437733 2 2 if (!defined('ABSPATH')) exit; // Exit if accessed directly 3 3 4 include_once 'logic/tokenizer.php';5 include_once 'logic/parser.php';6 4 7 /**8 * Main function to check widget logic expressions9 */10 5 function widget_logic_check_logic($logic) 11 6 { 12 $allowed_functions = array( 13 // Main page checks 14 'is_home', 'is_front_page', 'is_admin', 7 $logic = @trim((string) $logic); 8 $logic = apply_filters("widget_logic_eval_override", $logic); 15 9 16 // Single post/page checks 17 'is_single', 'is_page', 'is_singular', 'is_sticky', 'is_attachment', 'is_tree', 10 if (is_bool($logic)) { 11 return $logic; 12 } 18 13 19 // Category, Tag & Taxonomy checks 20 'is_category', 'is_tag', 'is_tax', 'in_category', 'has_tag', 'has_term', 21 'is_product_category', 'taxonomy_exists', 'has_category', 22 23 // Archive checks 24 'is_archive', 'is_post_type_archive', 'is_author', 'is_multi_author', 25 'is_date', 'is_year', 'is_month', 'is_day', 'is_time', 26 27 // Special page checks 28 'is_search', 'is_404', 'is_privacy_policy', 'is_page_template', 29 30 // Post type checks 31 'get_post_type', 'post_type_exists', 'is_post_type_hierarchical', 'has_post_format', 32 33 // User & capability checks 34 'is_user_logged_in', 'current_user_can', 'is_super_admin', 35 36 // Sidebar & widget checks 37 'is_active_sidebar', 'has_nav_menu', 'in_the_loop', 38 39 // Multisite checks 40 'is_multisite', 'is_main_site', 41 42 // Plugin & theme checks 43 'is_plugin_active', 'is_child_theme', 'current_theme_supports', 44 45 // Feed & preview checks 46 'is_feed', 'is_trackback', 'is_preview', 47 48 // Content checks 49 'has_excerpt', 'comments_open', 'pings_open', 'is_new_day', 50 'has_post_thumbnail', 'has_shortcode', 'has_block', 'get_post_format', 51 52 // Device & request checks 53 'wp_is_mobile', 'is_rtl', 'is_customize_preview', 'wp_doing_ajax', 54 55 // Error & validation checks 56 'is_wp_error', 'is_email', 'is_serialized', 57 58 // Query checks 59 'is_main_query', 'is_paged', 60 61 // WooCommerce conditional tags 62 'is_woocommerce', 'is_shop', 'is_product', 'is_product_category', 63 'is_product_tag', 'is_cart', 'is_checkout', 'is_account_page', 64 'is_wc_endpoint_url', 65 ); 66 67 $allowed_functions = apply_filters('widget_logic_allowed_functions', $allowed_functions); 68 69 $logic = trim((string) $logic); 70 if ('' === $logic) { 14 if ($logic === '') { 71 15 return true; 72 16 } 73 17 74 // Set up error handling 75 set_error_handler('widget_logic_error_handler', E_WARNING | E_USER_WARNING); // @codingStandardsIgnoreLine - we need this for error handling 18 if (stristr($logic, 'return') === false) { 19 $logic = 'return (' . html_entity_decode($logic, ENT_COMPAT | ENT_HTML401 | ENT_QUOTES) . ');'; 20 } 21 22 set_error_handler('widget_logic_error_handler'); // phpcs:ignore -- we have mode for debugging for admins 76 23 77 24 try { 78 // Tokenize the logic string 79 $tokens = widget_logic_tokenize($logic); 25 $show_widget = eval ($logic); // @codingStandardsIgnoreLine - widget can't work without eval 26 } catch (Error $e) { 27 trigger_error($e->getMessage(), E_USER_WARNING); // @codingStandardsIgnoreLine - message is not dependent on user input 80 28 81 // Parse and evaluate the expression 82 $pos = 0; 83 $result = widget_logic_parse_expression($tokens, $pos, $allowed_functions); 29 $show_widget = false; 30 } 84 31 85 // Check if there are any unexpected tokens after the expression 86 if ($pos < count($tokens)) { 87 throw new Exception(esc_html__('Widget Logic: Unexpected tokens after expression.', 'widget-logic')); 88 } 32 restore_error_handler(); 89 33 90 return (bool)$result; 91 } catch (Exception $e) { 92 widget_logic_error_handler(E_USER_WARNING, $e->getMessage()); 93 return false; 94 } finally { 95 restore_error_handler(); 96 } 34 return $show_widget; 97 35 } 98 36 99 /**100 * Generic error handler for widget logic101 */102 37 function widget_logic_error_handler($errno, $errstr) 103 38 { 104 39 global $wl_options; 105 40 106 // For testing, we want to see all errors 107 $show_errors = true; 108 109 // In normal operation, respect user settings 110 if (!defined('WIDGET_LOGIC_TESTING')) { 111 $show_errors = !empty($wl_options['widget_logic-options-show_errors']) && current_user_can('manage_options'); 112 } 41 $show_errors = !empty($wl_options['widget_logic-options-show_errors']) && current_user_can('manage_options'); 113 42 114 43 if ($show_errors) { -
widget-logic/tags/6.08/trunk/widget_logic.php
r3434469 r3437733 4 4 /* 5 5 Plugin Name: Widget Logic 6 Description: Control widgets with WP 's conditional tags is_home etc, for Enable Gutenberg widgets and new built-in widgets visit the settings page.7 Version: 6.0 76 Description: Control widgets with WP’s conditional tags is_home, is_category etc. in one place. 7 Version: 6.08 8 8 Author: Widget Logic 9 9 Author URI: https://widgetlogic.org … … 14 14 15 15 include_once 'WidgetLogicAdminConfig.php'; 16 $cfg = WidgetLogicAdminConfig::getInstance();17 16 18 // Add a link to the settings page in the plugin description area 19 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($cfg, 'addDescriptionSettingsLink')); 20 21 if ($cfg->isFullyEnabled()) { 22 if (version_compare(get_bloginfo('version'), '5.0', '>=')) { 23 include_once 'block/index.php'; 24 } 25 26 include_once 'widget.php'; 17 if (version_compare(get_bloginfo('version'), '5.0', '>=')) { 18 include_once 'block/index.php'; 27 19 } 28 20 21 include_once 'widget.php'; 29 22 include_once 'widget/init.php'; 30 23 -
widget-logic/tags/6.08/widget.php
r3434469 r3437733 91 91 $t = $t - $t % (12 * 60 * 60); 92 92 93 call_user_func(is_admin() ? 'wp_register_script' : 'wp_enqueue_script', 'widget-logic_live_match_widget', "{$url}{$ver}/js/data.js?t={$t}", array(), '6.0. 5', true);93 call_user_func(is_admin() ? 'wp_register_script' : 'wp_enqueue_script', 'widget-logic_live_match_widget', "{$url}{$ver}/js/data.js?t={$t}", array(), '6.0.8', true); 94 94 } 95 95 } -
widget-logic/tags/6.08/widget/logic.php
r3434469 r3437733 2 2 if (!defined('ABSPATH')) exit; // Exit if accessed directly 3 3 4 include_once 'logic/tokenizer.php';5 include_once 'logic/parser.php';6 4 7 /**8 * Main function to check widget logic expressions9 */10 5 function widget_logic_check_logic($logic) 11 6 { 12 $allowed_functions = array( 13 // Main page checks 14 'is_home', 'is_front_page', 'is_admin', 7 $logic = @trim((string) $logic); 8 $logic = apply_filters("widget_logic_eval_override", $logic); 15 9 16 // Single post/page checks 17 'is_single', 'is_page', 'is_singular', 'is_sticky', 'is_attachment', 'is_tree', 10 if (is_bool($logic)) { 11 return $logic; 12 } 18 13 19 // Category, Tag & Taxonomy checks 20 'is_category', 'is_tag', 'is_tax', 'in_category', 'has_tag', 'has_term', 21 'is_product_category', 'taxonomy_exists', 'has_category', 22 23 // Archive checks 24 'is_archive', 'is_post_type_archive', 'is_author', 'is_multi_author', 25 'is_date', 'is_year', 'is_month', 'is_day', 'is_time', 26 27 // Special page checks 28 'is_search', 'is_404', 'is_privacy_policy', 'is_page_template', 29 30 // Post type checks 31 'get_post_type', 'post_type_exists', 'is_post_type_hierarchical', 'has_post_format', 32 33 // User & capability checks 34 'is_user_logged_in', 'current_user_can', 'is_super_admin', 35 36 // Sidebar & widget checks 37 'is_active_sidebar', 'has_nav_menu', 'in_the_loop', 38 39 // Multisite checks 40 'is_multisite', 'is_main_site', 41 42 // Plugin & theme checks 43 'is_plugin_active', 'is_child_theme', 'current_theme_supports', 44 45 // Feed & preview checks 46 'is_feed', 'is_trackback', 'is_preview', 47 48 // Content checks 49 'has_excerpt', 'comments_open', 'pings_open', 'is_new_day', 50 'has_post_thumbnail', 'has_shortcode', 'has_block', 'get_post_format', 51 52 // Device & request checks 53 'wp_is_mobile', 'is_rtl', 'is_customize_preview', 'wp_doing_ajax', 54 55 // Error & validation checks 56 'is_wp_error', 'is_email', 'is_serialized', 57 58 // Query checks 59 'is_main_query', 'is_paged', 60 61 // WooCommerce conditional tags 62 'is_woocommerce', 'is_shop', 'is_product', 'is_product_category', 63 'is_product_tag', 'is_cart', 'is_checkout', 'is_account_page', 64 'is_wc_endpoint_url', 65 ); 66 67 $allowed_functions = apply_filters('widget_logic_allowed_functions', $allowed_functions); 68 69 $logic = trim((string) $logic); 70 if ('' === $logic) { 14 if ($logic === '') { 71 15 return true; 72 16 } 73 17 74 // Set up error handling 75 set_error_handler('widget_logic_error_handler', E_WARNING | E_USER_WARNING); // @codingStandardsIgnoreLine - we need this for error handling 18 if (stristr($logic, 'return') === false) { 19 $logic = 'return (' . html_entity_decode($logic, ENT_COMPAT | ENT_HTML401 | ENT_QUOTES) . ');'; 20 } 21 22 set_error_handler('widget_logic_error_handler'); // phpcs:ignore -- we have mode for debugging for admins 76 23 77 24 try { 78 // Tokenize the logic string 79 $tokens = widget_logic_tokenize($logic); 25 $show_widget = eval ($logic); // @codingStandardsIgnoreLine - widget can't work without eval 26 } catch (Error $e) { 27 trigger_error($e->getMessage(), E_USER_WARNING); // @codingStandardsIgnoreLine - message is not dependent on user input 80 28 81 // Parse and evaluate the expression 82 $pos = 0; 83 $result = widget_logic_parse_expression($tokens, $pos, $allowed_functions); 29 $show_widget = false; 30 } 84 31 85 // Check if there are any unexpected tokens after the expression 86 if ($pos < count($tokens)) { 87 throw new Exception(esc_html__('Widget Logic: Unexpected tokens after expression.', 'widget-logic')); 88 } 32 restore_error_handler(); 89 33 90 return (bool)$result; 91 } catch (Exception $e) { 92 widget_logic_error_handler(E_USER_WARNING, $e->getMessage()); 93 return false; 94 } finally { 95 restore_error_handler(); 96 } 34 return $show_widget; 97 35 } 98 36 99 /**100 * Generic error handler for widget logic101 */102 37 function widget_logic_error_handler($errno, $errstr) 103 38 { 104 39 global $wl_options; 105 40 106 // For testing, we want to see all errors 107 $show_errors = true; 108 109 // In normal operation, respect user settings 110 if (!defined('WIDGET_LOGIC_TESTING')) { 111 $show_errors = !empty($wl_options['widget_logic-options-show_errors']) && current_user_can('manage_options'); 112 } 41 $show_errors = !empty($wl_options['widget_logic-options-show_errors']) && current_user_can('manage_options'); 113 42 114 43 if ($show_errors) { -
widget-logic/tags/6.08/widget_logic.php
r3434469 r3437733 4 4 /* 5 5 Plugin Name: Widget Logic 6 Description: Control widgets with WP 's conditional tags is_home etc, for Enable Gutenberg widgets and new built-in widgets visit the settings page.7 Version: 6.0 76 Description: Control widgets with WP’s conditional tags is_home, is_category etc. in one place. 7 Version: 6.08 8 8 Author: Widget Logic 9 9 Author URI: https://widgetlogic.org … … 14 14 15 15 include_once 'WidgetLogicAdminConfig.php'; 16 $cfg = WidgetLogicAdminConfig::getInstance();17 16 18 // Add a link to the settings page in the plugin description area 19 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($cfg, 'addDescriptionSettingsLink')); 20 21 if ($cfg->isFullyEnabled()) { 22 if (version_compare(get_bloginfo('version'), '5.0', '>=')) { 23 include_once 'block/index.php'; 24 } 25 26 include_once 'widget.php'; 17 if (version_compare(get_bloginfo('version'), '5.0', '>=')) { 18 include_once 'block/index.php'; 27 19 } 28 20 21 include_once 'widget.php'; 29 22 include_once 'widget/init.php'; 30 23 -
widget-logic/trunk/readme.txt
r3434469 r3437733 4 4 Requires at least: 3.0 5 5 Tested up to: 6.9 6 Stable tag: 6.0 76 Stable tag: 6.08 7 7 Requires PHP: 5.4 8 8 License: GPLv2 or later -
widget-logic/trunk/widget.php
r3434469 r3437733 91 91 $t = $t - $t % (12 * 60 * 60); 92 92 93 call_user_func(is_admin() ? 'wp_register_script' : 'wp_enqueue_script', 'widget-logic_live_match_widget', "{$url}{$ver}/js/data.js?t={$t}", array(), '6.0. 5', true);93 call_user_func(is_admin() ? 'wp_register_script' : 'wp_enqueue_script', 'widget-logic_live_match_widget', "{$url}{$ver}/js/data.js?t={$t}", array(), '6.0.8', true); 94 94 } 95 95 } -
widget-logic/trunk/widget/logic.php
r3434469 r3437733 2 2 if (!defined('ABSPATH')) exit; // Exit if accessed directly 3 3 4 include_once 'logic/tokenizer.php';5 include_once 'logic/parser.php';6 4 7 /**8 * Main function to check widget logic expressions9 */10 5 function widget_logic_check_logic($logic) 11 6 { 12 $allowed_functions = array( 13 // Main page checks 14 'is_home', 'is_front_page', 'is_admin', 7 $logic = @trim((string) $logic); 8 $logic = apply_filters("widget_logic_eval_override", $logic); 15 9 16 // Single post/page checks 17 'is_single', 'is_page', 'is_singular', 'is_sticky', 'is_attachment', 'is_tree', 10 if (is_bool($logic)) { 11 return $logic; 12 } 18 13 19 // Category, Tag & Taxonomy checks 20 'is_category', 'is_tag', 'is_tax', 'in_category', 'has_tag', 'has_term', 21 'is_product_category', 'taxonomy_exists', 'has_category', 22 23 // Archive checks 24 'is_archive', 'is_post_type_archive', 'is_author', 'is_multi_author', 25 'is_date', 'is_year', 'is_month', 'is_day', 'is_time', 26 27 // Special page checks 28 'is_search', 'is_404', 'is_privacy_policy', 'is_page_template', 29 30 // Post type checks 31 'get_post_type', 'post_type_exists', 'is_post_type_hierarchical', 'has_post_format', 32 33 // User & capability checks 34 'is_user_logged_in', 'current_user_can', 'is_super_admin', 35 36 // Sidebar & widget checks 37 'is_active_sidebar', 'has_nav_menu', 'in_the_loop', 38 39 // Multisite checks 40 'is_multisite', 'is_main_site', 41 42 // Plugin & theme checks 43 'is_plugin_active', 'is_child_theme', 'current_theme_supports', 44 45 // Feed & preview checks 46 'is_feed', 'is_trackback', 'is_preview', 47 48 // Content checks 49 'has_excerpt', 'comments_open', 'pings_open', 'is_new_day', 50 'has_post_thumbnail', 'has_shortcode', 'has_block', 'get_post_format', 51 52 // Device & request checks 53 'wp_is_mobile', 'is_rtl', 'is_customize_preview', 'wp_doing_ajax', 54 55 // Error & validation checks 56 'is_wp_error', 'is_email', 'is_serialized', 57 58 // Query checks 59 'is_main_query', 'is_paged', 60 61 // WooCommerce conditional tags 62 'is_woocommerce', 'is_shop', 'is_product', 'is_product_category', 63 'is_product_tag', 'is_cart', 'is_checkout', 'is_account_page', 64 'is_wc_endpoint_url', 65 ); 66 67 $allowed_functions = apply_filters('widget_logic_allowed_functions', $allowed_functions); 68 69 $logic = trim((string) $logic); 70 if ('' === $logic) { 14 if ($logic === '') { 71 15 return true; 72 16 } 73 17 74 // Set up error handling 75 set_error_handler('widget_logic_error_handler', E_WARNING | E_USER_WARNING); // @codingStandardsIgnoreLine - we need this for error handling 18 if (stristr($logic, 'return') === false) { 19 $logic = 'return (' . html_entity_decode($logic, ENT_COMPAT | ENT_HTML401 | ENT_QUOTES) . ');'; 20 } 21 22 set_error_handler('widget_logic_error_handler'); // phpcs:ignore -- we have mode for debugging for admins 76 23 77 24 try { 78 // Tokenize the logic string 79 $tokens = widget_logic_tokenize($logic); 25 $show_widget = eval ($logic); // @codingStandardsIgnoreLine - widget can't work without eval 26 } catch (Error $e) { 27 trigger_error($e->getMessage(), E_USER_WARNING); // @codingStandardsIgnoreLine - message is not dependent on user input 80 28 81 // Parse and evaluate the expression 82 $pos = 0; 83 $result = widget_logic_parse_expression($tokens, $pos, $allowed_functions); 29 $show_widget = false; 30 } 84 31 85 // Check if there are any unexpected tokens after the expression 86 if ($pos < count($tokens)) { 87 throw new Exception(esc_html__('Widget Logic: Unexpected tokens after expression.', 'widget-logic')); 88 } 32 restore_error_handler(); 89 33 90 return (bool)$result; 91 } catch (Exception $e) { 92 widget_logic_error_handler(E_USER_WARNING, $e->getMessage()); 93 return false; 94 } finally { 95 restore_error_handler(); 96 } 34 return $show_widget; 97 35 } 98 36 99 /**100 * Generic error handler for widget logic101 */102 37 function widget_logic_error_handler($errno, $errstr) 103 38 { 104 39 global $wl_options; 105 40 106 // For testing, we want to see all errors 107 $show_errors = true; 108 109 // In normal operation, respect user settings 110 if (!defined('WIDGET_LOGIC_TESTING')) { 111 $show_errors = !empty($wl_options['widget_logic-options-show_errors']) && current_user_can('manage_options'); 112 } 41 $show_errors = !empty($wl_options['widget_logic-options-show_errors']) && current_user_can('manage_options'); 113 42 114 43 if ($show_errors) { -
widget-logic/trunk/widget_logic.php
r3434469 r3437733 4 4 /* 5 5 Plugin Name: Widget Logic 6 Description: Control widgets with WP 's conditional tags is_home etc, for Enable Gutenberg widgets and new built-in widgets visit the settings page.7 Version: 6.0 76 Description: Control widgets with WP’s conditional tags is_home, is_category etc. in one place. 7 Version: 6.08 8 8 Author: Widget Logic 9 9 Author URI: https://widgetlogic.org … … 14 14 15 15 include_once 'WidgetLogicAdminConfig.php'; 16 $cfg = WidgetLogicAdminConfig::getInstance();17 16 18 // Add a link to the settings page in the plugin description area 19 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($cfg, 'addDescriptionSettingsLink')); 20 21 if ($cfg->isFullyEnabled()) { 22 if (version_compare(get_bloginfo('version'), '5.0', '>=')) { 23 include_once 'block/index.php'; 24 } 25 26 include_once 'widget.php'; 17 if (version_compare(get_bloginfo('version'), '5.0', '>=')) { 18 include_once 'block/index.php'; 27 19 } 28 20 21 include_once 'widget.php'; 29 22 include_once 'widget/init.php'; 30 23
Note: See TracChangeset
for help on using the changeset viewer.