WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Widget Logic] Hook to override eval and to use custom function for logic validation

[Resolved] [Plugin: Widget Logic] Hook to override eval and to use custom function for logic validation

  • 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!

    http://wordpress.org/extend/plugins/widget-logic/

Viewing 15 replies - 1 through 15 (of 18 total)
  • Something like this…

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

    Plugin Author alanft
    Member

    @alanft

    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

    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.

    Plugin Author alanft
    Member

    @alanft

    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)

    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.

    Plugin Author alanft
    Member

    @alanft

    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 πŸ˜‰

    Thanks much!

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

    Plugin Author alanft
    Member

    @alanft

    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?

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

    Plugin Author alanft
    Member

    @alanft

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

    Plugin Author alanft
    Member

    @alanft

    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 :-/

    Plugin Author alanft
    Member

    @alanft

    that’s live in the dev version now

    http://wordpress.org/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)

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

    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 “http://wordpress.org/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.

    Plugin Author alanft
    Member

    @alanft

    (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 ‘[Resolved] [Plugin: Widget Logic] Hook to override eval and to use custom function for logic validation’ is closed to new replies.