I want my plugin to redirect to a page when some conditions are not met after plugin activation. I keep getting To many redirects... error message.

My code is as shown below:

if (! defined('WPINC')) die;
if (! class_exists('AwesomePlugin')) {

    class AwesomePlugin {
        public function __construct(){
            //Register admin menus
            add_action('admin_menu', [$this, add_menu]);

            //Init plugin
            add_action('admin_init', [$this, 'init_plugin']);

         * Init plugin
        public function init_plugin(){
                wp_redirect("admin.php?page=some-page"); exit; //This gives too many redirects
            wp_redirect('admin.php?page=dashboard'); exit;

         * Add menu and submenu items 
        public function add_menu(){
                'Dashboard', 'Dashboard', 'manage_options', 'dashboard', 
                [__CLASS__, 'load_dashboard_view'], 
                plugins_url('logo.png', __FILE__)

                '', 'Signup page', 'Signup page', 'manage_options', 
                'sign-up', [__CLASS__, 'load_signup_view']

         * Dashboard page 
        public function load_dashboard_view(){
            include(plugin_dir_path(__FILE__) . 'dashboard.php');

         * Signup page
        public function load_signup_view(){
            include(plugin_dir_path(__FILE__) . 'signup.php');


What am I missing?

EDIT: I understand that no matter the page I'm loading, the init_plugin function keeps firing. As a result, it keeps redirecting the user to the sign-up, thus the many redirect error message. How do I solve this?

  • 2
    You code perform a redirect if some_option is not set on every admin page load, it you don't set it up, the condition to redirect will be always true in every page load. You just need to think about a proper workflow for your purpose, which is what?
    – cybmeta
    Commented Sep 29, 2017 at 15:09

1 Answer 1


This will help you want you want to achieve.

// Add option
register_activation_hook( __FILE__, 'me_shakeeb_install' );
function me_shakeeb_install() {

    $result = 'signup'; // Perform your logic here to decide where to redirect
    add_option( 'me_shakeeb_redirect_to', $result );

// Check Option
add_action( 'init', 'me_shakeeb_signup_check' );
function me_shakeeb_signup_check() {

     * Redirect to about page.
    if ( false !== get_option( 'me_shakeeb_redirect_to', false ) ) {
        $page = get_option( 'me_shakeeb_redirect_to', false );
        delete_option( 'me_shakeeb_redirect_to' );
        wp_redirect( admin_url( 'admin.php?page=$page' ) );

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.