acf_form_comment::get_allowed_field_keys
Returns the top-level ACF field keys that are allowed to be saved for the given comment. Built from the field groups whose comment location rules match the comment's post type.
Метод класса: acf_form_comment{}
Хуки из метода
Возвращает
array.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_allowed_field_keys( $comment_id );
- $comment_id(int) (обязательный)
- The ID of comment being saved.
Список изменений
| С версии 6.8.7 | Введена. |
Код acf_form_comment::get_allowed_field_keys() acf form comment::get allowed field keys ACF 6.8.8
private function get_allowed_field_keys( $comment_id ) {
$keys = array();
$comment = get_comment( $comment_id );
if ( $comment ) {
$field_groups = acf_get_field_groups(
array(
'comment' => get_post_type( $comment->comment_post_ID ),
)
);
foreach ( $field_groups as $field_group ) {
foreach ( acf_get_fields( $field_group ) as $field ) {
$prefix = $field['prefix'] ?? 'acf';
if ( $prefix === 'acf' ) {
if ( ! empty( $field['key'] ) ) {
$keys[] = $field['key'];
}
} elseif ( preg_match( '/^acf\[([^]]+)]$/', $prefix, $matches ) ) {
$keys[] = $matches[1];
}
}
}
}
$keys = array_values( array_unique( array_filter( $keys ) ) );
/**
* Filters the list of $_POST['acf'] keys a comment submission is allowed to save.
*
* Use this to permit additional field keys when a developer dynamically injects
* fields into the comment form via JavaScript that aren't part of a field group
* whose location rules target this comment.
*
* @since 6.8.7
*
* @param array $keys The allowed top-level $_POST['acf'] keys.
* @param int $comment_id The comment being saved.
*/
$keys = apply_filters( 'acf/form/comment/allowed_field_keys', $keys, $comment_id );
// Re-normalize after the filter so a misbehaving callback can't break array_flip().
$keys = array_filter( (array) $keys, 'is_scalar' );
return array_values( array_unique( array_filter( array_map( 'strval', $keys ) ) ) );
}