| @@ 199-213 (lines=15) @@ | ||
| 196 | return $post; |
|
| 197 | } |
|
| 198 | ||
| 199 | public function current_user_can_access_post_type( $post_type, $context ) { |
|
| 200 | $post_type_object = $this->get_post_type_object( $post_type ); |
|
| 201 | if ( ! $post_type_object ) { |
|
| 202 | return false; |
|
| 203 | } |
|
| 204 | ||
| 205 | switch( $context ) { |
|
| 206 | case 'edit': |
|
| 207 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
| 208 | case 'display': |
|
| 209 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
| 210 | default: |
|
| 211 | return false; |
|
| 212 | } |
|
| 213 | } |
|
| 214 | ||
| 215 | protected function get_post_type_object( $post_type ) { |
|
| 216 | return get_post_type_object( $post_type ); |
|
| @@ 1719-1733 (lines=15) @@ | ||
| 1716 | * @param string $context 'display' or 'edit' |
|
| 1717 | * @return bool |
|
| 1718 | */ |
|
| 1719 | function current_user_can_access_post_type( $post_type, $context = 'display' ) { |
|
| 1720 | $post_type_object = get_post_type_object( $post_type ); |
|
| 1721 | if ( ! $post_type_object ) { |
|
| 1722 | return false; |
|
| 1723 | } |
|
| 1724 | ||
| 1725 | switch ( $context ) { |
|
| 1726 | case 'edit': |
|
| 1727 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
| 1728 | case 'display': |
|
| 1729 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
| 1730 | default: |
|
| 1731 | return false; |
|
| 1732 | } |
|
| 1733 | } |
|
| 1734 | ||
| 1735 | function is_post_type_allowed( $post_type ) { |
|
| 1736 | // if the post type is empty, that's fine, WordPress will default to post |
|