1 , 'public' => current_user_can('delete_others_posts') , 'labels' => array( 'all_items' => __('All') , 'popular_items' => __('Popular') , 'edit_item' => __('Edit') , 'view_item' => __('View') , 'update_item' => __('Update') , 'search_items' => __('Search') , 'add_new_item' => __('Add') , 'new_item_name' => __('Name') , 'add_or_remove_items' => __('Add or remove') , 'choose_from_most_used' => __('Most used') , 'not_found' => __('Not found') , 'separate_items_with_commas' => 'Use WP roles, capabilities, or user IDs.' , 'name' => $name , 'singular_name' => $name )) )); # Accommodate late post types. add_action('init', function() use ($tax, &$types, &$avoid) { if (taxonomy_exists($tax)) foreach (array_diff(get_post_types(), $types, $avoid) as $type) register_taxonomy_for_object_type($tax, $type); unset($types, $avoid); }, 100); # Define the "test access" callback via filter to enable override. add_filter("@$tax:test", function($fn, $user = null) use ($tax) { # Callback result grants (truthy) or denies (falsey) access. # Grant when not applicable, when no terms are applied, or when *any* term passes. $applicable = taxonomy_exists($tax) && !is_404() and $user = $user ?: wp_get_current_user(); return $applicable ? function($post = null) use ($tax, $user) { $grant = 1; $terms = get_the_terms($post, $tax); if ($terms && is_array($terms) and $grant--) foreach (wp_list_pluck($terms, 'slug') as $slug) if ($grant = is_numeric($slug) ? $user->id === $slug : $user->has_cap($slug)) break; return !!$grant; } : '__return_true'; }, 0, 2); add_action('loop_start', function(&$query) use ($tax, $cases) { $test = apply_filters("@$tax:test", null); $denies = array(); foreach ($query->posts as $i => $post) is_int($i) && call_user_func($test, $post) or $denies[] = array_splice($query->posts, $i, 1)[0]; $case = $cases[$denies ? $query->posts ? 1 : 0 : 2]; $hold = 'message'; $hook = "@$tax:$hold"; $msg = apply_filters($hook, '', $query->posts, $denies); foreach (array_diff($cases, array($case)) as $not) $msg = apply_filters("$hook:!$not", $msg, $query->posts, $denies); $msg = apply_filters("$hook:$case", $msg, $query->posts, $denies); if ($msg) echo "