Redirect Function Prevents Images from Showing in Front-end Media Uploader


I have a simple redirect function in a custom plugin to prevent users from accessing WP Admin area in a multi-site installation.

The plugin enables users manage contents and their profile at the front-end and gives access to uploading via WP Media Uploader.

While all works well, once I have the said redirect function active, users without the given capability can no longer see the images when the Media Uploader launches.

Here is the redirect function with the given capability:

function my_noAdminAccess(){
    if( !current_user_can( 'delete_others_posts' ) ){
        if( wp_get_referer() ){
            exit( wp_safe_redirect( wp_get_referer() ) );
            exit( wp_safe_redirect( site_url('/') ) );
add_action( 'admin_init', 'my_noAdminAccess', 100 );

I need the function active but how can it work without affecting the Media Uploader images?

, , Tunji Makanjuola 3 years 2020-08-26T17:10:21-05:00 0 Answers 52 views 0

Leave an answer