_acf_get_block_reader()
The internal ACF function to return the user whose read access is checked for an ACF Block's relational field values while it renders.
Editing previews and previews of posts can show data the current user has just entered, so they're checked against the current user.
Otherwise, blocks saved in a post or synced pattern were saved by someone who can edit it, so they're checked against its author, wherever its content is shown, such as on the front end or in the REST API. Posts the author picked show to every visitor, and posts they couldn't have picked are left out, even if an editor published the post without noticing them. Posts that an editor picked for another user's post, and that the author can't read, are left out too.
Blocks rendered by a synced pattern are saved in the pattern, and other blocks rendered by the_content saved in the current post. Posts whose content is shown inside a synced pattern, such as by a Query Loop in the pattern, are treated as part of the pattern.
Blocks that aren't saved in a post or synced pattern are checked against the current user if they're rendered in the admin, by AJAX or by a REST API endpoint, such as the block renderer, which can render any data. On the front end, they're in places like template parts and widgets, which only users who can edit the theme can change, so they aren't checked.
Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.
Хуков нет.
Возвращает
WP_User|false. The user, or false if the block's values aren't checked.
Использование
_acf_get_block_reader( $is_preview );
- $is_preview(true|false) (обязательный)
- Whether the block is being rendered for an editing preview.
Список изменений
| С версии 6.8.11 | Введена. |
Код _acf_get_block_reader() acf get block reader ACF 6.8.11
function _acf_get_block_reader( $is_preview ) {
if ( $is_preview || is_preview() ) {
return wp_get_current_user();
}
$source = acf_get_data( 'acf_synced_pattern' );
if ( ! $source && doing_filter( 'the_content' ) ) {
$source = get_post();
}
if ( $source ) {
return new WP_User( (int) $source->post_author );
}
if ( is_admin() || wp_doing_ajax() || acf_get_data( 'acf_rest_block_render_depth' ) ) {
return wp_get_current_user();
}
return false;
}