Duplicates all comments for this form and attaches them to another given form.
Description
See also
Parameters
- $form_id
-
(int) (Required) New form ID to attach the comments to.
Source
File: src/db-objects/forms/form.php
protected function duplicate_comments_for_form( $form_id ) { if ( ! post_type_supports( $this->manager->get_prefix() . 'form', 'comments' ) ) { return; } $mappings = array(); $comments = get_comments( array( 'post_id' => $this->original->ID, ) ); foreach ( $comments as $comment ) { $comment_data = get_comment( $comment, ARRAY_A ); $comment_data['comment_post_ID'] = $form_id; $old_id = $comment_data['comment_ID']; unset( $comment_data['comment_ID'] ); $new_id = wp_insert_comment( $comment_data ); $mappings[ $old_id ] = $new_id; } foreach ( $mappings as $old_id => $new_id ) { $comment_data = get_comment( $new_id, ARRAY_A ); if ( 0 === absint( $comment_data['comment_parent'] ) ) { continue; } if ( ! isset( $mappings[ $comment_data['comment_parent'] ] ) ) { continue; } $comment_data['comment_parent'] = $mappings[ $comment_data['comment_parent'] ]; wp_update_comment( $comment_data ); } }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |