Last active
March 21, 2017 11:44
-
-
Save aiiddqd/fe4a1866c8980a5ac77f to your computer and use it in GitHub Desktop.
Контроль доступа к постам WordPress основанный на метаполе 'acl_users_s' в котором записан список ИД пользователей, для которых есть доступ к посту
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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