| @@ 161-175 (lines=15) @@ | ||
| 158 | return $post; |
|
| 159 | } |
|
| 160 | ||
| 161 | public function current_user_can_access_post_type( $post_type, $context ) { |
|
| 162 | $post_type_object = $this->get_post_type_object( $post_type ); |
|
| 163 | if ( ! $post_type_object ) { |
|
| 164 | return false; |
|
| 165 | } |
|
| 166 | ||
| 167 | switch( $context ) { |
|
| 168 | case 'edit': |
|
| 169 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
| 170 | case 'display': |
|
| 171 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
| 172 | default: |
|
| 173 | return false; |
|
| 174 | } |
|
| 175 | } |
|
| 176 | ||
| 177 | protected function get_post_type_object( $post_type ) { |
|
| 178 | return get_post_type_object( $post_type ); |
|
| @@ 1644-1658 (lines=15) @@ | ||
| 1641 | * @param string $context 'display' or 'edit' |
|
| 1642 | * @return bool |
|
| 1643 | */ |
|
| 1644 | function current_user_can_access_post_type( $post_type, $context='display' ) { |
|
| 1645 | $post_type_object = get_post_type_object( $post_type ); |
|
| 1646 | if ( ! $post_type_object ) { |
|
| 1647 | return false; |
|
| 1648 | } |
|
| 1649 | ||
| 1650 | switch( $context ) { |
|
| 1651 | case 'edit': |
|
| 1652 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
| 1653 | case 'display': |
|
| 1654 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
| 1655 | default: |
|
| 1656 | return false; |
|
| 1657 | } |
|
| 1658 | } |
|
| 1659 | ||
| 1660 | function is_post_type_allowed( $post_type ) { |
|
| 1661 | // if the post type is empty, that's fine, WordPress will default to post |
|