acf_form_front::render_form │ public │ ACF 5.4.0
description
Метод класса: acf_form_front{}
Хуков нет.
Возвращает
$post_id. (int)
Использование
$acf_form_front = new acf_form_front(); $acf_form_front->render_form( $args );
- $args
- .
По умолчанию: array()
Список изменений
| С версии 5.4.0 | Введена. |
Код acf_form_front::render_form() acf form front::render form ACF 6.4.2
<?php
function render_form( $args = array() ) {
// Vars.
$is_registered = false;
$field_groups = array();
$fields = array();
// Allow form settings to be directly provided.
if ( is_array( $args ) ) {
$args = $this->validate_form( $args );
// Otherwise, lookup registered form.
} else {
$is_registered = true;
$args = $this->get_form( $args );
if ( ! $args ) {
return false;
}
}
// Extract vars.
$post_id = $args['post_id'];
// Prevent ACF from loading values for "new_post".
if ( $post_id === 'new_post' ) {
$post_id = false;
}
// Set uploader type.
acf_update_setting( 'uploader', $args['uploader'] );
// Register local fields.
foreach ( $this->get_default_fields() as $k => $field ) {
acf_add_local_field( $field );
}
// Append post_title field.
if ( $args['post_title'] ) {
$_post_title = acf_get_field( '_post_title' );
$_post_title['value'] = $post_id ? get_post_field( 'post_title', $post_id ) : '';
$fields[] = $_post_title;
}
// Append post_content field.
if ( $args['post_content'] ) {
$_post_content = acf_get_field( '_post_content' );
$_post_content['value'] = $post_id ? get_post_field( 'post_content', $post_id ) : '';
$fields[] = $_post_content;
}
// Load specific fields.
if ( $args['fields'] ) {
// Lookup fields using $strict = false for better compatibility with field names.
foreach ( $args['fields'] as $selector ) {
$fields[] = acf_maybe_get_field( $selector, $post_id, false );
}
// 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' );
}
// Display updated_message
if ( ! empty( $_GET['updated'] ) && $args['updated_message'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Used as a flag; data not used.
printf( $args['html_updated_message'], $args['updated_message'] ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- designed to contain potentially unsafe HTML, set by developers.
}
// display form
if ( $args['form'] ) : ?>
<form <?php echo acf_esc_attrs( $args['form_attributes'] ); ?>>
<?php
endif;
// Render hidde form data.
acf_form_data(
array(
'screen' => 'acf_form',
'post_id' => $args['post_id'],
'form' => $is_registered ? $args['id'] : acf_encrypt( json_encode( $args ) ),
)
);
?>
<div class="acf-fields acf-form-fields -<?php echo esc_attr( $args['label_placement'] ); ?>">
<?php echo $args['html_before_fields']; ?><?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- designed to contain potentially unsafe HTML, set by developers. ?>
<?php acf_render_fields( $fields, $post_id, $args['field_el'], $args['instruction_placement'] ); ?>
<?php echo $args['html_after_fields']; ?><?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- designed to contain potentially unsafe HTML, set by developers. ?>
</div>
<?php if ( $args['form'] ) : ?>
<div class="acf-form-submit">
<?php printf( $args['html_submit_button'], $args['submit_value'] ); ?><?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- designed to contain potentially unsafe HTML, set by developers. ?>
<?php echo $args['html_submit_spinner']; ?><?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- designed to contain potentially unsafe HTML, set by developers. ?>
</div>
</form>
<?php endif;
}