Allow to see only the media files and images uploaded by the user in wordpress

Hi in this tutorial we are going to learn how to make Allow to see only the media files and images uploaded by the user in wordpress.

Allow to see only the media files and images uploaded by the user in wordpress

Write the code in functions.php file inside your theme folder
add_action(‘pre_get_posts’,’hm_users_own_attachments’);
function hm_users_own_attachments( $wp_query_obj ) {

global $current_user, $pagenow;

$is_attachment_request = ($wp_query_obj->get(‘post_type’)==’attachment’);

if( !$is_attachment_request )
return;

if( !is_a( $current_user, ‘WP_User’) )
return;

if( !in_array( $pagenow, array( ‘upload.php’, ‘admin-ajax.php’ ) ) )
return;

if( !current_user_can(‘delete_pages’) )
$wp_query_obj->set(‘author’, $current_user->ID );

return;
}
?>

Please provide your valuable comment to make the site more useful.

Thanks for reading

Share The Post On -

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.