• Gavin Smith

    (@gavinsmithleapcomau)


    Hi

    I have installed the Restrict Widgets plugin on a WordPress 3.6.1 multisite running on IIS 7.5 and PHP 5.4

    I am receiving the following PHP warning message:
    ‘[18-Oct-2013 00:08:36 UTC] PHP Warning: array_keys() expects parameter 1 to be array, null given in C:\inetpub\wwwroot\wp-content\plugins\restrict-widgets\restrict-widgets.php on line 218’
    ‘[18-Oct-2013 00:08:36 UTC] PHP Warning: in_array() expects parameter 2 to be array, null given in C:\inetpub\wwwroot\wp-content\plugins\restrict-widgets\restrict-widgets.php on line 218’

    The Restricts Widgets menu item doesn’t appear.

    https://www.ads-software.com/plugins/restrict-widgets/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author dFactory

    (@dfactory)

    Thanks Gavin. The answer is quite simple: Restrict Widgets is not multisite compatible yet, but we added that feature to our to-do list as you can see here https://www.dfactory.eu/plugins/restrict-widgets/

    I just ran across this on my multi-site. The way I fixed it was to edit the ‘restrict_sidebar_params’ function in ‘restrict-widgets.php’ by adding in a few more checks to the variables being used.

    /**
    	 * Hides widgets for users without admin privileges
    	*/
    	public function restrict_sidebar_params($params)
    	{
    		if(!current_user_can('manage_options'))
    		{
    			global $wp_registered_widgets;
    
    			$option = get_option('rw_widgets_options');
    
    			$widgetid = $params[0]['widget_id'];
    			$callback = $wp_registered_widgets[$widgetid]['callback'][0];
    			$registeredid = $wp_registered_widgets[$widgetid]['id'];
    			$callback_class = get_class($callback);
    			$available = $option['available'];
    
    			if( isset($widgetid) && (
    
    				//standard based widget class
    				(isset($callback) && is_object($callback) && isset($callback_class) && isset($available) && in_array($callback_class, array_keys($available))) ||
    
    				//non-standard based widget
    				(isset($registeredid) && isset($available) && in_array($registeredid, array_keys($available)))
    			))
    				$params[0]['_hide'] = 1;
    		}
    
    		return $params;
    	}

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP Warnings for array_keys() and in_array()’ is closed to new replies.