@@ 1743-1757 (lines=15) @@ | ||
1740 | * @param string $context 'display' or 'edit' |
|
1741 | * @return bool |
|
1742 | */ |
|
1743 | function current_user_can_access_post_type( $post_type, $context = 'display' ) { |
|
1744 | $post_type_object = get_post_type_object( $post_type ); |
|
1745 | if ( ! $post_type_object ) { |
|
1746 | return false; |
|
1747 | } |
|
1748 | ||
1749 | switch ( $context ) { |
|
1750 | case 'edit': |
|
1751 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
1752 | case 'display': |
|
1753 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
1754 | default: |
|
1755 | return false; |
|
1756 | } |
|
1757 | } |
|
1758 | ||
1759 | function is_post_type_allowed( $post_type ) { |
|
1760 | // if the post type is empty, that's fine, WordPress will default to post |
@@ 228-242 (lines=15) @@ | ||
225 | return $post; |
|
226 | } |
|
227 | ||
228 | public function current_user_can_access_post_type( $post_type, $context ) { |
|
229 | $post_type_object = $this->get_post_type_object( $post_type ); |
|
230 | if ( ! $post_type_object ) { |
|
231 | return false; |
|
232 | } |
|
233 | ||
234 | switch( $context ) { |
|
235 | case 'edit': |
|
236 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
237 | case 'display': |
|
238 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
239 | default: |
|
240 | return false; |
|
241 | } |
|
242 | } |
|
243 | ||
244 | protected function get_post_type_object( $post_type ) { |
|
245 | return get_post_type_object( $post_type ); |