• Resolved alx359

    (@alx359)


    Hello, found an issue with the URL of a menu of another well-established plugin not getting rendered correctly when AME is active. Please refer to this issue, thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Janis Elsts

    (@whiteshadow)

    Thank you for the report. It looks like this is another annoying case where a plugin removes a menu item using the admin_head action instead of the admin_menu action. Because Admin Menu Editor has already finished processing the admin menu by that time (it has to do that to properly apply menu permissions), it doesn’t “see” the removal and the item remains in the admin menu.

    In this case, that item happens to be a non-functional placeholder that was automatically created by WP core: Stripe Gateway -> Stripe Gateway. Because it’s the first item in the “Stripe Gateway” submenu, that also changes the URL of the top level “Stripe Gateway” menu.

    I’ll add that submenu item to the internal menu blacklist. The conflict should be fixed in the next update. Or you can try the development version that already includes this patch.

    “Stripe For WooCommerce” could also fix the conflict by changing this line:
    add_action( 'admin_head', array( __CLASS__, 'remove_submenu' ) );

    To this:
    add_action( 'admin_menu', array( __CLASS__, 'remove_submenu' ), 30 );

    The idea is to use the admin_menu hook. The priority only needs to be changed to ensure that the method that removes the submenu runs after the method that adds the submenu.

    Thread Starter alx359

    (@alx359)

    Thank you for your detailed answer. Tried your suggestion of adding 30 priority to remove_submenu, but it didn’t work for me. Anyway, have referred your previous post into the OP.

    Plugin Author Janis Elsts

    (@whiteshadow)

    Just changing the priority is not enough, the important bit is changing the hook from admin_head to admin_menu.

    Thread Starter alx359

    (@alx359)

    Nope, it still doesn’t work for me. Here’s the entire block of pertinent code:

    public static function init() {
    	add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ), 10 );
    	add_action( 'admin_menu', array( __CLASS__, 'sub_menu' ), 20 );
      //add_action( 'admin_head', array( __CLASS__, 'remove_submenu' ) );
        add_action( 'admin_menu', array( __CLASS__, 'remove_submenu', 30 ) ); #alx359
    }
    
    public static function admin_menu() {
    	add_menu_page( __( 'Stripe Gateway', 'woo-stripe-payment' ), __( 'Stripe Gateway', 'woo-stripe-payment' ), 'manage_woocommerce', 
    }
    
    public static function sub_menu() {
    	add_submenu_page( 'wc_stripe', __( 'Settings', 'woo-stripe-payment' ), __( 'Settings', 'woo-stripe-payment' ), 
    	add_submenu_page( 'wc_stripe', __( 'Logs', 'woo-stripe-payment' ), __( 'Logs', 'woo-stripe-payment' ), 'manage_woocommerce', 
    	add_submenu_page( 'wc_stripe', __( 'Documentation', 'woo-stripe-payment' ), __( 'Documentation', 'woo-stripe-payment' ), 
    }
    
    public static function remove_submenu() {
    	global $submenu;
    	if ( isset( $submenu['wc_stripe'] ) ) {
    		unset( $submenu['wc_stripe'][0] );
    	}
    }
    Plugin Author Janis Elsts

    (@whiteshadow)

    It looks like there’s a typo in your code: the 30 is in the wrong place. It should be the third argument to add_action(), but it’s inside the callback array instead.

    That line should look like this:
    add_action( 'admin_menu', array( __CLASS__, 'remove_submenu' ), 30 ); #alx359

    Thread Starter alx359

    (@alx359)

    Oops, you’re right. Now it works. Thank you! 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Menu Issue with another plugin’ is closed to new replies.