acf_form_front::get_form_fields
Returns the fields a given form configuration will expose, mirroring the selection logic used by render_form().
Used by render_form() to discover what to render, and by submit_form() to derive the set of $_POST['acf'] keys the save path will accept.
Метод класса: acf_form_front{}
Хуков нет.
Возвращает
array.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_form_fields( $args ): array;
- $args(массив) (обязательный)
- The validated form configuration.
Список изменений
| С версии 6.8.2 | Введена. |
Код acf_form_front::get_form_fields() acf form front::get form fields ACF 6.8.8
protected function get_form_fields( array $args ): array {
$fields = array();
$field_groups = array();
$post_id = $args['post_id'];
// Prevent ACF from loading values for "new_post".
if ( $post_id === 'new_post' ) {
$post_id = false;
}
// Register local default fields so the special _post_title / _post_content / _validate_email
// keys are resolvable via acf_get_field().
foreach ( $this->get_default_fields() as $field ) {
acf_add_local_field( $field );
}
// Append post_title field.
if ( $args['post_title'] ) {
$fields[] = acf_get_field( '_post_title' );
}
// Append post_content field.
if ( $args['post_content'] ) {
$fields[] = acf_get_field( '_post_content' );
}
// Load specific fields.
if ( $args['fields'] ) {
foreach ( $args['fields'] as $selector ) {
if ( $post_id ) {
// Lookup fields using $strict = false for better compatibility with field names.
$fields[] = acf_maybe_get_field( $selector, $post_id, false );
} else {
// No post to resolve meta references against — skip acf_maybe_get_field()'s
// post_id resolution, which can fatal in get_queried_object() if submit_form()
// runs before WordPress's main query is built.
$fields[] = acf_get_field( $selector );
}
}
// Load specific field groups.
} elseif ( $args['field_groups'] ) {
foreach ( $args['field_groups'] as $selector ) {
$field_groups[] = acf_get_field_group( $selector );
}
// Load fields for the given "new_post" args.
} elseif ( $args['post_id'] === 'new_post' ) {
$field_groups = acf_get_field_groups( $args['new_post'] );
// Load fields for the given "post_id" arg.
} else {
$field_groups = acf_get_field_groups(
array(
'post_id' => $args['post_id'],
)
);
}
// Load fields from the found field groups.
if ( $field_groups ) {
foreach ( $field_groups as $field_group ) {
$_fields = acf_get_fields( $field_group );
if ( $_fields ) {
foreach ( $_fields as $_field ) {
$fields[] = $_field;
}
}
}
}
// Add honeypot field.
if ( $args['honeypot'] ) {
$fields[] = acf_get_field( '_validate_email' );
}
return array_filter( $fields );
}