acf_map_post_meta_caps()
Prevents WordPress's own custom field editing from changing post meta that belongs to an ACF field.
The Custom Fields meta box (metakeyinput and meta[] in the post form), wp_ajax_add_meta and XML-RPC custom_fields check these capabilities. Without this, a user who can edit a post could write values for ACF fields that aren't shown to them, bypassing ACF's save checks. ACF saves its own values without these checks. Meta keys registered with register_meta() and protected meta keys are left to WordPress.
Хуков нет.
Возвращает
string[].
Использование
acf_map_post_meta_caps( $caps, $cap, ...$context );
- $caps(string[]) (обязательный)
- The primitive capabilities required.
- $cap(строка) (обязательный)
- The capability being checked.
- ...$context(разное) (обязательный)
- The user ID, and the post ID and meta key.
Список изменений
| С версии 6.8.11 | Введена. |
Код acf_map_post_meta_caps() acf map post meta caps ACF 6.8.11
function acf_map_post_meta_caps( $caps, $cap, ...$context ) {
// The user ID isn't needed: the capability is denied whoever the user is.
$args = isset( $context[1] ) ? (array) $context[1] : array();
if ( ! in_array( $cap, array( 'add_post_meta', 'edit_post_meta', 'delete_post_meta' ), true ) || ! isset( $args[0], $args[1] ) || ! is_string( $args[1] ) ) {
return $caps;
}
$post_id = (int) $args[0];
$meta_key = $args[1];
$post_type = (string) get_post_type( $post_id );
if ( registered_meta_key_exists( 'post', $meta_key, $post_type ) || registered_meta_key_exists( 'post', $meta_key ) || is_protected_meta( $meta_key, 'post' ) ) {
return $caps;
}
if ( _acf_is_field_meta_key( $post_id, $meta_key ) ) {
$caps[] = 'do_not_allow';
}
return $caps;
}