@@ 1588-1602 (lines=15) @@ | ||
1585 | * @param string $context 'display' or 'edit' |
|
1586 | * @return bool |
|
1587 | */ |
|
1588 | function current_user_can_access_post_type( $post_type, $context='display' ) { |
|
1589 | $post_type_object = get_post_type_object( $post_type ); |
|
1590 | if ( ! $post_type_object ) { |
|
1591 | return false; |
|
1592 | } |
|
1593 | ||
1594 | switch( $context ) { |
|
1595 | case 'edit': |
|
1596 | return current_user_can( $post_type_object->cap->edit_posts ); |
|
1597 | case 'display': |
|
1598 | return $post_type_object->public || current_user_can( $post_type_object->cap->read_private_posts ); |
|
1599 | default: |
|
1600 | return false; |
|
1601 | } |
|
1602 | } |
|
1603 | ||
1604 | function is_post_type_allowed( $post_type ) { |
|
1605 | // if the post type is empty, that's fine, WordPress will default to post |
@@ 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 ); |