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