User permissions to upload images

Only logged in user can upload media from front end. Below code will allow users to see only their media files and not others. Put this in your theme’s functions.php file. I hope this helps.


add_action( 'pre_get_posts', 'users_own_attachments');
function users_own_attachments( $wp_query_obj )
    {
        global $current_user, $pagenow;

        if ( $pagenow == 'upload.php' || ( $pagenow == 'admin-ajax.php' && !empty( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'query-attachments' ) ) {
            $wp_query_obj->set( 'author', $current_user->ID );
        }
    }

tech