@@ 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 |
@@ 173-187 (lines=15) @@ | ||
170 | return $post; |
|
171 | } |
|
172 | ||
173 | public function current_user_can_access_post_type( $post_type, $context ) { |
|
174 | $post_type_object = $this->get_post_type_object( $post_type ); |
|
175 | if ( ! $post_type_object ) { |
|
176 | return false; |
|
177 | } |
|
178 | ||
179 | switch( $context ) { |
|
180 | case 'edit': |
|
181 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
182 | case 'display': |
|
183 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
184 | default: |
|
185 | return false; |
|
186 | } |
|
187 | } |
|
188 | ||
189 | protected function get_post_type_object( $post_type ) { |
|
190 | return get_post_type_object( $post_type ); |