| @@ 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 ); |
|
| @@ 1649-1663 (lines=15) @@ | ||
| 1646 | * @param string $context 'display' or 'edit' |
|
| 1647 | * @return bool |
|
| 1648 | */ |
|
| 1649 | function current_user_can_access_post_type( $post_type, $context='display' ) { |
|
| 1650 | $post_type_object = get_post_type_object( $post_type ); |
|
| 1651 | if ( ! $post_type_object ) { |
|
| 1652 | return false; |
|
| 1653 | } |
|
| 1654 | ||
| 1655 | switch( $context ) { |
|
| 1656 | case 'edit': |
|
| 1657 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
| 1658 | case 'display': |
|
| 1659 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
| 1660 | default: |
|
| 1661 | return false; |
|
| 1662 | } |
|
| 1663 | } |
|
| 1664 | ||
| 1665 | function is_post_type_allowed( $post_type ) { |
|
| 1666 | // if the post type is empty, that's fine, WordPress will default to post |
|