0

I would like to redirect authors when they visit the URL mynetwork.com/OWNBLOG/wp-admin/upload.php to another page. How can I do that?

I tried this code but i received this error :

"Warning: Cannot modify header information - headers already sent by (output started at /home/content/59/104129/html/wp-admin/includes/template.php:1642) in /home/content/59/10412659/html/wp-includes/pluggable.php on line 876" :

add_action( 'admin_head-upload.php', 'redirect_media_library_wpse_93626' );

function redirect_media_library_wpse_93626()
{
    // 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();
}
0

2 Answers 2

0

If I understand you, he hook you want (WordPress 3.5.1) is load-upload.php.

Proof of concept:

function t_wpse_94284() {
  wp_redirect(home_url()); 
  exit;
}
add_action('load-upload.php','t_wpse_94284');

That hook should fire only on /wp-admin/upload.php and, though I haven't tested it, I think that your function should work just fine as it is.

0
0

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();
}
0

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.