• Is it possible to add a hook to override the default “eval” and use a custom function that validates the logic?

    Basically we want to use Drupal blocks URL pattern way of handling the logic, and don’t use eval.

    We can manually go into the code and change “eval” to our function, but as always there is a cleaner WP way of doing it. ??

    Thanks!

    https://www.ads-software.com/extend/plugins/widget-logic/

Viewing 15 replies - 1 through 15 (of 18 total)
  • Thread Starter Mohan Chevuri

    (@mchev2)

    Something like this…

    if(!(function_exists("widget_logic_eval_override")?widget_logic_eval_override($wl_value):eval($wl_value)))

    I could put in an action that passes through the widget logic, and then does the eval if the result is true/false – I’ll think about which makes more sense.

    can i ask why you wouldn’t simply put your function in the widget logic like this:

    widget_logic_eval_override('some value for my function')

    which would have the effect of calling your function

    Thread Starter Mohan Chevuri

    (@mchev2)

    Thanks for the reply. Yeah I can modify widget logic plugin code a tiny bit, but thought it will be better if I don’t modify the code and use some kind of hook (or action as you said) to call in my custom plugin. That way I can do future updates without going and updating widget logic code everytime.

    what I was getting at is you could put in your logic in the admin interface as the above without altering the WL plugin code, and that would have the same effect. Obviously you’d have to do it for each widget but it looks like you’d be putting something in the WL code anyway? (for your function to use as a param)

    Thread Starter Mohan Chevuri

    (@mchev2)

    That is the way we are using widget logic with our function, now in testing. But we decided not to use eval in production, as this WPMU installation will be used by about 500 people and might become a security issue.

    ah fair point ??

    I will try adding something to the DEV version soon for you to try – but apologies in advance as I have been promising to play with the code for weeks (to fix some bad coding and a couple of other small requests). However I’ll take a quick look at the code and write some basic amendment including a do_action for you to look at here. Just got to go light a barbecue now ??

    Thread Starter Mohan Chevuri

    (@mchev2)

    Thanks much!

    You already seem to be in the party mode. Have fun!

    How about a filter instead of an action and I change the crucial code in WL plugin to

    foreach($widget_list as $pos => $widget_id)
    {	if (empty($wl_options[$widget_id]))  continue;
    	$wl_value=trim($wl_options[$widget_id]);
    	if (empty($wl_value))  continue;
    
    	$wl_value=apply_filters( "widget_logic_eval_override", $wl_value )
    	if ($wl_value===false)
    	{	unset($sidebars_widgets[$widget_area][$pos]);
    		continue;
    	}
    	if ($wl_value===true) continue;
    
    	if (stristr($wl_value,"return")===false)
    		$wl_value="return (" . $wl_value . ");";
    
    	if (!eval($wl_value))
    		unset($sidebars_widgets[$widget_area][$pos]);
    }

    so the filter gives you the chance to step in and return a boolean value directly?

    Thread Starter Mohan Chevuri

    (@mchev2)

    Awesome! I will try it out when I get back home.

    hang on, I’ll try adding that now to see if it’s harmless, and then add it to the DEV code…

    looks ok IF you add a ‘;’ at the end of the apply_filters line

    right now I can’t update the SVN to add those lines to the DEV version. i’ve just discovered that Mountain Lion doesn’t have SVN by default, and the main way to install it is to download the 1.5GB Xcode install :-/

    that’s live in the dev version now

    https://www.ads-software.com/extend/plugins/widget-logic/developers/

    filter: widget_logic_eval_override

    any function hooked into this filter is passed the widget logic text. you can return the text altered in some way before it is EVAL’d, or you can bypass any EVAL’ing happening by returning with a boolean TRUE (show widget) or FALSE (don’t show)

    Thread Starter Mohan Chevuri

    (@mchev2)

    Thanks! I downloaded it from dev. I’m writing a small plugin to use the filter. I will let you know how it works.

    Thread Starter Mohan Chevuri

    (@mchev2)

    It works. Could you also add a filter or something for the “WL field text”, which says “Widget Logic”. Then I will be able to add a link/popup to display some help.

    OR

    You can add a tiny help link which by default points to “https://www.ads-software.com/extend/plugins/widget-logic/other_notes/”. Then if you provide a way to change the link, I will change it to point to this plugin help page.

    Whichever you think will be more appropriate.

    (been off the grid for a couple of weeks, will get back and look at this soon)

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘[Plugin: Widget Logic] Hook to override eval and to use custom function for logic validation’ is closed to new replies.