• This plugin seems to be buggy.

    Warning: Invalid argument supplied for foreach() in /wp-content/plugins/product-specifications/inc/admin/class-admin.php on line 139

    WP 5.6

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Backpack.Studio

    (@backpackstudio)

    Related code:

    		foreach( $submenu['dw-specs'] as $k => $d ){
    			if( $d[2] == 'dw-specs-new' ){
    				$submenu['dw-specs'][$k][2] = 'post-new.php?post_type=specs-table';
    				break;
    			}
    		}
    Thread Starter Backpack.Studio

    (@backpackstudio)

    Seems to be invalid code.

    	/**
    	 * Modify menu page urls
    	*/
    	public static function modify_menu_urls(){
    		global $menu, $submenu;
    
    		foreach( $submenu['dw-specs'] as $k => $d ){
    			if( $d[2] == 'dw-specs-new' ){
    				$submenu['dw-specs'][$k][2] = 'post-new.php?post_type=specs-table';
    				break;
    			}
    		}
    	}

    Variable $menu not used at all. Why it is defined at all?

    Why there is no check if function is called too earlier on why it’s called at admin login etc?

    Code below avoids errors:

    	/**
    	 * Modify menu page urls
    	*/
    	public static function modify_menu_urls(){
    		global $submenu;
    		if(is_array($submenu) && isset($submenu['dw-specs'])){
    			foreach( $submenu['dw-specs'] as $k => $d ){
    				if( $d[2] == 'dw-specs-new' ){
    					$submenu['dw-specs'][$k][2] = 'post-new.php?post_type=specs-table';
    					break;
    				}
    			}
    		}
    	}
    Plugin Author Dornaweb

    (@dornaweb)

    Couldn’t re-produce the error
    Can you please specify your WordPress and the plugin version?

    Thread Starter Backpack.Studio

    (@backpackstudio)

    Thank you for response.

    As mentioned above, version of WordPress is 5.6, the latest. Plugin version is also the latest – 0.4.1.

    As you see from my post above, the code has bad logic, no any validation of external variables, also an unnecessary variable is defined. On such case if you use external variables, you have to validate these before using.

    It’s irrelevant if you can or cannot reproduce this error, because your code have used has an open door for errors! Please fix the code.

    Plugin Author Dornaweb

    (@dornaweb)

    Thank you for your report, we will fix and update the plugin ASAP

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Cannot login into admin – Invalid argument supplied for foreach()’ is closed to new replies.