@@ 1754-1768 (lines=15) @@ | ||
1751 | * @param string $context 'display' or 'edit' |
|
1752 | * @return bool |
|
1753 | */ |
|
1754 | function current_user_can_access_post_type( $post_type, $context = 'display' ) { |
|
1755 | $post_type_object = get_post_type_object( $post_type ); |
|
1756 | if ( ! $post_type_object ) { |
|
1757 | return false; |
|
1758 | } |
|
1759 | ||
1760 | switch ( $context ) { |
|
1761 | case 'edit': |
|
1762 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
1763 | case 'display': |
|
1764 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
1765 | default: |
|
1766 | return false; |
|
1767 | } |
|
1768 | } |
|
1769 | ||
1770 | function is_post_type_allowed( $post_type ) { |
|
1771 | // if the post type is empty, that's fine, WordPress will default to post |
@@ 237-251 (lines=15) @@ | ||
234 | return $post; |
|
235 | } |
|
236 | ||
237 | public function current_user_can_access_post_type( $post_type, $context ) { |
|
238 | $post_type_object = $this->get_post_type_object( $post_type ); |
|
239 | if ( ! $post_type_object ) { |
|
240 | return false; |
|
241 | } |
|
242 | ||
243 | switch( $context ) { |
|
244 | case 'edit': |
|
245 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
246 | case 'display': |
|
247 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
248 | default: |
|
249 | return false; |
|
250 | } |
|
251 | } |
|
252 | ||
253 | protected function get_post_type_object( $post_type ) { |
|
254 | return get_post_type_object( $post_type ); |