Uncategorized Control wp media files by specific user
As my previous post , i explained how to use WordPress media file uploader. with this script you can WordPress media uploader manager as per your requirement but in that post you can not control the files by specific users.
Now we can control WordPress media file manager and images and files by user specific.For that we have to use hook up the pre_post_query that is action that filter WP Query Object.We have to just pass current logged in user’s ID in WP Query set. Copy and paste this script into your theme’s functions.php.
<?php function set_auther( $query ) { $user_ID = get_current_user_id(); /*if run this hook for specific template then you can use is_page_template( 'your-template-file.php' ) if ( $query->is_home() ) { $query->set( 'author', $user_ID ); } */ if ( $query->is_home() ) { $query->set( 'author', $user_ID ); } } add_action( 'pre_get_posts', 'set_auther' ); ?>
Note : This hook every where apply when a user is logged in means it will effect for wp query and this wp query used by post query , search query, fetch media files.So please use page screen condition for this Hook.