_acf_get_allowed_save_keys()
Returns the submitted top-level keys a save may accept for an object.
A key is accepted if it is in a verified field list for one of the render IDs (it was rendered for this user and object), or, without a list, if it belongs to a top-level field of a field group whose location rules match the object. Everything else is dropped, and logged when WP_DEBUG is on.
Fields hidden only by acf/prepare_field can still be submitted without a list. Conditional logic is not evaluated.
Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.
Хуки из функции
Возвращает
array. The allowed top-level keys.
Использование
_acf_get_allowed_save_keys( $submitted, $args );
- $submitted(массив) (обязательный)
- The submitted top-level keys.
- $args(массив) (обязательный)
- See acf_filter_save_values().
Список изменений
| С версии 6.8.11 | Введена. |
Код _acf_get_allowed_save_keys() acf get allowed save keys ACF 6.8.11
function _acf_get_allowed_save_keys( $submitted, $args ) {
$args = wp_parse_args(
$args,
array(
'context' => '',
'post_id' => 0,
'render_ids' => array(),
'lists' => null,
'screen' => array(),
'filter_arg' => null,
'flat_clone_keys' => false,
)
);
if ( null === $args['lists'] ) {
// phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Verified by the caller; each list is verified as a nonce.
$args['lists'] = isset( $_POST['_acf_fields'] ) ? wp_unslash( $_POST['_acf_fields'] ) : array();
}
$submitted = array_values( array_unique( array_map( 'strval', $submitted ) ) );
$verified = acf_get_verified_field_keys( $args['lists'], (array) $args['render_ids'] );
if ( $args['flat_clone_keys'] ) {
$verified = array_merge( $verified, _acf_get_verified_flat_clone_keys( $verified, $submitted ) );
}
$located = _acf_get_located_field_keys( array_values( array_diff( $submitted, $verified ) ), $args['screen'], $args['flat_clone_keys'] );
/**
* Filters the top-level field keys a save is allowed to persist.
*
* The dynamic portion of the hook name, `$context`, refers to the save context: `post`, `user`,
* `taxonomy`, `comment`, `attachment`, `nav_menu`, `nav_menu_item`, `widget`, `options_page`,
* `woo_order` or `datastore`.
*
* Use this to permit additional field keys, for example when inputs are added to a form by
* JavaScript, or for fields rendered outside a field group whose location rules match the object.
*
* @since 6.8.7 For the `user` and `comment` contexts.
* @since 6.8.11 For the other contexts.
*
* @param array $keys The allowed top-level keys.
* @param integer|string|array $post_id The object being saved. The user or comment ID for the `user` and
* `comment` contexts, the options page settings for `options_page`;
* the ACF post ID otherwise.
*/
$filter_arg = null === $args['filter_arg'] ? $args['post_id'] : $args['filter_arg'];
$keys = apply_filters( "acf/form/{$args['context']}/allowed_field_keys", array_merge( $verified, $located ), $filter_arg );
$keys = acf_normalize_field_keys( $keys );
_acf_log_dropped_field_keys( $submitted, $keys, $args );
return $keys;
}