<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否

/***** 投稿者権限までのユーザーは自身のメディアのみ表示 *****/
/* https://www.wpbeginner.com/plugins/how-to-restrict-media-library-access-to-users-own-uploads-in-wordpress/ */
function haup_show_current_user_attachments( $query ) {
	$user_id = get_current_user_id();
	if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts
') ) {
		$query['author'] = $user_id;
	}
		return $query;
}
add_filter( 'ajax_query_attachments_args', 'haup_show_current_user_attachments' );