АП
Size: a a a
АП
K
PK
EV
K
И
# Скрывать Чужие Записи, Комментарии, Медиафайлы От Других Авторов В Админке
function posts_for_current_author($query) {
global $pagenow;
if( 'edit.php' != $pagenow || !$query->is_admin )
return $query;
if( !current_user_can( 'edit_others_posts' ) ) {
global $user_ID;
$query->set('author', $user_ID );
}
return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');
if( is_admin() ) // мы ведь только в админке скрываем, да?
add_filter('parse_query', 'true_hide_attachments_2' );
function true_hide_attachments_2( $wp_query ) {
global $current_user;
if ( !current_user_can('administrator') // администраторов всё так же не трогаем
&& isset( $wp_query->query_vars['post_type'] ) // защищаемся от Notices :)
&& $wp_query->query_vars['post_type']=="attachment" ) // тип поста - вложения
$wp_query->set( 'author', $current_user->data->ID );
}
add_filter( 'pre_get_comments', function ( $data ) {
// Выходим, если не админка
if ( ! is_admin() ) {
return;
}
$screen = get_current_screen();
// Проверяем, что текущая страница страница с комментариями и текущий пользователь не Админ
if ( $screen->base === 'edit-comments' && ! current_user_can( 'manage_options' ) ) {
// Указываем запрашивать комментарии только текущего пользователя
$data->query_vars['user_id'] = get_current_user_id();
}
} );
KZ
ТВ
PK
B
И
ОК
TD
N
AP
G
ПМ
АП
IH
АП