acf_form_front::pre_save_post
pre_save_post
description
Method of the class: acf_form_front{}
No Hooks.
Returns
$post_id. (int)
Usage
$acf_form_front = new acf_form_front(); $acf_form_front->pre_save_post( $post_id, $form );
- $post_id(required)
- .
- $form(required)
- .
Changelog
| Since 5.4.0 | Introduced. |
acf_form_front::pre_save_post() acf form front::pre save post code ACF 6.0.4
function pre_save_post( $post_id, $form ) {
// vars
$save = array(
'ID' => 0,
);
// determine save data
if ( is_numeric( $post_id ) ) {
// update post
$save['ID'] = $post_id;
} elseif ( $post_id == 'new_post' ) {
// merge in new post data
$save = array_merge( $save, $form['new_post'] );
} else {
// not post
return $post_id;
}
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified in check_submit_form().
// save post_title
if ( isset( $_POST['acf']['_post_title'] ) ) {
$save['post_title'] = acf_extract_var( $_POST['acf'], '_post_title' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized by WP when saved.
}
// save post_content
if ( isset( $_POST['acf']['_post_content'] ) ) {
$save['post_content'] = acf_extract_var( $_POST['acf'], '_post_content' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized by WP when saved.
}
// phpcs:enable WordPress.Security.NonceVerification.Missing
// honeypot
if ( ! empty( $_POST['acf']['_validate_email'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Data not used; presence indicates spam.
return false;
}
// validate
if ( count( $save ) == 1 ) {
return $post_id;
}
// save
if ( $save['ID'] ) {
wp_update_post( $save );
} else {
$post_id = wp_insert_post( $save );
}
// return
return $post_id;
}