Plugin Directory

Changeset 3434469


Ignore:
Timestamp:
01/07/2026 03:33:10 PM (2 months ago)
Author:
widgetlogics
Message:

update to v6.0.7 added more wp functions

Location:
widget-logic
Files:
27 edited
20 copied

Legend:

Unmodified
Added
Removed
  • widget-logic/tags/6.07/WidgetLogicAdminConfig.php

    r3254708 r3434469  
    11<?php
    2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
     2if (!defined('ABSPATH')) exit; // Exit if accessed directly
    33
    44class WidgetLogicAdminConfig
     
    99    protected $options;
    1010
    11     public static function getInstance() {
    12 
     11    public static function getInstance()
     12    {
    1313        if (null == self::$instance) {
    1414            self::$instance = new self;
     
    1616
    1717        return self::$instance;
    18 
    1918    }
    2019
    21     private function __construct() {
    22 
     20    private function __construct()
     21    {
    2322        // Add the page to the admin menu
    2423        add_action('admin_menu', array(&$this, 'addPage'));
     
    2928        // Get registered option
    3029        $this->options = get_option('widget_logic_settings_options');
    31 
    3230    }
    3331
     
    3735    }
    3836
    39     public function addDescriptionSettingsLink($links) {
     37    public function addDescriptionSettingsLink($links)
     38    {
    4039        if ($this->isFullyEnabled()) {
    4140            return $links;
     
    4948    }
    5049
    51     public function addPage() {
     50    public function addPage()
     51    {
    5252        add_options_page('Theme Options', 'Widget Logic', 'manage_options', 'widget-logic', array($this, 'displayPage'));
    5353    }
    5454
    55     public function displayPage() {
     55    public function displayPage()
     56    {
    5657    ?>
    5758    <div class='wrap'>
     
    8687    }
    8788
    88     public function registerPageOptions() {
     89    public function registerPageOptions()
     90    {
    8991        // Add Section for option fields
    9092        add_settings_section('widget_logic_section', '', array($this, 'displaySection'), __FILE__);
     
    9597    }
    9698
    97     public function validateOptions($fields) {
     99    public function validateOptions($fields)
     100    {
    98101        $valid_fields = array();
    99102
     
    104107    }
    105108
    106     public function displaySection() { /* Leave blank */ }
     109    public function displaySection()
     110    {
     111        /* Leave blank */
     112    }
    107113
    108114    protected function getFullyEnabledValue()
     
    111117    }
    112118
    113     public function isEnabledSettingsField() {
     119    public function isEnabledSettingsField()
     120    {
    114121        $val = $this->getFullyEnabledValue();
    115122
    116         $selected_one=array(self::ON => '', self::OFF => '');
     123        $selected_one = array(self::ON => '', self::OFF => '');
    117124        $selected_one[$val] = 'selected="selected"';
    118125        echo "
    119126        <div>
    120127            <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>
    123130            </select>
    124131        </div>
  • widget-logic/tags/6.07/block_widget/index.php

    r3259805 r3434469  
    33if (!defined('ABSPATH')) exit;
    44
    5 function widget_logic_register_block() {
     5function widget_logic_register_block()
     6{
    67    register_logic_live_match_widget_service();
    78    register_block_type(__DIR__ . '/block.json');
  • widget-logic/tags/6.07/readme.txt

    r3329843 r3434469  
    33Tags: widget, sidebar, conditional tags, blocks, gutenberg widgets
    44Requires at least: 3.0
    5 Tested up to: 6.8
    6 Stable tag: 6.0.6
     5Tested up to: 6.9
     6Stable tag: 6.07
    77Requires PHP: 5.4
    88License: GPLv2 or later
     
    2323
    2424* 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.
    2527
    2628
     
    4143*  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.
    4244
     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
    4379= Interaction with External Services =
    4480
     
    125161
    126162== 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...
    127174
    128175= 6.0.6 =
  • widget-logic/tags/6.07/widget.php

    r3259805 r3434469  
    77     * Sets up the widgets name etc
    88     */
    9     public function __construct() {
     9    public function __construct()
     10    {
    1011        $widget_ops = array(
    1112            'classname' => 'live_match_widget',
     
    2122     * @param array $instance
    2223     */
    23     public function widget($args, $instance) {
     24    public function widget($args, $instance)
     25    {
    2426        $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']);
    2931        ?>
    3032
    3133        <?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/) ?>
    3234        <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>
    3941        </div>
    4042        <?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');
    4244    }
    4345
     
    4749     * @param array $instance The widget options
    4850     */
    49     public function form($instance) {
     51    public function form($instance)
     52    {
    5053        $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);
    5457
    55         $title    = esc_attr( $instance['title'] );
     58        $title = esc_attr($instance['title']);
    5659        ?>
    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         <?php
     60        <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
    6063    }
    6164
     
    6871     * @return array
    6972     */
    70     public function update($new_instance, $old_instance) {
     73    public function update($new_instance, $old_instance)
     74    {
    7175        $instance = $old_instance;
    7276
     
    7781}
    7882
    79 function register_logic_live_match_widget_service() {
     83function register_logic_live_match_widget_service()
     84{
    8085    // 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);
    8792
    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    }
    9095}
    9196
     
    9398
    9499if (version_compare(get_bloginfo('version'), '5.0', '>=')) {
    95     include_once 'block_widget/index.php';
     100    include_once 'block_widget/index.php';
    96101} else {
    97102    add_action('widgets_init', function() {
    98         register_widget( 'Widget_Logic_Live_Match_Widget' );
     103        register_widget('Widget_Logic_Live_Match_Widget');
    99104    });
    100105}
  • widget-logic/tags/6.07/widget/admin.php

    r3254708 r3434469  
    5151        echo "[START=WIDGET LOGIC OPTIONS]\n";
    5252        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";
    5454        }
    5555        echo "[STOP=WIDGET LOGIC OPTIONS]";
     
    7373                foreach ($import as $import_option) {
    7474                    list($key, $value) = explode("\t", $import_option);
    75                     $wl_options[$key]  = json_decode($value);
     75                    $wl_options[$key] = json_decode($value);
    7676                }
    7777                $wl_options['msg'] = __('Success! Options file imported', 'widget-logic');
     
    8585
    8686        update_option('widget_logic', $wl_options);
    87         wp_redirect(admin_url('widgets.php'));
     87        wp_safe_redirect(admin_url('widgets.php'));
    8888        exit;
    8989    }
     
    104104
    105105        $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'] : ''));
    108108    }
    109109
     
    122122        $msgClass = $isError ? 'error' : 'updated';
    123123
    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>';
    125125        unset($wl_options['msg']);
    126126        update_option('widget_logic', $wl_options);
     
    170170                            <?php
    171171                                $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'),
    174174                                    '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')
    177177                                );
    178178                                foreach ($wl_load_points as $action => $action_desc) {
     
    271271    $args = func_get_args();
    272272
    273     $callback  = array_pop($args);
     273    $callback = array_pop($args);
    274274    $widget_id = array_pop($args);
    275275
     
    290290    }
    291291
    292     $input_id   = "widget-$widget_id-widget_logic";
     292    $input_id = "widget-$widget_id-widget_logic";
    293293    $input_name = "widget-{$widget_id}[widget_logic]";
    294294    ?>
  • widget-logic/tags/6.07/widget/init.php

    r3135406 r3434469  
    3030    ob_start();
    3131    $show_widget = widget_logic_check_logic($logic);
    32     $error       = ob_get_clean();
     32    $error = ob_get_clean();
    3333
    3434    // Register a custom script handle
  • widget-logic/tags/6.07/widget/logic.php

    r3329843 r3434469  
    1111{
    1212    $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',
    1665    );
    1766
     
    76125    if (preg_match('/^(.+)-(\d+)$/', $widget_id, $m)) {
    77126        $widget_class = $m[1];
    78         $widget_i     = $m[2];
     127        $widget_i = $m[2];
    79128
    80129        $info = get_option('widget_' . $widget_class);
     
    109158    if (preg_match('/^(.+)-(\d+)$/', $widget_id, $m)) {
    110159        $widget_class = $m[1];
    111         $widget_i     = $m[2];
     160        $widget_i = $m[2];
    112161
    113162        $info = get_option('widget_' . $widget_class);
  • widget-logic/tags/6.07/widget/logic/array/is_array.php

    r3329843 r3434469  
    55 * Check if value uses array syntax
    66 */
    7 function widget_logic_is_array_syntax($value) {
     7function widget_logic_is_array_syntax($value)
     8{
    89    return (0 === strpos($value, 'array(') && ')' === substr($value, -1)) ||
    910           ('[' === substr($value, 0, 1) && ']' === substr($value, -1));
  • widget-logic/tags/6.07/widget/logic/array/key.php

    r3329843 r3434469  
    77 * Process an array key with security checks
    88 */
    9 function widget_logic_process_array_key($key, $allowed_functions) {
     9function widget_logic_process_array_key($key, $allowed_functions)
     10{
    1011    // Handle function calls in keys
    1112    if (widget_logic_is_function_call(trim($key), $matches)) {
  • widget-logic/tags/6.07/widget/logic/array/main_array.php

    r3329843 r3434469  
    99 * Parse array strings into actual PHP arrays with security checks
    1010 */
    11 function widget_logic_parse_array_string($array_str, $allowed_functions) {
     11function widget_logic_parse_array_string($array_str, $allowed_functions)
     12{
    1213    $array_str = trim($array_str);
    1314
     
    3738 * Extract the inner string from array syntax
    3839 */
    39 function widget_logic_extract_array_inner($array_str) {
     40function widget_logic_extract_array_inner($array_str)
     41{
    4042    if (0 === strpos($array_str, 'array(') && ')' === substr($array_str, -1)) {
    4143        return trim(substr($array_str, 6, -1));
     
    5052 * Process a single array element and add it to the result array
    5153 */
    52 function widget_logic_process_array_element($element, &$result, $allowed_functions) {
     54function widget_logic_process_array_element($element, &$result, $allowed_functions)
     55{
    5356    // Check if it's a key => value pair
    5457    if (preg_match('/^(.+?)=>(.+)$/s', $element, $matches)) {
     
    6972}
    7073
    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 */
     77function widget_logic_split_array_elements($str)
     78{
    7379    $elements = array();
    7480    $current = '';
  • widget-logic/tags/6.07/widget/logic/array/tokenize_array.php

    r3329843 r3434469  
    88 * Capture an array token from the logic string
    99 */
    10 function widget_logic_capture_array($logic, $i, &$tokens) {
     10function widget_logic_capture_array($logic, $i, &$tokens)
     11{
    1112    $start = $i;
    1213
  • widget-logic/tags/6.07/widget/logic/array/value/string.php

    r3329843 r3434469  
    88 * Check if value is a quoted string
    99 */
    10 function widget_logic_is_quoted_string($value, &$out_string) {
     10function widget_logic_is_quoted_string($value, &$out_string)
     11{
    1112    if (('"' === substr($value, 0, 1) && '"' === substr($value, -1)) ||
    1213        ("'" === substr($value, 0, 1) && "'" === substr($value, -1))) {
     
    2021 * Validate string values for security issues
    2122 */
    22 function widget_logic_validate_string_value($string_value) {
     23function widget_logic_validate_string_value($string_value)
     24{
    2325    // Check for PHP stream wrappers in strings
    2426    $dangerous_wrappers = array('php://', 'file://', 'expect://', 'data://', 'zip://', 'glob://', 'phar://');
  • widget-logic/tags/6.07/widget/logic/function/is_function.php

    r3329843 r3434469  
    66 * Check if value is a function call
    77 */
    8 function widget_logic_is_function_call($value, &$matches) {
     8function widget_logic_is_function_call($value, &$matches)
     9{
    910    return preg_match('/^([a-zA-Z_][a-zA-Z0-9_]*)\((.*)\)$/', $value, $matches);
    1011}
  • widget-logic/tags/6.07/widget/logic/function/main_function.php

    r3329843 r3434469  
    1414 * @throws Exception If the function is not allowed or does not exist
    1515 */
    16 
    1716function widget_logic_handle_function_call($matches, $allowed_functions)
    1817{
  • widget-logic/tags/6.07/widget/logic/parser.php

    r3329843 r3434469  
    4242}
    4343
    44 // Helper function to parse AND expressions (terms connected by &&)
     44/**
     45 * Helper function to parse AND expressions (terms connected by &&)
     46 */
    4547function widget_logic_parse_and_expression(&$tokens, &$pos, $allowed_functions)
    4648{
     
    7476}
    7577
    76 // Helper function to parse terms
     78/**
     79 * Helper function to parse terms
     80 */
    7781function widget_logic_parse_term(&$tokens, &$pos, $allowed_functions)
    7882{
  • widget-logic/tags/6.07/widget/logic/tokenizer.php

    r3329843 r3434469  
    77 * Tokenize a logic expression string into an array of tokens
    88 */
    9 function widget_logic_tokenize($logic) {
     9function widget_logic_tokenize($logic)
     10{
    1011    $tokens = [];
    1112    $i = 0;
     
    5051 * Capture a word or function call token from the logic string
    5152 */
    52 function widget_logic_capture_word_or_function($logic, $i, &$tokens) {
     53function widget_logic_capture_word_or_function($logic, $i, &$tokens)
     54{
    5355    $start = $i;
    5456    $length = strlen($logic);
  • widget-logic/tags/6.07/widget_cfg.php

    r3143078 r3434469  
    11<?php
    2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
     2if (!defined('ABSPATH')) exit; // Exit if accessed directly
    33
    44// a helper function to lookup "env_FILE", "env", then fallback, standard WP function, needed for compatibility with WP 3
    55if (!function_exists('getenv_docker')) {
    6     function getenv_docker($env, $default) {
     6    function getenv_docker($env, $default)
     7    {
    78        if ($fileEnv = getenv($env . '_FILE')) {
    89            return rtrim(file_get_contents($fileEnv), "\r\n"); // @codingStandardsIgnoreLine
    9         }
    10         else if (($val = getenv($env)) !== false) {
     10        } elseif (($val = getenv($env)) !== false) {
    1111            return $val;
    12         }
    13         else {
     12        } else {
    1413            return $default;
    1514        }
     
    1817// a helper function for development plugin
    1918if (!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    }
    2424}
    2525
    2626
    2727return 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')
    3030);
  • widget-logic/tags/6.07/widget_logic.php

    r3329843 r3434469  
    55Plugin Name: Widget Logic
    66Description: 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.6
     7Version:     6.07
    88Author:      Widget Logic
    99Author URI:  https://widgetlogic.org
     
    1717
    1818// Add a link to the settings page in the plugin description area
    19 add_filter('plugin_action_links_'.plugin_basename(__FILE__), array($cfg, 'addDescriptionSettingsLink'));
     19add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($cfg, 'addDescriptionSettingsLink'));
    2020
    2121if ($cfg->isFullyEnabled()) {
  • widget-logic/trunk/WidgetLogicAdminConfig.php

    r3254708 r3434469  
    11<?php
    2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
     2if (!defined('ABSPATH')) exit; // Exit if accessed directly
    33
    44class WidgetLogicAdminConfig
     
    99    protected $options;
    1010
    11     public static function getInstance() {
    12 
     11    public static function getInstance()
     12    {
    1313        if (null == self::$instance) {
    1414            self::$instance = new self;
     
    1616
    1717        return self::$instance;
    18 
    1918    }
    2019
    21     private function __construct() {
    22 
     20    private function __construct()
     21    {
    2322        // Add the page to the admin menu
    2423        add_action('admin_menu', array(&$this, 'addPage'));
     
    2928        // Get registered option
    3029        $this->options = get_option('widget_logic_settings_options');
    31 
    3230    }
    3331
     
    3735    }
    3836
    39     public function addDescriptionSettingsLink($links) {
     37    public function addDescriptionSettingsLink($links)
     38    {
    4039        if ($this->isFullyEnabled()) {
    4140            return $links;
     
    4948    }
    5049
    51     public function addPage() {
     50    public function addPage()
     51    {
    5252        add_options_page('Theme Options', 'Widget Logic', 'manage_options', 'widget-logic', array($this, 'displayPage'));
    5353    }
    5454
    55     public function displayPage() {
     55    public function displayPage()
     56    {
    5657    ?>
    5758    <div class='wrap'>
     
    8687    }
    8788
    88     public function registerPageOptions() {
     89    public function registerPageOptions()
     90    {
    8991        // Add Section for option fields
    9092        add_settings_section('widget_logic_section', '', array($this, 'displaySection'), __FILE__);
     
    9597    }
    9698
    97     public function validateOptions($fields) {
     99    public function validateOptions($fields)
     100    {
    98101        $valid_fields = array();
    99102
     
    104107    }
    105108
    106     public function displaySection() { /* Leave blank */ }
     109    public function displaySection()
     110    {
     111        /* Leave blank */
     112    }
    107113
    108114    protected function getFullyEnabledValue()
     
    111117    }
    112118
    113     public function isEnabledSettingsField() {
     119    public function isEnabledSettingsField()
     120    {
    114121        $val = $this->getFullyEnabledValue();
    115122
    116         $selected_one=array(self::ON => '', self::OFF => '');
     123        $selected_one = array(self::ON => '', self::OFF => '');
    117124        $selected_one[$val] = 'selected="selected"';
    118125        echo "
    119126        <div>
    120127            <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>
    123130            </select>
    124131        </div>
  • widget-logic/trunk/block_widget/index.php

    r3259805 r3434469  
    33if (!defined('ABSPATH')) exit;
    44
    5 function widget_logic_register_block() {
     5function widget_logic_register_block()
     6{
    67    register_logic_live_match_widget_service();
    78    register_block_type(__DIR__ . '/block.json');
  • widget-logic/trunk/readme.txt

    r3329843 r3434469  
    33Tags: widget, sidebar, conditional tags, blocks, gutenberg widgets
    44Requires at least: 3.0
    5 Tested up to: 6.8
    6 Stable tag: 6.0.6
     5Tested up to: 6.9
     6Stable tag: 6.07
    77Requires PHP: 5.4
    88License: GPLv2 or later
     
    2323
    2424* 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.
    2527
    2628
     
    4143*  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.
    4244
     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
    4379= Interaction with External Services =
    4480
     
    125161
    126162== 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...
    127174
    128175= 6.0.6 =
  • widget-logic/trunk/widget.php

    r3259805 r3434469  
    77     * Sets up the widgets name etc
    88     */
    9     public function __construct() {
     9    public function __construct()
     10    {
    1011        $widget_ops = array(
    1112            'classname' => 'live_match_widget',
     
    2122     * @param array $instance
    2223     */
    23     public function widget($args, $instance) {
     24    public function widget($args, $instance)
     25    {
    2426        $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']);
    2931        ?>
    3032
    3133        <?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/) ?>
    3234        <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>
    3941        </div>
    4042        <?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');
    4244    }
    4345
     
    4749     * @param array $instance The widget options
    4850     */
    49     public function form($instance) {
     51    public function form($instance)
     52    {
    5053        $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);
    5457
    55         $title    = esc_attr( $instance['title'] );
     58        $title = esc_attr($instance['title']);
    5659        ?>
    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         <?php
     60        <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
    6063    }
    6164
     
    6871     * @return array
    6972     */
    70     public function update($new_instance, $old_instance) {
     73    public function update($new_instance, $old_instance)
     74    {
    7175        $instance = $old_instance;
    7276
     
    7781}
    7882
    79 function register_logic_live_match_widget_service() {
     83function register_logic_live_match_widget_service()
     84{
    8085    // 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);
    8792
    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    }
    9095}
    9196
     
    9398
    9499if (version_compare(get_bloginfo('version'), '5.0', '>=')) {
    95     include_once 'block_widget/index.php';
     100    include_once 'block_widget/index.php';
    96101} else {
    97102    add_action('widgets_init', function() {
    98         register_widget( 'Widget_Logic_Live_Match_Widget' );
     103        register_widget('Widget_Logic_Live_Match_Widget');
    99104    });
    100105}
  • widget-logic/trunk/widget/admin.php

    r3254708 r3434469  
    5151        echo "[START=WIDGET LOGIC OPTIONS]\n";
    5252        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";
    5454        }
    5555        echo "[STOP=WIDGET LOGIC OPTIONS]";
     
    7373                foreach ($import as $import_option) {
    7474                    list($key, $value) = explode("\t", $import_option);
    75                     $wl_options[$key]  = json_decode($value);
     75                    $wl_options[$key] = json_decode($value);
    7676                }
    7777                $wl_options['msg'] = __('Success! Options file imported', 'widget-logic');
     
    8585
    8686        update_option('widget_logic', $wl_options);
    87         wp_redirect(admin_url('widgets.php'));
     87        wp_safe_redirect(admin_url('widgets.php'));
    8888        exit;
    8989    }
     
    104104
    105105        $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'] : ''));
    108108    }
    109109
     
    122122        $msgClass = $isError ? 'error' : 'updated';
    123123
    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>';
    125125        unset($wl_options['msg']);
    126126        update_option('widget_logic', $wl_options);
     
    170170                            <?php
    171171                                $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'),
    174174                                    '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')
    177177                                );
    178178                                foreach ($wl_load_points as $action => $action_desc) {
     
    271271    $args = func_get_args();
    272272
    273     $callback  = array_pop($args);
     273    $callback = array_pop($args);
    274274    $widget_id = array_pop($args);
    275275
     
    290290    }
    291291
    292     $input_id   = "widget-$widget_id-widget_logic";
     292    $input_id = "widget-$widget_id-widget_logic";
    293293    $input_name = "widget-{$widget_id}[widget_logic]";
    294294    ?>
  • widget-logic/trunk/widget/init.php

    r3135406 r3434469  
    3030    ob_start();
    3131    $show_widget = widget_logic_check_logic($logic);
    32     $error       = ob_get_clean();
     32    $error = ob_get_clean();
    3333
    3434    // Register a custom script handle
  • widget-logic/trunk/widget/logic.php

    r3329843 r3434469  
    1111{
    1212    $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',
    1665    );
    1766
     
    76125    if (preg_match('/^(.+)-(\d+)$/', $widget_id, $m)) {
    77126        $widget_class = $m[1];
    78         $widget_i     = $m[2];
     127        $widget_i = $m[2];
    79128
    80129        $info = get_option('widget_' . $widget_class);
     
    109158    if (preg_match('/^(.+)-(\d+)$/', $widget_id, $m)) {
    110159        $widget_class = $m[1];
    111         $widget_i     = $m[2];
     160        $widget_i = $m[2];
    112161
    113162        $info = get_option('widget_' . $widget_class);
  • widget-logic/trunk/widget/logic/array/is_array.php

    r3329843 r3434469  
    55 * Check if value uses array syntax
    66 */
    7 function widget_logic_is_array_syntax($value) {
     7function widget_logic_is_array_syntax($value)
     8{
    89    return (0 === strpos($value, 'array(') && ')' === substr($value, -1)) ||
    910           ('[' === substr($value, 0, 1) && ']' === substr($value, -1));
  • widget-logic/trunk/widget/logic/array/key.php

    r3329843 r3434469  
    77 * Process an array key with security checks
    88 */
    9 function widget_logic_process_array_key($key, $allowed_functions) {
     9function widget_logic_process_array_key($key, $allowed_functions)
     10{
    1011    // Handle function calls in keys
    1112    if (widget_logic_is_function_call(trim($key), $matches)) {
  • widget-logic/trunk/widget/logic/array/main_array.php

    r3329843 r3434469  
    99 * Parse array strings into actual PHP arrays with security checks
    1010 */
    11 function widget_logic_parse_array_string($array_str, $allowed_functions) {
     11function widget_logic_parse_array_string($array_str, $allowed_functions)
     12{
    1213    $array_str = trim($array_str);
    1314
     
    3738 * Extract the inner string from array syntax
    3839 */
    39 function widget_logic_extract_array_inner($array_str) {
     40function widget_logic_extract_array_inner($array_str)
     41{
    4042    if (0 === strpos($array_str, 'array(') && ')' === substr($array_str, -1)) {
    4143        return trim(substr($array_str, 6, -1));
     
    5052 * Process a single array element and add it to the result array
    5153 */
    52 function widget_logic_process_array_element($element, &$result, $allowed_functions) {
     54function widget_logic_process_array_element($element, &$result, $allowed_functions)
     55{
    5356    // Check if it's a key => value pair
    5457    if (preg_match('/^(.+?)=>(.+)$/s', $element, $matches)) {
     
    6972}
    7073
    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 */
     77function widget_logic_split_array_elements($str)
     78{
    7379    $elements = array();
    7480    $current = '';
  • widget-logic/trunk/widget/logic/array/tokenize_array.php

    r3329843 r3434469  
    88 * Capture an array token from the logic string
    99 */
    10 function widget_logic_capture_array($logic, $i, &$tokens) {
     10function widget_logic_capture_array($logic, $i, &$tokens)
     11{
    1112    $start = $i;
    1213
  • widget-logic/trunk/widget/logic/array/value/string.php

    r3329843 r3434469  
    88 * Check if value is a quoted string
    99 */
    10 function widget_logic_is_quoted_string($value, &$out_string) {
     10function widget_logic_is_quoted_string($value, &$out_string)
     11{
    1112    if (('"' === substr($value, 0, 1) && '"' === substr($value, -1)) ||
    1213        ("'" === substr($value, 0, 1) && "'" === substr($value, -1))) {
     
    2021 * Validate string values for security issues
    2122 */
    22 function widget_logic_validate_string_value($string_value) {
     23function widget_logic_validate_string_value($string_value)
     24{
    2325    // Check for PHP stream wrappers in strings
    2426    $dangerous_wrappers = array('php://', 'file://', 'expect://', 'data://', 'zip://', 'glob://', 'phar://');
  • widget-logic/trunk/widget/logic/function/is_function.php

    r3329843 r3434469  
    66 * Check if value is a function call
    77 */
    8 function widget_logic_is_function_call($value, &$matches) {
     8function widget_logic_is_function_call($value, &$matches)
     9{
    910    return preg_match('/^([a-zA-Z_][a-zA-Z0-9_]*)\((.*)\)$/', $value, $matches);
    1011}
  • widget-logic/trunk/widget/logic/function/main_function.php

    r3329843 r3434469  
    1414 * @throws Exception If the function is not allowed or does not exist
    1515 */
    16 
    1716function widget_logic_handle_function_call($matches, $allowed_functions)
    1817{
  • widget-logic/trunk/widget/logic/parser.php

    r3329843 r3434469  
    4242}
    4343
    44 // Helper function to parse AND expressions (terms connected by &&)
     44/**
     45 * Helper function to parse AND expressions (terms connected by &&)
     46 */
    4547function widget_logic_parse_and_expression(&$tokens, &$pos, $allowed_functions)
    4648{
     
    7476}
    7577
    76 // Helper function to parse terms
     78/**
     79 * Helper function to parse terms
     80 */
    7781function widget_logic_parse_term(&$tokens, &$pos, $allowed_functions)
    7882{
  • widget-logic/trunk/widget/logic/tokenizer.php

    r3329843 r3434469  
    77 * Tokenize a logic expression string into an array of tokens
    88 */
    9 function widget_logic_tokenize($logic) {
     9function widget_logic_tokenize($logic)
     10{
    1011    $tokens = [];
    1112    $i = 0;
     
    5051 * Capture a word or function call token from the logic string
    5152 */
    52 function widget_logic_capture_word_or_function($logic, $i, &$tokens) {
     53function widget_logic_capture_word_or_function($logic, $i, &$tokens)
     54{
    5355    $start = $i;
    5456    $length = strlen($logic);
  • widget-logic/trunk/widget_cfg.php

    r3143078 r3434469  
    11<?php
    2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
     2if (!defined('ABSPATH')) exit; // Exit if accessed directly
    33
    44// a helper function to lookup "env_FILE", "env", then fallback, standard WP function, needed for compatibility with WP 3
    55if (!function_exists('getenv_docker')) {
    6     function getenv_docker($env, $default) {
     6    function getenv_docker($env, $default)
     7    {
    78        if ($fileEnv = getenv($env . '_FILE')) {
    89            return rtrim(file_get_contents($fileEnv), "\r\n"); // @codingStandardsIgnoreLine
    9         }
    10         else if (($val = getenv($env)) !== false) {
     10        } elseif (($val = getenv($env)) !== false) {
    1111            return $val;
    12         }
    13         else {
     12        } else {
    1413            return $default;
    1514        }
     
    1817// a helper function for development plugin
    1918if (!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    }
    2424}
    2525
    2626
    2727return 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')
    3030);
  • widget-logic/trunk/widget_logic.php

    r3329843 r3434469  
    55Plugin Name: Widget Logic
    66Description: 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.6
     7Version:     6.07
    88Author:      Widget Logic
    99Author URI:  https://widgetlogic.org
     
    1717
    1818// Add a link to the settings page in the plugin description area
    19 add_filter('plugin_action_links_'.plugin_basename(__FILE__), array($cfg, 'addDescriptionSettingsLink'));
     19add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($cfg, 'addDescriptionSettingsLink'));
    2020
    2121if ($cfg->isFullyEnabled()) {
Note: See TracChangeset for help on using the changeset viewer.