acf_form_front::submit_form
This function will submit form data
Метод класса: acf_form_front{}
Хуки из метода
Возвращает
n/a.
Использование
$acf_form_front = new acf_form_front(); $acf_form_front->submit_form( $form );
- $form(обязательный)
- .
Список изменений
| С версии 5.5.10 | Введена. |
Код acf_form_front::submit_form() acf form front::submit form ACF 6.8.11
function submit_form( $form ) {
// filter
$form = apply_filters( 'acf/pre_submit_form', $form );
// vars
$post_id = acf_maybe_get( $form, 'post_id', 0 );
// add global for backwards compatibility
$GLOBALS['acf_form'] = $form;
// allow for custom save
$post_id = apply_filters( 'acf/pre_save_post', $post_id, $form );
// Restrict $_POST['acf'] to the field keys the form actually exposed, so the
// save path cannot accept values for fields the form did not render.
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified in check_submit_form().
$allowed_keys = $this->get_allowed_field_keys( $form );
if ( isset( $_POST['acf'] ) && is_array( $_POST['acf'] ) ) {
$_POST['acf'] = array_intersect_key( $_POST['acf'], array_flip( $allowed_keys ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Sanitized downstream; save pipeline expects slashed input.
}
// Uploads write back into $_POST['acf'], so restrict them to the same keys.
acf_restrict_uploaded_field_keys( $allowed_keys );
// Basic uploader nonces are signed for the form's render (see render_form()).
$render_id = $this->get_submitted_render_id();
acf_set_upload_render_ids( $render_id ? array( 'acf_form/' . $render_id ) : array() );
// phpcs:enable WordPress.Security.NonceVerification.Missing
// save
acf_save_post( $post_id );
// restore form (potentially modified)
$form = $GLOBALS['acf_form'];
// action
do_action( 'acf/submit_form', $form, $post_id );
// vars
$return = acf_maybe_get( $form, 'return', '' );
// redirect
if ( $return ) {
// update %placeholders%
$return = str_replace( '%post_id%', $post_id, $return );
$return = str_replace( '%post_url%', get_permalink( $post_id ), $return );
// redirect
wp_redirect( $return ); //phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- unsafe redirects allowed.
exit;
}
}