$file[‘error’] except if

Question

Only administrators can upload images to the site.

EDIT:
However, the author can create a page and when he creates it, I want to allow him to upload, but only then.

function tomjn_only_upload_for_admin( $file ) {
    if ( ! current_user_can( 'manage_options' ) ) { 
        if ( $pagenow !== "post-new.php" ) {
         $file['error'] = 'You can\'t upload images without admin privileges!'; 
        }        
    }
    return $file;
}
add_filter( 'wp_handle_upload_prefilter', 'tomjn_only_upload_for_admin' );
0
Olvas0 3 months 2022-05-24T11:11:03-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse