_acf_get_unreadable_post_statuses()
The internal ACF function to return the statuses of a post type's posts that the current user can't read when another user wrote them, following how core maps the read_post capability.
Core lets users read other users' draft, pending and scheduled posts only if they can edit them, which for scheduled posts also requires the capability to edit published posts. Other users' private posts require the capability to read private posts. Post types that don't map meta capabilities let users with the post type's read capability read all of its posts.
Access granted to individual posts can't be known here, so sites that grant it can use the acf/fields/relational/unreadable_post_statuses filter.
Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.
Хуки из функции
Возвращает
string[].
Использование
_acf_get_unreadable_post_statuses( $post_type );
- $post_type(строка) (обязательный)
- The post type.
Список изменений
| С версии 6.8.11 | Введена. |
Код _acf_get_unreadable_post_statuses() acf get unreadable post statuses ACF 6.8.11
function _acf_get_unreadable_post_statuses( $post_type ) {
$post_type_object = get_post_type_object( $post_type );
$protected_statuses = get_post_stati( array( 'protected' => true ) );
$private_statuses = get_post_stati( array( 'private' => true ) );
if ( ! $post_type_object ) {
return array_values( array_merge( $protected_statuses, $private_statuses ) );
}
$statuses = array();
if ( ! $post_type_object->map_meta_cap ) {
// `read_post` and `read_page` are meta capabilities, which can't be checked without a post.
$read_cap = $post_type_object->cap->read_post;
$can_read = ! in_array( $read_cap, array( 'read_post', 'read_page' ), true ) && current_user_can( $read_cap );
if ( ! $can_read ) {
$statuses = array_merge( $protected_statuses, $private_statuses );
}
} else {
if ( ! current_user_can( $post_type_object->cap->edit_others_posts ) ) {
$statuses = $protected_statuses;
} elseif ( ! current_user_can( $post_type_object->cap->edit_published_posts ) ) {
$statuses = array_intersect( $protected_statuses, array( 'future' ) );
}
if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
$statuses = array_merge( $statuses, $private_statuses );
}
}
/**
* Filters the statuses of other users' posts that relational field searches hide from the current user.
*
* Posts with a status removed here are included in the search query, and each is then checked with
* `acf_current_user_can_read_post()`, so posts the user can't read are still left out. Use this when
* access to individual posts is granted, such as through the `acf/user_can_read_post` filter
* or a `map_meta_cap` callback. Pages of results may then contain fewer posts, or none, and the next
* page being loaded can show that the search matched posts the user can't read.
*
* @since 6.8.11
*
* @param string[] $statuses The statuses hidden from the current user.
* @param string $post_type The post type.
*/
$statuses = apply_filters( 'acf/fields/relational/unreadable_post_statuses', array_values( $statuses ), $post_type );
return array_values( array_filter( (array) $statuses, 'is_string' ) );
}