0

Both of these methods remove and restrict access to the WooCommerce "Extensions" menu page in the admin, which is what I want. But which method is more ideal?

By removing it (option 1) or by overriding the filter that creates it (option 2)?

Both options seem to work fine.

Option 1:

add_action('admin_menu', 'fs_remove_admin_menu_links', 999);
function fs_remove_admin_menu_links(){
    $user = wp_get_current_user();
    if( $user && isset($user->user_email) && '[email protected]' == $user->user_email ) {
        remove_submenu_page('woocommerce', 'wc-addons');
    }
}

Option 2:

function fs_new_remove_admin_menu_links() {
    $user = wp_get_current_user();
    if( $user && isset($user->user_email) && '[email protected]' == $user->user_email ) {
        return false;
    }
    return true;
}
add_filter( 'woocommerce_show_addons_page', 'fs_new_remove_admin_menu_links' );

The goal is just to prevent access to the page for a certain user.

It seems to be added via the WooCommerce plugin by a function that includes:

if ( apply_filters( 'woocommerce_show_addons_page', true ) ) {
    add_action( 'admin_menu', array( $this, 'addons_menu' ), 70 );
}
2
  • the filter looks like be made for removing acces to this page then I would use that. but instead of testing the e-mail adress, you can test a role then you can give this role to more users with no needs to edit the code.
    – mmm
    Commented Oct 24, 2017 at 19:38
  • The end goal is to remove this page for everyone who doesn't have a registered email address with a certain domain (e.g., everyone outside of Example Company). So here is what I've decided to use for now: gist.github.com/Garconis/3674f897893589f55ab6e17e3a0dd605
    – Garconis
    Commented Oct 24, 2017 at 19:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.