Changeset 3434469
- Timestamp:
- 01/07/2026 03:33:10 PM (2 months ago)
- Location:
- widget-logic
- Files:
-
- 27 edited
- 20 copied
-
tags/6.07 (copied) (copied from widget-logic/trunk)
-
tags/6.07/WidgetLogicAdminConfig.php (copied) (copied from widget-logic/trunk/WidgetLogicAdminConfig.php) (10 diffs)
-
tags/6.07/block (copied) (copied from widget-logic/trunk/block)
-
tags/6.07/block/index.php (copied) (copied from widget-logic/trunk/block/index.php)
-
tags/6.07/block_widget (copied) (copied from widget-logic/trunk/block_widget)
-
tags/6.07/block_widget/block.json (copied) (copied from widget-logic/trunk/block_widget/block.json)
-
tags/6.07/block_widget/index.php (copied) (copied from widget-logic/trunk/block_widget/index.php) (1 diff)
-
tags/6.07/block_widget/js/widget.js (copied) (copied from widget-logic/trunk/block_widget/js/widget.js)
-
tags/6.07/block_widget/preview.png (copied) (copied from widget-logic/trunk/block_widget/preview.png)
-
tags/6.07/readme.txt (copied) (copied from widget-logic/trunk/readme.txt) (4 diffs)
-
tags/6.07/widget (copied) (copied from widget-logic/trunk/widget)
-
tags/6.07/widget.php (copied) (copied from widget-logic/trunk/widget.php) (6 diffs)
-
tags/6.07/widget/admin.php (copied) (copied from widget-logic/trunk/widget/admin.php) (8 diffs)
-
tags/6.07/widget/config.php (copied) (copied from widget-logic/trunk/widget/config.php)
-
tags/6.07/widget/init.php (copied) (copied from widget-logic/trunk/widget/init.php) (1 diff)
-
tags/6.07/widget/logic (copied) (copied from widget-logic/trunk/widget/logic)
-
tags/6.07/widget/logic.php (copied) (copied from widget-logic/trunk/widget/logic.php) (3 diffs)
-
tags/6.07/widget/logic/array/is_array.php (modified) (1 diff)
-
tags/6.07/widget/logic/array/key.php (modified) (1 diff)
-
tags/6.07/widget/logic/array/main_array.php (modified) (4 diffs)
-
tags/6.07/widget/logic/array/tokenize_array.php (modified) (1 diff)
-
tags/6.07/widget/logic/array/value/string.php (modified) (2 diffs)
-
tags/6.07/widget/logic/function/is_function.php (modified) (1 diff)
-
tags/6.07/widget/logic/function/main_function.php (modified) (1 diff)
-
tags/6.07/widget/logic/parser.php (modified) (2 diffs)
-
tags/6.07/widget/logic/tokenizer.php (modified) (2 diffs)
-
tags/6.07/widget/test-widget-logic.php (copied) (copied from widget-logic/trunk/widget/test-widget-logic.php)
-
tags/6.07/widget_cfg.php (copied) (copied from widget-logic/trunk/widget_cfg.php) (2 diffs)
-
tags/6.07/widget_logic.php (copied) (copied from widget-logic/trunk/widget_logic.php) (2 diffs)
-
trunk/WidgetLogicAdminConfig.php (modified) (10 diffs)
-
trunk/block_widget/index.php (modified) (1 diff)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/widget.php (modified) (6 diffs)
-
trunk/widget/admin.php (modified) (8 diffs)
-
trunk/widget/init.php (modified) (1 diff)
-
trunk/widget/logic.php (modified) (3 diffs)
-
trunk/widget/logic/array/is_array.php (modified) (1 diff)
-
trunk/widget/logic/array/key.php (modified) (1 diff)
-
trunk/widget/logic/array/main_array.php (modified) (4 diffs)
-
trunk/widget/logic/array/tokenize_array.php (modified) (1 diff)
-
trunk/widget/logic/array/value/string.php (modified) (2 diffs)
-
trunk/widget/logic/function/is_function.php (modified) (1 diff)
-
trunk/widget/logic/function/main_function.php (modified) (1 diff)
-
trunk/widget/logic/parser.php (modified) (2 diffs)
-
trunk/widget/logic/tokenizer.php (modified) (2 diffs)
-
trunk/widget_cfg.php (modified) (2 diffs)
-
trunk/widget_logic.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
widget-logic/tags/6.07/WidgetLogicAdminConfig.php
r3254708 r3434469 1 1 <?php 2 if ( ! defined( 'ABSPATH' )) exit; // Exit if accessed directly2 if (!defined('ABSPATH')) exit; // Exit if accessed directly 3 3 4 4 class WidgetLogicAdminConfig … … 9 9 protected $options; 10 10 11 public static function getInstance() {12 11 public static function getInstance() 12 { 13 13 if (null == self::$instance) { 14 14 self::$instance = new self; … … 16 16 17 17 return self::$instance; 18 19 18 } 20 19 21 private function __construct() {22 20 private function __construct() 21 { 23 22 // Add the page to the admin menu 24 23 add_action('admin_menu', array(&$this, 'addPage')); … … 29 28 // Get registered option 30 29 $this->options = get_option('widget_logic_settings_options'); 31 32 30 } 33 31 … … 37 35 } 38 36 39 public function addDescriptionSettingsLink($links) { 37 public function addDescriptionSettingsLink($links) 38 { 40 39 if ($this->isFullyEnabled()) { 41 40 return $links; … … 49 48 } 50 49 51 public function addPage() { 50 public function addPage() 51 { 52 52 add_options_page('Theme Options', 'Widget Logic', 'manage_options', 'widget-logic', array($this, 'displayPage')); 53 53 } 54 54 55 public function displayPage() { 55 public function displayPage() 56 { 56 57 ?> 57 58 <div class='wrap'> … … 86 87 } 87 88 88 public function registerPageOptions() { 89 public function registerPageOptions() 90 { 89 91 // Add Section for option fields 90 92 add_settings_section('widget_logic_section', '', array($this, 'displaySection'), __FILE__); … … 95 97 } 96 98 97 public function validateOptions($fields) { 99 public function validateOptions($fields) 100 { 98 101 $valid_fields = array(); 99 102 … … 104 107 } 105 108 106 public function displaySection() { /* Leave blank */ } 109 public function displaySection() 110 { 111 /* Leave blank */ 112 } 107 113 108 114 protected function getFullyEnabledValue() … … 111 117 } 112 118 113 public function isEnabledSettingsField() { 119 public function isEnabledSettingsField() 120 { 114 121 $val = $this->getFullyEnabledValue(); 115 122 116 $selected_one =array(self::ON => '', self::OFF => '');123 $selected_one = array(self::ON => '', self::OFF => ''); 117 124 $selected_one[$val] = 'selected="selected"'; 118 125 echo " 119 126 <div> 120 127 <select name='widget_logic_settings_options[widget_logic_is_fully_enabled]'> 121 <option value='" .esc_attr(self::OFF)."' ". esc_html($selected_one[self::OFF]) .">Disabled</option>122 <option value='" .esc_attr(self::ON)."' ". esc_html($selected_one[self::ON]) .">Enabled</option>128 <option value='" . esc_attr(self::OFF) . "' " . esc_html($selected_one[self::OFF]) . ">Disabled</option> 129 <option value='" . esc_attr(self::ON) . "' " . esc_html($selected_one[self::ON]) . ">Enabled</option> 123 130 </select> 124 131 </div> -
widget-logic/tags/6.07/block_widget/index.php
r3259805 r3434469 3 3 if (!defined('ABSPATH')) exit; 4 4 5 function widget_logic_register_block() { 5 function widget_logic_register_block() 6 { 6 7 register_logic_live_match_widget_service(); 7 8 register_block_type(__DIR__ . '/block.json'); -
widget-logic/tags/6.07/readme.txt
r3329843 r3434469 3 3 Tags: widget, sidebar, conditional tags, blocks, gutenberg widgets 4 4 Requires at least: 3.0 5 Tested up to: 6. 86 Stable tag: 6.0 .65 Tested up to: 6.9 6 Stable tag: 6.07 7 7 Requires PHP: 5.4 8 8 License: GPLv2 or later … … 23 23 24 24 * Pre-installed widgets let you add special widget with one click of the mouse. First pre-installed widget is Live Match that let you add widget of one random live football game with real time score updates (teams logos, livescore, minute of the match, tournament name). And more interesting widgets to come! 25 26 **NOTE ON DEFAULT FUNCTIONS:** Widget Logic includes a whitelist of common WordPress conditional tags and safe functions. If you need additional WordPress functions that are not currently whitelisted, please create a topic in our [support forum](https://wordpress.org/support/plugin/widget-logic/) to request them. We regularly add commonly requested functions in new releases. 25 27 26 28 … … 41 43 * Don't cache widget logic results -- From v .58 the widget logic code should only execute once, but that might cause unexpected results with some themes, so this option is here to turn that behaviour off. (The truth/false of the code will be evaluated every time the sidebars_widgets filter is called. 42 44 45 * Custom PHP Functions -- From v.6.0.6 you can use the `widget_logic_allowed_functions` filter to add custom PHP functions that will be allowed in Widget Logic fields. By default, only WordPress conditional tags and a whitelist of safe functions are available. This filter allows you to extend the functionality and use your own custom functions. 46 47 To add a custom function, add the following code to your theme's `functions.php` file: 48 `add_filter('widget_logic_allowed_functions', 'my_allowed_functions'); 49 function my_allowed_functions($functions) { 50 $functions[] = '_my_custom_function_name_'; 51 return $functions; 52 }` 53 54 You can add multiple functions by using one wrapper function: 55 `add_filter('widget_logic_allowed_functions', 'my_allowed_functions'); 56 function my_allowed_functions($functions) { 57 $functions[] = 'is_special_page'; 58 $functions[] = 'is_user_verified'; 59 $functions[] = 'get_sidebar_title'; 60 return $functions; 61 }` 62 63 **IMPORTANT NOTE ON VARIABLES:** Widget Logic is designed to work with simple data types (strings, numbers, booleans). If you need to use complex variables, global state, or conditional logic that depends on many factors, create a custom function in your theme's `functions.php` file and call it from Widget Logic: 64 65 **Good approach (in functions.php):** 66 `function is_special_page() { 67 global $post; 68 $special_ids = array(5, 10, 15); 69 $conditions = some_complex_function(); 70 71 return is_page() && in_array($post->ID, $special_ids) && $conditions; 72 }` 73 74 Then in Widget Logic field, simply use: `is_special_page()` 75 76 **Less ideal approach (in Widget Logic field):** 77 Avoid putting complex logic directly in the Widget Logic field. Keep it simple and let your custom function handle the complexity. This keeps your widget settings clean and maintainable. 78 43 79 = Interaction with External Services = 44 80 … … 125 161 126 162 == Changelog == 163 164 = 6.0.7 = 165 166 * Enhanced Configuration section with detailed documentation for `widget_logic_allowed_functions` filter 167 * Added examples for adding custom functions to Widget Logic 168 * Added best practices guide for using variables with custom functions 169 * Improved documentation on separating complex logic from Widget Logic fields 170 * added support for more WordPress functions in the allowed functions in that account added: 171 - is_product_category 172 - has_category 173 - etc... 127 174 128 175 = 6.0.6 = -
widget-logic/tags/6.07/widget.php
r3259805 r3434469 7 7 * Sets up the widgets name etc 8 8 */ 9 public function __construct() { 9 public function __construct() 10 { 10 11 $widget_ops = array( 11 12 'classname' => 'live_match_widget', … … 21 22 * @param array $instance 22 23 */ 23 public function widget($args, $instance) { 24 public function widget($args, $instance) 25 { 24 26 $defaults = array( 25 'title' => esc_html__('Live Match', 'widget-logic')26 );27 $instance = wp_parse_args( (array) $instance, $defaults);28 $title = apply_filters( 'widget_title', $instance['title']);27 'title' => esc_html__('Live Match', 'widget-logic') 28 ); 29 $instance = wp_parse_args((array) $instance, $defaults); 30 $title = apply_filters('widget_title', $instance['title']); 29 31 ?> 30 32 31 33 <?php echo $args['before_widget']; // @codingStandardsIgnoreLine here I can't escape output because other widgets will be damaged (example from https://developer.wordpress.org/reference/classes/wp_widget_search/widget/) ?> 32 34 <div class="live_match_widget"> 33 <?php if ( $title) { ?>34 <div class="live_match_widget_header"><?php echo $args['before_title'] . esc_html( $title ) . $args['after_title']; // @codingStandardsIgnoreLine here I can't escape output $args['before_title'] and $args['after_title'] because other functionality will be damaged (example from https://developer.wordpress.org/reference/classes/wp_widget_search/widget/)?></div>35 <?php } ?>36 <div class="live_match_widget_div">37 <div data-place="widget-live-match">Live Match will be here</div>38 </div>35 <?php if ($title) { ?> 36 <div class="live_match_widget_header"><?php echo $args['before_title'] . esc_html($title) . $args['after_title']; // @codingStandardsIgnoreLine here I can't escape output $args['before_title'] and $args['after_title'] because other functionality will be damaged (example from https://developer.wordpress.org/reference/classes/wp_widget_search/widget/) ?></div> 37 <?php } ?> 38 <div class="live_match_widget_div"> 39 <div data-place="widget-live-match">Live Match will be here</div> 40 </div> 39 41 </div> 40 42 <?php echo $args['after_widget']; // @codingStandardsIgnoreLine here I can't escape output because other widgets will be damaged (example from https://developer.wordpress.org/reference/classes/wp_widget_search/widget/) 41 wp_enqueue_script( 'widget-logic_live_match_widget');43 wp_enqueue_script('widget-logic_live_match_widget'); 42 44 } 43 45 … … 47 49 * @param array $instance The widget options 48 50 */ 49 public function form($instance) { 51 public function form($instance) 52 { 50 53 $defaults = array( 51 'title' => esc_html__( 'Live Match', 'widget-logic')52 );53 $instance = wp_parse_args( (array) $instance, $defaults);54 'title' => esc_html__('Live Match', 'widget-logic') 55 ); 56 $instance = wp_parse_args((array) $instance, $defaults); 54 57 55 $title = esc_attr( $instance['title']);58 $title = esc_attr($instance['title']); 56 59 ?> 57 <p><label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php esc_html_e( 'Title:', 'widget-logic'); ?></label>58 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" type="text" value="<?php echo esc_attr( $title); ?>" /></p>59 <?php60 <p><label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:', 'widget-logic'); ?></label> 61 <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> 62 <?php 60 63 } 61 64 … … 68 71 * @return array 69 72 */ 70 public function update($new_instance, $old_instance) { 73 public function update($new_instance, $old_instance) 74 { 71 75 $instance = $old_instance; 72 76 … … 77 81 } 78 82 79 function register_logic_live_match_widget_service() { 83 function register_logic_live_match_widget_service() 84 { 80 85 // Check if the script is already registered 81 if ( !wp_script_is('widget-logic_live_match_widget', 'registered')) {82 $cfg = require('widget_cfg.php');83 $url = $cfg['base'];84 $ver = $cfg['ver'];85 $t = time();86 $t = $t - $t % (12 * 60 * 60);86 if (!wp_script_is('widget-logic_live_match_widget', 'registered')) { 87 $cfg = require('widget_cfg.php'); 88 $url = $cfg['base']; 89 $ver = $cfg['ver']; 90 $t = time(); 91 $t = $t - $t % (12 * 60 * 60); 87 92 88 wp_register_script('widget-logic_live_match_widget', "{$url}{$ver}/js/data.js?t={$t}", array(),'6.0.5', true);89 }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); 94 } 90 95 } 91 96 … … 93 98 94 99 if (version_compare(get_bloginfo('version'), '5.0', '>=')) { 95 include_once 'block_widget/index.php';100 include_once 'block_widget/index.php'; 96 101 } else { 97 102 add_action('widgets_init', function() { 98 register_widget( 'Widget_Logic_Live_Match_Widget');103 register_widget('Widget_Logic_Live_Match_Widget'); 99 104 }); 100 105 } -
widget-logic/tags/6.07/widget/admin.php
r3254708 r3434469 51 51 echo "[START=WIDGET LOGIC OPTIONS]\n"; 52 52 foreach ($wl_options as $id => $text) { 53 echo esc_attr($id) ."\t" . wp_json_encode($text) . "\n";53 echo esc_attr($id) . "\t" . wp_json_encode($text) . "\n"; 54 54 } 55 55 echo "[STOP=WIDGET LOGIC OPTIONS]"; … … 73 73 foreach ($import as $import_option) { 74 74 list($key, $value) = explode("\t", $import_option); 75 $wl_options[$key] = json_decode($value);75 $wl_options[$key] = json_decode($value); 76 76 } 77 77 $wl_options['msg'] = __('Success! Options file imported', 'widget-logic'); … … 85 85 86 86 update_option('widget_logic', $wl_options); 87 wp_ redirect(admin_url('widgets.php'));87 wp_safe_redirect(admin_url('widgets.php')); 88 88 exit; 89 89 } … … 104 104 105 105 $wl_options['widget_logic-options-wp_reset_query'] = !empty($_POST['widget_logic-options-wp_reset_query']); 106 $wl_options['widget_logic-options-show_errors'] = !empty($_POST['widget_logic-options-show_errors']);107 $wl_options['widget_logic-options-load_point'] = sanitize_text_field(wp_unslash(isset($_POST['widget_logic-options-load_point']) ? $_POST['widget_logic-options-load_point'] : ''));106 $wl_options['widget_logic-options-show_errors'] = !empty($_POST['widget_logic-options-show_errors']); 107 $wl_options['widget_logic-options-load_point'] = sanitize_text_field(wp_unslash(isset($_POST['widget_logic-options-load_point']) ? $_POST['widget_logic-options-load_point'] : '')); 108 108 } 109 109 … … 122 122 $msgClass = $isError ? 'error' : 'updated'; 123 123 124 echo '<div id="message" class="' .esc_attr($msgClass).'"><p>Widget Logic – '.esc_html($wl_options['msg']).'</p></div>';124 echo '<div id="message" class="' . esc_attr($msgClass) . '"><p>Widget Logic – ' . esc_html($wl_options['msg']) . '</p></div>'; 125 125 unset($wl_options['msg']); 126 126 update_option('widget_logic', $wl_options); … … 170 170 <?php 171 171 $wl_load_points = array( 172 'parse_query' => __('after query variables set (default)', 'widget-logic'),173 'plugins_loaded' => __('when plugin starts', 'widget-logic'),172 'parse_query' => __('after query variables set (default)', 'widget-logic'), 173 'plugins_loaded' => __('when plugin starts', 'widget-logic'), 174 174 'after_setup_theme' => __('after theme loads', 'widget-logic'), 175 'wp_loaded' => __('when all PHP loaded', 'widget-logic'),176 'wp_head' => __('during page header', 'widget-logic')175 'wp_loaded' => __('when all PHP loaded', 'widget-logic'), 176 'wp_head' => __('during page header', 'widget-logic') 177 177 ); 178 178 foreach ($wl_load_points as $action => $action_desc) { … … 271 271 $args = func_get_args(); 272 272 273 $callback = array_pop($args);273 $callback = array_pop($args); 274 274 $widget_id = array_pop($args); 275 275 … … 290 290 } 291 291 292 $input_id = "widget-$widget_id-widget_logic";292 $input_id = "widget-$widget_id-widget_logic"; 293 293 $input_name = "widget-{$widget_id}[widget_logic]"; 294 294 ?> -
widget-logic/tags/6.07/widget/init.php
r3135406 r3434469 30 30 ob_start(); 31 31 $show_widget = widget_logic_check_logic($logic); 32 $error = ob_get_clean();32 $error = ob_get_clean(); 33 33 34 34 // Register a custom script handle -
widget-logic/tags/6.07/widget/logic.php
r3329843 r3434469 11 11 { 12 12 $allowed_functions = array( 13 'is_home', 'is_front_page', 'is_single', 'is_page', 'is_category', 14 'is_tag', 'is_archive', 'is_search', 'is_404', 'is_user_logged_in', 15 'current_user_can', 'is_active_sidebar', 'is_admin', 13 // Main page checks 14 'is_home', 'is_front_page', 'is_admin', 15 16 // Single post/page checks 17 'is_single', 'is_page', 'is_singular', 'is_sticky', 'is_attachment', 'is_tree', 18 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', 16 65 ); 17 66 … … 76 125 if (preg_match('/^(.+)-(\d+)$/', $widget_id, $m)) { 77 126 $widget_class = $m[1]; 78 $widget_i = $m[2];127 $widget_i = $m[2]; 79 128 80 129 $info = get_option('widget_' . $widget_class); … … 109 158 if (preg_match('/^(.+)-(\d+)$/', $widget_id, $m)) { 110 159 $widget_class = $m[1]; 111 $widget_i = $m[2];160 $widget_i = $m[2]; 112 161 113 162 $info = get_option('widget_' . $widget_class); -
widget-logic/tags/6.07/widget/logic/array/is_array.php
r3329843 r3434469 5 5 * Check if value uses array syntax 6 6 */ 7 function widget_logic_is_array_syntax($value) { 7 function widget_logic_is_array_syntax($value) 8 { 8 9 return (0 === strpos($value, 'array(') && ')' === substr($value, -1)) || 9 10 ('[' === substr($value, 0, 1) && ']' === substr($value, -1)); -
widget-logic/tags/6.07/widget/logic/array/key.php
r3329843 r3434469 7 7 * Process an array key with security checks 8 8 */ 9 function widget_logic_process_array_key($key, $allowed_functions) { 9 function widget_logic_process_array_key($key, $allowed_functions) 10 { 10 11 // Handle function calls in keys 11 12 if (widget_logic_is_function_call(trim($key), $matches)) { -
widget-logic/tags/6.07/widget/logic/array/main_array.php
r3329843 r3434469 9 9 * Parse array strings into actual PHP arrays with security checks 10 10 */ 11 function widget_logic_parse_array_string($array_str, $allowed_functions) { 11 function widget_logic_parse_array_string($array_str, $allowed_functions) 12 { 12 13 $array_str = trim($array_str); 13 14 … … 37 38 * Extract the inner string from array syntax 38 39 */ 39 function widget_logic_extract_array_inner($array_str) { 40 function widget_logic_extract_array_inner($array_str) 41 { 40 42 if (0 === strpos($array_str, 'array(') && ')' === substr($array_str, -1)) { 41 43 return trim(substr($array_str, 6, -1)); … … 50 52 * Process a single array element and add it to the result array 51 53 */ 52 function widget_logic_process_array_element($element, &$result, $allowed_functions) { 54 function widget_logic_process_array_element($element, &$result, $allowed_functions) 55 { 53 56 // Check if it's a key => value pair 54 57 if (preg_match('/^(.+?)=>(.+)$/s', $element, $matches)) { … … 69 72 } 70 73 71 // Helper function to split array elements, handling nested structures and quotes 72 function widget_logic_split_array_elements($str) { 74 /** 75 * Helper function to split array elements, handling nested structures and quotes 76 */ 77 function widget_logic_split_array_elements($str) 78 { 73 79 $elements = array(); 74 80 $current = ''; -
widget-logic/tags/6.07/widget/logic/array/tokenize_array.php
r3329843 r3434469 8 8 * Capture an array token from the logic string 9 9 */ 10 function widget_logic_capture_array($logic, $i, &$tokens) { 10 function widget_logic_capture_array($logic, $i, &$tokens) 11 { 11 12 $start = $i; 12 13 -
widget-logic/tags/6.07/widget/logic/array/value/string.php
r3329843 r3434469 8 8 * Check if value is a quoted string 9 9 */ 10 function widget_logic_is_quoted_string($value, &$out_string) { 10 function widget_logic_is_quoted_string($value, &$out_string) 11 { 11 12 if (('"' === substr($value, 0, 1) && '"' === substr($value, -1)) || 12 13 ("'" === substr($value, 0, 1) && "'" === substr($value, -1))) { … … 20 21 * Validate string values for security issues 21 22 */ 22 function widget_logic_validate_string_value($string_value) { 23 function widget_logic_validate_string_value($string_value) 24 { 23 25 // Check for PHP stream wrappers in strings 24 26 $dangerous_wrappers = array('php://', 'file://', 'expect://', 'data://', 'zip://', 'glob://', 'phar://'); -
widget-logic/tags/6.07/widget/logic/function/is_function.php
r3329843 r3434469 6 6 * Check if value is a function call 7 7 */ 8 function widget_logic_is_function_call($value, &$matches) { 8 function widget_logic_is_function_call($value, &$matches) 9 { 9 10 return preg_match('/^([a-zA-Z_][a-zA-Z0-9_]*)\((.*)\)$/', $value, $matches); 10 11 } -
widget-logic/tags/6.07/widget/logic/function/main_function.php
r3329843 r3434469 14 14 * @throws Exception If the function is not allowed or does not exist 15 15 */ 16 17 16 function widget_logic_handle_function_call($matches, $allowed_functions) 18 17 { -
widget-logic/tags/6.07/widget/logic/parser.php
r3329843 r3434469 42 42 } 43 43 44 // Helper function to parse AND expressions (terms connected by &&) 44 /** 45 * Helper function to parse AND expressions (terms connected by &&) 46 */ 45 47 function widget_logic_parse_and_expression(&$tokens, &$pos, $allowed_functions) 46 48 { … … 74 76 } 75 77 76 // Helper function to parse terms 78 /** 79 * Helper function to parse terms 80 */ 77 81 function widget_logic_parse_term(&$tokens, &$pos, $allowed_functions) 78 82 { -
widget-logic/tags/6.07/widget/logic/tokenizer.php
r3329843 r3434469 7 7 * Tokenize a logic expression string into an array of tokens 8 8 */ 9 function widget_logic_tokenize($logic) { 9 function widget_logic_tokenize($logic) 10 { 10 11 $tokens = []; 11 12 $i = 0; … … 50 51 * Capture a word or function call token from the logic string 51 52 */ 52 function widget_logic_capture_word_or_function($logic, $i, &$tokens) { 53 function widget_logic_capture_word_or_function($logic, $i, &$tokens) 54 { 53 55 $start = $i; 54 56 $length = strlen($logic); -
widget-logic/tags/6.07/widget_cfg.php
r3143078 r3434469 1 1 <?php 2 if ( ! defined( 'ABSPATH' )) exit; // Exit if accessed directly2 if (!defined('ABSPATH')) exit; // Exit if accessed directly 3 3 4 4 // a helper function to lookup "env_FILE", "env", then fallback, standard WP function, needed for compatibility with WP 3 5 5 if (!function_exists('getenv_docker')) { 6 function getenv_docker($env, $default) { 6 function getenv_docker($env, $default) 7 { 7 8 if ($fileEnv = getenv($env . '_FILE')) { 8 9 return rtrim(file_get_contents($fileEnv), "\r\n"); // @codingStandardsIgnoreLine 9 } 10 else if (($val = getenv($env)) !== false) { 10 } elseif (($val = getenv($env)) !== false) { 11 11 return $val; 12 } 13 else { 12 } else { 14 13 return $default; 15 14 } … … 18 17 // a helper function for development plugin 19 18 if (!function_exists('widget_logic_getServiceVersion')) { 20 function widget_logic_getServiceVersion() { 21 $ver = getenv_docker('WORDPRESS_SERVICE_WGL_VER', 'v2'); 22 return $ver ? "/{$ver}" : $ver; 23 } 19 function widget_logic_getServiceVersion() 20 { 21 $ver = getenv_docker('WORDPRESS_SERVICE_WGL_VER', 'v2'); 22 return $ver ? "/{$ver}" : $ver; 23 } 24 24 } 25 25 26 26 27 27 return array( 28 'ver' => widget_logic_getServiceVersion(),29 'base' => getenv_docker('WORDPRESS_PLUGIN_WGL_BASE_URL', 'https://widgetlogic.org')28 'ver' => widget_logic_getServiceVersion(), 29 'base' => getenv_docker('WORDPRESS_PLUGIN_WGL_BASE_URL', 'https://widgetlogic.org') 30 30 ); -
widget-logic/tags/6.07/widget_logic.php
r3329843 r3434469 5 5 Plugin Name: Widget Logic 6 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 .67 Version: 6.07 8 8 Author: Widget Logic 9 9 Author URI: https://widgetlogic.org … … 17 17 18 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'));19 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($cfg, 'addDescriptionSettingsLink')); 20 20 21 21 if ($cfg->isFullyEnabled()) { -
widget-logic/trunk/WidgetLogicAdminConfig.php
r3254708 r3434469 1 1 <?php 2 if ( ! defined( 'ABSPATH' )) exit; // Exit if accessed directly2 if (!defined('ABSPATH')) exit; // Exit if accessed directly 3 3 4 4 class WidgetLogicAdminConfig … … 9 9 protected $options; 10 10 11 public static function getInstance() {12 11 public static function getInstance() 12 { 13 13 if (null == self::$instance) { 14 14 self::$instance = new self; … … 16 16 17 17 return self::$instance; 18 19 18 } 20 19 21 private function __construct() {22 20 private function __construct() 21 { 23 22 // Add the page to the admin menu 24 23 add_action('admin_menu', array(&$this, 'addPage')); … … 29 28 // Get registered option 30 29 $this->options = get_option('widget_logic_settings_options'); 31 32 30 } 33 31 … … 37 35 } 38 36 39 public function addDescriptionSettingsLink($links) { 37 public function addDescriptionSettingsLink($links) 38 { 40 39 if ($this->isFullyEnabled()) { 41 40 return $links; … … 49 48 } 50 49 51 public function addPage() { 50 public function addPage() 51 { 52 52 add_options_page('Theme Options', 'Widget Logic', 'manage_options', 'widget-logic', array($this, 'displayPage')); 53 53 } 54 54 55 public function displayPage() { 55 public function displayPage() 56 { 56 57 ?> 57 58 <div class='wrap'> … … 86 87 } 87 88 88 public function registerPageOptions() { 89 public function registerPageOptions() 90 { 89 91 // Add Section for option fields 90 92 add_settings_section('widget_logic_section', '', array($this, 'displaySection'), __FILE__); … … 95 97 } 96 98 97 public function validateOptions($fields) { 99 public function validateOptions($fields) 100 { 98 101 $valid_fields = array(); 99 102 … … 104 107 } 105 108 106 public function displaySection() { /* Leave blank */ } 109 public function displaySection() 110 { 111 /* Leave blank */ 112 } 107 113 108 114 protected function getFullyEnabledValue() … … 111 117 } 112 118 113 public function isEnabledSettingsField() { 119 public function isEnabledSettingsField() 120 { 114 121 $val = $this->getFullyEnabledValue(); 115 122 116 $selected_one =array(self::ON => '', self::OFF => '');123 $selected_one = array(self::ON => '', self::OFF => ''); 117 124 $selected_one[$val] = 'selected="selected"'; 118 125 echo " 119 126 <div> 120 127 <select name='widget_logic_settings_options[widget_logic_is_fully_enabled]'> 121 <option value='" .esc_attr(self::OFF)."' ". esc_html($selected_one[self::OFF]) .">Disabled</option>122 <option value='" .esc_attr(self::ON)."' ". esc_html($selected_one[self::ON]) .">Enabled</option>128 <option value='" . esc_attr(self::OFF) . "' " . esc_html($selected_one[self::OFF]) . ">Disabled</option> 129 <option value='" . esc_attr(self::ON) . "' " . esc_html($selected_one[self::ON]) . ">Enabled</option> 123 130 </select> 124 131 </div> -
widget-logic/trunk/block_widget/index.php
r3259805 r3434469 3 3 if (!defined('ABSPATH')) exit; 4 4 5 function widget_logic_register_block() { 5 function widget_logic_register_block() 6 { 6 7 register_logic_live_match_widget_service(); 7 8 register_block_type(__DIR__ . '/block.json'); -
widget-logic/trunk/readme.txt
r3329843 r3434469 3 3 Tags: widget, sidebar, conditional tags, blocks, gutenberg widgets 4 4 Requires at least: 3.0 5 Tested up to: 6. 86 Stable tag: 6.0 .65 Tested up to: 6.9 6 Stable tag: 6.07 7 7 Requires PHP: 5.4 8 8 License: GPLv2 or later … … 23 23 24 24 * Pre-installed widgets let you add special widget with one click of the mouse. First pre-installed widget is Live Match that let you add widget of one random live football game with real time score updates (teams logos, livescore, minute of the match, tournament name). And more interesting widgets to come! 25 26 **NOTE ON DEFAULT FUNCTIONS:** Widget Logic includes a whitelist of common WordPress conditional tags and safe functions. If you need additional WordPress functions that are not currently whitelisted, please create a topic in our [support forum](https://wordpress.org/support/plugin/widget-logic/) to request them. We regularly add commonly requested functions in new releases. 25 27 26 28 … … 41 43 * Don't cache widget logic results -- From v .58 the widget logic code should only execute once, but that might cause unexpected results with some themes, so this option is here to turn that behaviour off. (The truth/false of the code will be evaluated every time the sidebars_widgets filter is called. 42 44 45 * Custom PHP Functions -- From v.6.0.6 you can use the `widget_logic_allowed_functions` filter to add custom PHP functions that will be allowed in Widget Logic fields. By default, only WordPress conditional tags and a whitelist of safe functions are available. This filter allows you to extend the functionality and use your own custom functions. 46 47 To add a custom function, add the following code to your theme's `functions.php` file: 48 `add_filter('widget_logic_allowed_functions', 'my_allowed_functions'); 49 function my_allowed_functions($functions) { 50 $functions[] = '_my_custom_function_name_'; 51 return $functions; 52 }` 53 54 You can add multiple functions by using one wrapper function: 55 `add_filter('widget_logic_allowed_functions', 'my_allowed_functions'); 56 function my_allowed_functions($functions) { 57 $functions[] = 'is_special_page'; 58 $functions[] = 'is_user_verified'; 59 $functions[] = 'get_sidebar_title'; 60 return $functions; 61 }` 62 63 **IMPORTANT NOTE ON VARIABLES:** Widget Logic is designed to work with simple data types (strings, numbers, booleans). If you need to use complex variables, global state, or conditional logic that depends on many factors, create a custom function in your theme's `functions.php` file and call it from Widget Logic: 64 65 **Good approach (in functions.php):** 66 `function is_special_page() { 67 global $post; 68 $special_ids = array(5, 10, 15); 69 $conditions = some_complex_function(); 70 71 return is_page() && in_array($post->ID, $special_ids) && $conditions; 72 }` 73 74 Then in Widget Logic field, simply use: `is_special_page()` 75 76 **Less ideal approach (in Widget Logic field):** 77 Avoid putting complex logic directly in the Widget Logic field. Keep it simple and let your custom function handle the complexity. This keeps your widget settings clean and maintainable. 78 43 79 = Interaction with External Services = 44 80 … … 125 161 126 162 == Changelog == 163 164 = 6.0.7 = 165 166 * Enhanced Configuration section with detailed documentation for `widget_logic_allowed_functions` filter 167 * Added examples for adding custom functions to Widget Logic 168 * Added best practices guide for using variables with custom functions 169 * Improved documentation on separating complex logic from Widget Logic fields 170 * added support for more WordPress functions in the allowed functions in that account added: 171 - is_product_category 172 - has_category 173 - etc... 127 174 128 175 = 6.0.6 = -
widget-logic/trunk/widget.php
r3259805 r3434469 7 7 * Sets up the widgets name etc 8 8 */ 9 public function __construct() { 9 public function __construct() 10 { 10 11 $widget_ops = array( 11 12 'classname' => 'live_match_widget', … … 21 22 * @param array $instance 22 23 */ 23 public function widget($args, $instance) { 24 public function widget($args, $instance) 25 { 24 26 $defaults = array( 25 'title' => esc_html__('Live Match', 'widget-logic')26 );27 $instance = wp_parse_args( (array) $instance, $defaults);28 $title = apply_filters( 'widget_title', $instance['title']);27 'title' => esc_html__('Live Match', 'widget-logic') 28 ); 29 $instance = wp_parse_args((array) $instance, $defaults); 30 $title = apply_filters('widget_title', $instance['title']); 29 31 ?> 30 32 31 33 <?php echo $args['before_widget']; // @codingStandardsIgnoreLine here I can't escape output because other widgets will be damaged (example from https://developer.wordpress.org/reference/classes/wp_widget_search/widget/) ?> 32 34 <div class="live_match_widget"> 33 <?php if ( $title) { ?>34 <div class="live_match_widget_header"><?php echo $args['before_title'] . esc_html( $title ) . $args['after_title']; // @codingStandardsIgnoreLine here I can't escape output $args['before_title'] and $args['after_title'] because other functionality will be damaged (example from https://developer.wordpress.org/reference/classes/wp_widget_search/widget/)?></div>35 <?php } ?>36 <div class="live_match_widget_div">37 <div data-place="widget-live-match">Live Match will be here</div>38 </div>35 <?php if ($title) { ?> 36 <div class="live_match_widget_header"><?php echo $args['before_title'] . esc_html($title) . $args['after_title']; // @codingStandardsIgnoreLine here I can't escape output $args['before_title'] and $args['after_title'] because other functionality will be damaged (example from https://developer.wordpress.org/reference/classes/wp_widget_search/widget/) ?></div> 37 <?php } ?> 38 <div class="live_match_widget_div"> 39 <div data-place="widget-live-match">Live Match will be here</div> 40 </div> 39 41 </div> 40 42 <?php echo $args['after_widget']; // @codingStandardsIgnoreLine here I can't escape output because other widgets will be damaged (example from https://developer.wordpress.org/reference/classes/wp_widget_search/widget/) 41 wp_enqueue_script( 'widget-logic_live_match_widget');43 wp_enqueue_script('widget-logic_live_match_widget'); 42 44 } 43 45 … … 47 49 * @param array $instance The widget options 48 50 */ 49 public function form($instance) { 51 public function form($instance) 52 { 50 53 $defaults = array( 51 'title' => esc_html__( 'Live Match', 'widget-logic')52 );53 $instance = wp_parse_args( (array) $instance, $defaults);54 'title' => esc_html__('Live Match', 'widget-logic') 55 ); 56 $instance = wp_parse_args((array) $instance, $defaults); 54 57 55 $title = esc_attr( $instance['title']);58 $title = esc_attr($instance['title']); 56 59 ?> 57 <p><label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php esc_html_e( 'Title:', 'widget-logic'); ?></label>58 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" type="text" value="<?php echo esc_attr( $title); ?>" /></p>59 <?php60 <p><label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Title:', 'widget-logic'); ?></label> 61 <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> 62 <?php 60 63 } 61 64 … … 68 71 * @return array 69 72 */ 70 public function update($new_instance, $old_instance) { 73 public function update($new_instance, $old_instance) 74 { 71 75 $instance = $old_instance; 72 76 … … 77 81 } 78 82 79 function register_logic_live_match_widget_service() { 83 function register_logic_live_match_widget_service() 84 { 80 85 // Check if the script is already registered 81 if ( !wp_script_is('widget-logic_live_match_widget', 'registered')) {82 $cfg = require('widget_cfg.php');83 $url = $cfg['base'];84 $ver = $cfg['ver'];85 $t = time();86 $t = $t - $t % (12 * 60 * 60);86 if (!wp_script_is('widget-logic_live_match_widget', 'registered')) { 87 $cfg = require('widget_cfg.php'); 88 $url = $cfg['base']; 89 $ver = $cfg['ver']; 90 $t = time(); 91 $t = $t - $t % (12 * 60 * 60); 87 92 88 wp_register_script('widget-logic_live_match_widget', "{$url}{$ver}/js/data.js?t={$t}", array(),'6.0.5', true);89 }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); 94 } 90 95 } 91 96 … … 93 98 94 99 if (version_compare(get_bloginfo('version'), '5.0', '>=')) { 95 include_once 'block_widget/index.php';100 include_once 'block_widget/index.php'; 96 101 } else { 97 102 add_action('widgets_init', function() { 98 register_widget( 'Widget_Logic_Live_Match_Widget');103 register_widget('Widget_Logic_Live_Match_Widget'); 99 104 }); 100 105 } -
widget-logic/trunk/widget/admin.php
r3254708 r3434469 51 51 echo "[START=WIDGET LOGIC OPTIONS]\n"; 52 52 foreach ($wl_options as $id => $text) { 53 echo esc_attr($id) ."\t" . wp_json_encode($text) . "\n";53 echo esc_attr($id) . "\t" . wp_json_encode($text) . "\n"; 54 54 } 55 55 echo "[STOP=WIDGET LOGIC OPTIONS]"; … … 73 73 foreach ($import as $import_option) { 74 74 list($key, $value) = explode("\t", $import_option); 75 $wl_options[$key] = json_decode($value);75 $wl_options[$key] = json_decode($value); 76 76 } 77 77 $wl_options['msg'] = __('Success! Options file imported', 'widget-logic'); … … 85 85 86 86 update_option('widget_logic', $wl_options); 87 wp_ redirect(admin_url('widgets.php'));87 wp_safe_redirect(admin_url('widgets.php')); 88 88 exit; 89 89 } … … 104 104 105 105 $wl_options['widget_logic-options-wp_reset_query'] = !empty($_POST['widget_logic-options-wp_reset_query']); 106 $wl_options['widget_logic-options-show_errors'] = !empty($_POST['widget_logic-options-show_errors']);107 $wl_options['widget_logic-options-load_point'] = sanitize_text_field(wp_unslash(isset($_POST['widget_logic-options-load_point']) ? $_POST['widget_logic-options-load_point'] : ''));106 $wl_options['widget_logic-options-show_errors'] = !empty($_POST['widget_logic-options-show_errors']); 107 $wl_options['widget_logic-options-load_point'] = sanitize_text_field(wp_unslash(isset($_POST['widget_logic-options-load_point']) ? $_POST['widget_logic-options-load_point'] : '')); 108 108 } 109 109 … … 122 122 $msgClass = $isError ? 'error' : 'updated'; 123 123 124 echo '<div id="message" class="' .esc_attr($msgClass).'"><p>Widget Logic – '.esc_html($wl_options['msg']).'</p></div>';124 echo '<div id="message" class="' . esc_attr($msgClass) . '"><p>Widget Logic – ' . esc_html($wl_options['msg']) . '</p></div>'; 125 125 unset($wl_options['msg']); 126 126 update_option('widget_logic', $wl_options); … … 170 170 <?php 171 171 $wl_load_points = array( 172 'parse_query' => __('after query variables set (default)', 'widget-logic'),173 'plugins_loaded' => __('when plugin starts', 'widget-logic'),172 'parse_query' => __('after query variables set (default)', 'widget-logic'), 173 'plugins_loaded' => __('when plugin starts', 'widget-logic'), 174 174 'after_setup_theme' => __('after theme loads', 'widget-logic'), 175 'wp_loaded' => __('when all PHP loaded', 'widget-logic'),176 'wp_head' => __('during page header', 'widget-logic')175 'wp_loaded' => __('when all PHP loaded', 'widget-logic'), 176 'wp_head' => __('during page header', 'widget-logic') 177 177 ); 178 178 foreach ($wl_load_points as $action => $action_desc) { … … 271 271 $args = func_get_args(); 272 272 273 $callback = array_pop($args);273 $callback = array_pop($args); 274 274 $widget_id = array_pop($args); 275 275 … … 290 290 } 291 291 292 $input_id = "widget-$widget_id-widget_logic";292 $input_id = "widget-$widget_id-widget_logic"; 293 293 $input_name = "widget-{$widget_id}[widget_logic]"; 294 294 ?> -
widget-logic/trunk/widget/init.php
r3135406 r3434469 30 30 ob_start(); 31 31 $show_widget = widget_logic_check_logic($logic); 32 $error = ob_get_clean();32 $error = ob_get_clean(); 33 33 34 34 // Register a custom script handle -
widget-logic/trunk/widget/logic.php
r3329843 r3434469 11 11 { 12 12 $allowed_functions = array( 13 'is_home', 'is_front_page', 'is_single', 'is_page', 'is_category', 14 'is_tag', 'is_archive', 'is_search', 'is_404', 'is_user_logged_in', 15 'current_user_can', 'is_active_sidebar', 'is_admin', 13 // Main page checks 14 'is_home', 'is_front_page', 'is_admin', 15 16 // Single post/page checks 17 'is_single', 'is_page', 'is_singular', 'is_sticky', 'is_attachment', 'is_tree', 18 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', 16 65 ); 17 66 … … 76 125 if (preg_match('/^(.+)-(\d+)$/', $widget_id, $m)) { 77 126 $widget_class = $m[1]; 78 $widget_i = $m[2];127 $widget_i = $m[2]; 79 128 80 129 $info = get_option('widget_' . $widget_class); … … 109 158 if (preg_match('/^(.+)-(\d+)$/', $widget_id, $m)) { 110 159 $widget_class = $m[1]; 111 $widget_i = $m[2];160 $widget_i = $m[2]; 112 161 113 162 $info = get_option('widget_' . $widget_class); -
widget-logic/trunk/widget/logic/array/is_array.php
r3329843 r3434469 5 5 * Check if value uses array syntax 6 6 */ 7 function widget_logic_is_array_syntax($value) { 7 function widget_logic_is_array_syntax($value) 8 { 8 9 return (0 === strpos($value, 'array(') && ')' === substr($value, -1)) || 9 10 ('[' === substr($value, 0, 1) && ']' === substr($value, -1)); -
widget-logic/trunk/widget/logic/array/key.php
r3329843 r3434469 7 7 * Process an array key with security checks 8 8 */ 9 function widget_logic_process_array_key($key, $allowed_functions) { 9 function widget_logic_process_array_key($key, $allowed_functions) 10 { 10 11 // Handle function calls in keys 11 12 if (widget_logic_is_function_call(trim($key), $matches)) { -
widget-logic/trunk/widget/logic/array/main_array.php
r3329843 r3434469 9 9 * Parse array strings into actual PHP arrays with security checks 10 10 */ 11 function widget_logic_parse_array_string($array_str, $allowed_functions) { 11 function widget_logic_parse_array_string($array_str, $allowed_functions) 12 { 12 13 $array_str = trim($array_str); 13 14 … … 37 38 * Extract the inner string from array syntax 38 39 */ 39 function widget_logic_extract_array_inner($array_str) { 40 function widget_logic_extract_array_inner($array_str) 41 { 40 42 if (0 === strpos($array_str, 'array(') && ')' === substr($array_str, -1)) { 41 43 return trim(substr($array_str, 6, -1)); … … 50 52 * Process a single array element and add it to the result array 51 53 */ 52 function widget_logic_process_array_element($element, &$result, $allowed_functions) { 54 function widget_logic_process_array_element($element, &$result, $allowed_functions) 55 { 53 56 // Check if it's a key => value pair 54 57 if (preg_match('/^(.+?)=>(.+)$/s', $element, $matches)) { … … 69 72 } 70 73 71 // Helper function to split array elements, handling nested structures and quotes 72 function widget_logic_split_array_elements($str) { 74 /** 75 * Helper function to split array elements, handling nested structures and quotes 76 */ 77 function widget_logic_split_array_elements($str) 78 { 73 79 $elements = array(); 74 80 $current = ''; -
widget-logic/trunk/widget/logic/array/tokenize_array.php
r3329843 r3434469 8 8 * Capture an array token from the logic string 9 9 */ 10 function widget_logic_capture_array($logic, $i, &$tokens) { 10 function widget_logic_capture_array($logic, $i, &$tokens) 11 { 11 12 $start = $i; 12 13 -
widget-logic/trunk/widget/logic/array/value/string.php
r3329843 r3434469 8 8 * Check if value is a quoted string 9 9 */ 10 function widget_logic_is_quoted_string($value, &$out_string) { 10 function widget_logic_is_quoted_string($value, &$out_string) 11 { 11 12 if (('"' === substr($value, 0, 1) && '"' === substr($value, -1)) || 12 13 ("'" === substr($value, 0, 1) && "'" === substr($value, -1))) { … … 20 21 * Validate string values for security issues 21 22 */ 22 function widget_logic_validate_string_value($string_value) { 23 function widget_logic_validate_string_value($string_value) 24 { 23 25 // Check for PHP stream wrappers in strings 24 26 $dangerous_wrappers = array('php://', 'file://', 'expect://', 'data://', 'zip://', 'glob://', 'phar://'); -
widget-logic/trunk/widget/logic/function/is_function.php
r3329843 r3434469 6 6 * Check if value is a function call 7 7 */ 8 function widget_logic_is_function_call($value, &$matches) { 8 function widget_logic_is_function_call($value, &$matches) 9 { 9 10 return preg_match('/^([a-zA-Z_][a-zA-Z0-9_]*)\((.*)\)$/', $value, $matches); 10 11 } -
widget-logic/trunk/widget/logic/function/main_function.php
r3329843 r3434469 14 14 * @throws Exception If the function is not allowed or does not exist 15 15 */ 16 17 16 function widget_logic_handle_function_call($matches, $allowed_functions) 18 17 { -
widget-logic/trunk/widget/logic/parser.php
r3329843 r3434469 42 42 } 43 43 44 // Helper function to parse AND expressions (terms connected by &&) 44 /** 45 * Helper function to parse AND expressions (terms connected by &&) 46 */ 45 47 function widget_logic_parse_and_expression(&$tokens, &$pos, $allowed_functions) 46 48 { … … 74 76 } 75 77 76 // Helper function to parse terms 78 /** 79 * Helper function to parse terms 80 */ 77 81 function widget_logic_parse_term(&$tokens, &$pos, $allowed_functions) 78 82 { -
widget-logic/trunk/widget/logic/tokenizer.php
r3329843 r3434469 7 7 * Tokenize a logic expression string into an array of tokens 8 8 */ 9 function widget_logic_tokenize($logic) { 9 function widget_logic_tokenize($logic) 10 { 10 11 $tokens = []; 11 12 $i = 0; … … 50 51 * Capture a word or function call token from the logic string 51 52 */ 52 function widget_logic_capture_word_or_function($logic, $i, &$tokens) { 53 function widget_logic_capture_word_or_function($logic, $i, &$tokens) 54 { 53 55 $start = $i; 54 56 $length = strlen($logic); -
widget-logic/trunk/widget_cfg.php
r3143078 r3434469 1 1 <?php 2 if ( ! defined( 'ABSPATH' )) exit; // Exit if accessed directly2 if (!defined('ABSPATH')) exit; // Exit if accessed directly 3 3 4 4 // a helper function to lookup "env_FILE", "env", then fallback, standard WP function, needed for compatibility with WP 3 5 5 if (!function_exists('getenv_docker')) { 6 function getenv_docker($env, $default) { 6 function getenv_docker($env, $default) 7 { 7 8 if ($fileEnv = getenv($env . '_FILE')) { 8 9 return rtrim(file_get_contents($fileEnv), "\r\n"); // @codingStandardsIgnoreLine 9 } 10 else if (($val = getenv($env)) !== false) { 10 } elseif (($val = getenv($env)) !== false) { 11 11 return $val; 12 } 13 else { 12 } else { 14 13 return $default; 15 14 } … … 18 17 // a helper function for development plugin 19 18 if (!function_exists('widget_logic_getServiceVersion')) { 20 function widget_logic_getServiceVersion() { 21 $ver = getenv_docker('WORDPRESS_SERVICE_WGL_VER', 'v2'); 22 return $ver ? "/{$ver}" : $ver; 23 } 19 function widget_logic_getServiceVersion() 20 { 21 $ver = getenv_docker('WORDPRESS_SERVICE_WGL_VER', 'v2'); 22 return $ver ? "/{$ver}" : $ver; 23 } 24 24 } 25 25 26 26 27 27 return array( 28 'ver' => widget_logic_getServiceVersion(),29 'base' => getenv_docker('WORDPRESS_PLUGIN_WGL_BASE_URL', 'https://widgetlogic.org')28 'ver' => widget_logic_getServiceVersion(), 29 'base' => getenv_docker('WORDPRESS_PLUGIN_WGL_BASE_URL', 'https://widgetlogic.org') 30 30 ); -
widget-logic/trunk/widget_logic.php
r3329843 r3434469 5 5 Plugin Name: Widget Logic 6 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 .67 Version: 6.07 8 8 Author: Widget Logic 9 9 Author URI: https://widgetlogic.org … … 17 17 18 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'));19 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($cfg, 'addDescriptionSettingsLink')); 20 20 21 21 if ($cfg->isFullyEnabled()) {
Note: See TracChangeset
for help on using the changeset viewer.