| @@ 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 |
|
| @@ 207-221 (lines=15) @@ | ||
| 204 | return $post; |
|
| 205 | } |
|
| 206 | ||
| 207 | public function current_user_can_access_post_type( $post_type, $context ) { |
|
| 208 | $post_type_object = $this->get_post_type_object( $post_type ); |
|
| 209 | if ( ! $post_type_object ) { |
|
| 210 | return false; |
|
| 211 | } |
|
| 212 | ||
| 213 | switch( $context ) { |
|
| 214 | case 'edit': |
|
| 215 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
| 216 | case 'display': |
|
| 217 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
| 218 | default: |
|
| 219 | return false; |
|
| 220 | } |
|
| 221 | } |
|
| 222 | ||
| 223 | protected function get_post_type_object( $post_type ) { |
|
| 224 | return get_post_type_object( $post_type ); |
|