| @@ 242-256 (lines=15) @@ | ||
| 239 | return $post; |
|
| 240 | } |
|
| 241 | ||
| 242 | public function current_user_can_access_post_type( $post_type, $context ) { |
|
| 243 | $post_type_object = $this->get_post_type_object( $post_type ); |
|
| 244 | if ( ! $post_type_object ) { |
|
| 245 | return false; |
|
| 246 | } |
|
| 247 | ||
| 248 | switch( $context ) { |
|
| 249 | case 'edit': |
|
| 250 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
| 251 | case 'display': |
|
| 252 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
| 253 | default: |
|
| 254 | return false; |
|
| 255 | } |
|
| 256 | } |
|
| 257 | ||
| 258 | protected function get_post_type_object( $post_type ) { |
|
| 259 | return get_post_type_object( $post_type ); |
|
| @@ 1766-1780 (lines=15) @@ | ||
| 1763 | * @param string $context 'display' or 'edit' |
|
| 1764 | * @return bool |
|
| 1765 | */ |
|
| 1766 | function current_user_can_access_post_type( $post_type, $context = 'display' ) { |
|
| 1767 | $post_type_object = get_post_type_object( $post_type ); |
|
| 1768 | if ( ! $post_type_object ) { |
|
| 1769 | return false; |
|
| 1770 | } |
|
| 1771 | ||
| 1772 | switch ( $context ) { |
|
| 1773 | case 'edit': |
|
| 1774 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
| 1775 | case 'display': |
|
| 1776 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
| 1777 | default: |
|
| 1778 | return false; |
|
| 1779 | } |
|
| 1780 | } |
|
| 1781 | ||
| 1782 | function is_post_type_allowed( $post_type ) { |
|
| 1783 | // if the post type is empty, that's fine, WordPress will default to post |
|