Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Bug with Gantry widget filter
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chris  
View profile  
 More options Jan 25 2012, 10:58 am
From: Chris <chris.mavri...@gmail.com>
Date: Wed, 25 Jan 2012 07:58:42 -0800 (PST)
Local: Wed, Jan 25 2012 10:58 am
Subject: Bug with Gantry widget filter
Hi,

I'm the author of a WordPress plugin and had a customer that was
having trouble with Gantry.  Basically, adding widgets via my plugin
was causing errors to be thrown by Gantry.

Warning: Invalid argument supplied for foreach() in /home/laundro/
public_html/wp-content/plugins/gantry/core/renderers/
gantrywidgetsrenderer.class.php on line 154

After digging through the Gantry code for a while, this is what I've
found:

From what I can tell, Gantry augments the WordPress widgets with a
"widget_map" (not sure exactly its purpose, but I don't think it's a
core WordPress feature).  Then Gantry adds a filter to the widgets,
and it assumes this widget_map exists, attempting to access it in an
array.  I'm guessing the widget_map doesn't exist because this is a
widget area added by a plugin rather than Gantry.  However, the filter
is applied to all widgets and doesn't check to see if the widget_map
exists.  Since it doesn't, it throws an error.  Since the filter
throws an error, it returns null, and the parameters it filters get
cleared, so this actually causes 2 errors, and the second prevents the
widget from being displayed.

The (potential) solution:

Add a check to the Gantry function to ignore widgets without the
widget_map parameter:

if( !isset( $params[0]['widget_map'] )) return $params;

This would be placed in plugins/gantry/core/renderers/
gantrywidgetsrenderer.class.php, around line 148, so you end up with
this as the filterWidget() function:

function filterWidget($params) {

        if( !isset( $params[0]['widget_map'] )) return $params;

        global $gantry;

        $widget_id = $params[0]['widget_id'];
        $layout = $params[0]['layout'];

        // find the widget and its position
        foreach ($params[0]['widget_map'] as $pos => $position_info){
            $position_widgets = $position_info['widgets'];
            if (!array_key_exists($widget_id,$position_widgets))
continue;
            $params[0]['position'] = $pos;
            $params[0]['end'] = end(array_keys($position_widgets));
            $params[0]['start'] =
reset(array_keys($position_widgets));
            break;
        }

        $params = $gantry->renderLayout('widget_'.$layout, $params);

        return $params;
    }

The only alternative I could find would be to temporarily remove the
filter in any other plugin in order to avoid the error:

        if(function_exists('dynamic_sidebar')){

                //Gantry-specific
                remove_filter('dynamic_sidebar_params',
array('GantryWidgetsRenderer', 'filterWidget'));

                ob_start();
                echo '<ul id="mysidebar">';
                dynamic_sidebar($name);
                echo '</ul>';

                //Gantry-specific
                add_filter('dynamic_sidebar_params', array('GantryWidgetsRenderer',
'filterWidget'));

                return ob_get_clean();
        }

Of course that's just a hack and clearly not optimal.  A filter
shouldn't throw errors because a non-standard field is missing when
calling a standard WordPress function.

Hope you'll either add that fix or a comparable one to your next
release!  It doesn't seem like something that can be solved gracefully
from outside your framework.

Thanks!

Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »