| @@ 187-201 (lines=15) @@ | ||
| 184 | return $post; |
|
| 185 | } |
|
| 186 | ||
| 187 | public function current_user_can_access_post_type( $post_type, $context ) { |
|
| 188 | $post_type_object = $this->get_post_type_object( $post_type ); |
|
| 189 | if ( ! $post_type_object ) { |
|
| 190 | return false; |
|
| 191 | } |
|
| 192 | ||
| 193 | switch( $context ) { |
|
| 194 | case 'edit': |
|
| 195 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
| 196 | case 'display': |
|
| 197 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
| 198 | default: |
|
| 199 | return false; |
|
| 200 | } |
|
| 201 | } |
|
| 202 | ||
| 203 | protected function get_post_type_object( $post_type ) { |
|
| 204 | return get_post_type_object( $post_type ); |
|
| @@ 1676-1690 (lines=15) @@ | ||
| 1673 | * @param string $context 'display' or 'edit' |
|
| 1674 | * @return bool |
|
| 1675 | */ |
|
| 1676 | function current_user_can_access_post_type( $post_type, $context='display' ) { |
|
| 1677 | $post_type_object = get_post_type_object( $post_type ); |
|
| 1678 | if ( ! $post_type_object ) { |
|
| 1679 | return false; |
|
| 1680 | } |
|
| 1681 | ||
| 1682 | switch( $context ) { |
|
| 1683 | case 'edit': |
|
| 1684 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
| 1685 | case 'display': |
|
| 1686 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
| 1687 | default: |
|
| 1688 | return false; |
|
| 1689 | } |
|
| 1690 | } |
|
| 1691 | ||
| 1692 | function is_post_type_allowed( $post_type ) { |
|
| 1693 | // if the post type is empty, that's fine, WordPress will default to post |
|