Skip to main content
misspelled.
Source Link
Jake
  • 1.8k
  • 20
  • 16

Unfortunately, admin_head-{pluginname} runs after things have already been outputted to the page, so you cancan't do a redirect there. You need to do it sooner.

View load order here: http://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_an_Admin_Page_Request

You could plugin to "admin_init" instead and then just manually test for the page:

add_action( 'admin_init', 'redirect_media_library_wpse_93626' );
function redirect_media_library_wpse_93626()
{
    // Add this extra test to make sure you are on the right page.
    if ( $GLOBALS['pagenow'] != 'upload.php' ) return;
    
    // Stop if not Multisite
    if ( !is_multisite() ) return;
    
    // Stop if is main site
    if ( is_main_blog() ) return;
    
    // Stop if is administrator
    if ( current_user_can( 'add_users' ) ) return;
    
    // Finally, redirect
    // wp_redirect( site_url( 'personal-page' ) ); // http://subsite.example.com/personal-page
    // wp_redirect( 'http://example.com' );
    wp_redirect( admin_url() ); // http://subsite.example.com/wp-admin
    exit();
}

Unfortunately, admin_head-{pluginname} runs after things have already been outputted to the page, so you can do a redirect there. You need to do it sooner.

View load order here: http://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_an_Admin_Page_Request

You could plugin to "admin_init" instead and then just manually test for the page:

add_action( 'admin_init', 'redirect_media_library_wpse_93626' );
function redirect_media_library_wpse_93626()
{
    // Add this extra test to make sure you are on the right page.
    if ( $GLOBALS['pagenow'] != 'upload.php' ) return;
    
    // Stop if not Multisite
    if ( !is_multisite() ) return;
    
    // Stop if is main site
    if ( is_main_blog() ) return;
    
    // Stop if is administrator
    if ( current_user_can( 'add_users' ) ) return;
    
    // Finally, redirect
    // wp_redirect( site_url( 'personal-page' ) ); // http://subsite.example.com/personal-page
    // wp_redirect( 'http://example.com' );
    wp_redirect( admin_url() ); // http://subsite.example.com/wp-admin
    exit();
}

Unfortunately, admin_head-{pluginname} runs after things have already been outputted to the page, so you can't do a redirect there. You need to do it sooner.

View load order here: http://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_an_Admin_Page_Request

You could plugin to "admin_init" instead and then just manually test for the page:

add_action( 'admin_init', 'redirect_media_library_wpse_93626' );
function redirect_media_library_wpse_93626()
{
    // Add this extra test to make sure you are on the right page.
    if ( $GLOBALS['pagenow'] != 'upload.php' ) return;
    
    // Stop if not Multisite
    if ( !is_multisite() ) return;
    
    // Stop if is main site
    if ( is_main_blog() ) return;
    
    // Stop if is administrator
    if ( current_user_can( 'add_users' ) ) return;
    
    // Finally, redirect
    // wp_redirect( site_url( 'personal-page' ) ); // http://subsite.example.com/personal-page
    // wp_redirect( 'http://example.com' );
    wp_redirect( admin_url() ); // http://subsite.example.com/wp-admin
    exit();
}
Source Link
Jake
  • 1.8k
  • 20
  • 16

Unfortunately, admin_head-{pluginname} runs after things have already been outputted to the page, so you can do a redirect there. You need to do it sooner.

View load order here: http://codex.wordpress.org/Plugin_API/Action_Reference#Actions_Run_During_an_Admin_Page_Request

You could plugin to "admin_init" instead and then just manually test for the page:

add_action( 'admin_init', 'redirect_media_library_wpse_93626' );
function redirect_media_library_wpse_93626()
{
    // Add this extra test to make sure you are on the right page.
    if ( $GLOBALS['pagenow'] != 'upload.php' ) return;
    
    // Stop if not Multisite
    if ( !is_multisite() ) return;
    
    // Stop if is main site
    if ( is_main_blog() ) return;
    
    // Stop if is administrator
    if ( current_user_can( 'add_users' ) ) return;
    
    // Finally, redirect
    // wp_redirect( site_url( 'personal-page' ) ); // http://subsite.example.com/personal-page
    // wp_redirect( 'http://example.com' );
    wp_redirect( admin_url() ); // http://subsite.example.com/wp-admin
    exit();
}