Skip to content

Instantly share code, notes, and snippets.

@uptimizt
Last active March 21, 2017 11:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uptimizt/fe4a1866c8980a5ac77f to your computer and use it in GitHub Desktop.
Save uptimizt/fe4a1866c8980a5ac77f to your computer and use it in GitHub Desktop.
Контроль доступа к постам WordPress основанный на метаполе 'acl_users_s' в котором записан список ИД пользователей, для которых есть доступ к посту
<?php
if ( ! function_exists( 'acl_filter_posts_where' ) ) :
function acl_filter_posts_where($where){
global $wpdb;
$current_user_id = get_current_user_id();
$where .= " AND ($wpdb->posts.post_type != 'post'
OR $wpdb->posts.ID IN (
SELECT post_id
FROM $wpdb->postmeta
WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID
AND $wpdb->postmeta.meta_key = 'cmdb_acl'
AND $wpdb->postmeta.meta_value like '%\"$current_user_id\"%'
))";
return $where;
}
endif;
add_filter('posts_where', 'acl_filter_posts_where');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment