acf_form_comment::save_comment
Saves ACF field values to a comment.
Method of the class: acf_form_comment{}
No Hooks.
Returns
Int|null.
Usage
$acf_form_comment = new acf_form_comment(); $acf_form_comment->save_comment( $comment_id );
- $comment_id(int) (required)
- The ID of the comment being saved to.
Changelog
| Since 5.0.0 | Introduced. |
acf_form_comment::save_comment() acf form comment::save comment code ACF 6.8.8
public function save_comment( $comment_id ) {
// bail early if not valid nonce
if ( ! acf_verify_nonce( 'comment' ) ) {
return $comment_id;
}
if ( isset( $_POST['acf'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified above.
if ( ! is_array( $_POST['acf'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified above.
return $comment_id;
}
// Restrict $_POST['acf'] to keys of fields belonging to field groups that apply to this comment.
$allowed_keys = $this->get_allowed_field_keys( $comment_id );
$_POST['acf'] = array_intersect_key( $_POST['acf'], array_flip( $allowed_keys ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Verified above; sanitized below.
if ( empty( $_POST['acf'] ) ) {
return $comment_id;
}
$_POST['acf'] = wp_kses_post_deep( $_POST['acf'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized with wp_kses_post_deep().
}
// validate and save
if ( acf_validate_save_post( true ) ) {
acf_save_post( "comment_{$comment_id}" );
}
}