What's the best way to prevent a plugin from redirecting

HI,
What's the best way to prevent a plugin from redirecting to a default page after its being activate. Ex: when woocommerce is activated for the first time, it redirects the user to sitename.com/wp-admin/index.php?page=wc-about, how do i prevent woocommerce or anyother plugin from doing that. i just want to check if the current page is equal to whatever and then just redirect to sitename.com/wp-admin/
Thanks in advanced.

  • Adam Czajczyk

    Hey Thomas,

    I hope you're well today and thank you for your question!

    Some of the plugins indeed redirect user to the plugin's "welcome" or settings page. Not every plugin does this and it's in fact a matter of a plugin code.

    Plugins that do this usually use a core WP function: wp_redirect().

    Disabling/overwriting this function is not an option here because it would most likely break a lot of other WordPress features. However, this function is usually called by "register_activation_hook()" from inside the plugin.

    The hard part here is that although you could disable it entirely with some custom code, it would most likely break plugin's activation procedure as well. That said, the only way would be to examine the code of selected plugin(s) to find out if "register_activation_hook()" calls out only the "wp_redirect()" function or a bunch of other functions too.

    If it does call "wp_redirect()" only, then it might be possible to disable it, but in most cases (including WooCommerce) this wouldn't be an option as "register_activation_hook()" do a lot of other things required to make plugin work.

    Furthermore, some plugins may do the redirect on "admin_init" filter and this complicates things even more.

    Having said that, I think this is not quite possible, unless done upon a particular plugin. It would also require some custom coding job.

    If you have any further questions, please ask. I'll be glad to assist.

    Cheers,
    Adam

  • Tom Whittaker

    sort of come up with a solution, that requires of changing the core code. i will just to update that code everytime i update woocommerce

    public function admin_menus() {
    		$welcome_page_name  = __( 'About WooCommerce', 'woocommerce' );
    		$welcome_page_title = __( 'Welcome to WooCommerce', 'woocommerce' );
    		switch ( $_GET['page'] ) {
    			case 'wc-about' :
    				$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'wc-about', array( $this, 'about_screen' ) );
    				add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) );
    			break;
    			case 'wc-credits' :
    				$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'wc-credits', array( $this, 'credits_screen' ) );
    				add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) );
    			break;
    			case 'wc-translators' :
    				$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'wc-translators', array( $this, 'translators_screen' ) );
    				add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) );
    			break;
    		}
    	}

    so i change manage_options to manage_network_options'

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.