Skip to content

Commit 2e36fc4

Browse files
enejbkangzj
authored andcommitted
Forms: Start using the new feedvack version v3 (#45047)
* Forms: Finally store the feedback in the new format Replaces manual construction and insertion of feedback posts with a call to the response object's save() method, simplifying the code and improving maintainability. Also updates a test to use unescaped apostrophes in the subject assertion. * changelog
1 parent bb560cd commit 2e36fc4

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: added
3+
4+
Forms: Finally store the feedback in the new format

projects/packages/forms/src/contact-form/class-contact-form.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,8 +1658,6 @@ public function process_submission() {
16581658
// Initialize all these "standard" fields to null
16591659
$comment_author_email = $response->get_author_email();
16601660
$comment_author = $response->get_author();
1661-
$comment_author_url = $response->get_author_url();
1662-
$comment_content = $response->get_comment_content();
16631661

16641662
$contact_form_subject = $response->get_subject();
16651663

@@ -1784,11 +1782,6 @@ public function process_submission() {
17841782

17851783
$all_values['email_marketing_consent'] = $email_marketing_consent;
17861784

1787-
// Build feedback reference
1788-
$feedback_time = $response->get_time();
1789-
$feedback_title = $response->get_title();
1790-
$feedback_id = $response->get_feedback_id();
1791-
17921785
$entry_values = $response->get_entry_values();
17931786

17941787
/** This filter is already documented in \Automattic\Jetpack\Forms\ContactForm\Admin */
@@ -1859,20 +1852,11 @@ public function process_submission() {
18591852
$comment_author_ip = null;
18601853
}
18611854

1862-
$comment_ip_text = $comment_author_ip ? "IP: {$comment_author_ip}\n" : null;
1863-
1864-
$post_id = wp_insert_post(
1865-
array(
1866-
'post_date' => addslashes( $feedback_time ),
1867-
'post_type' => 'feedback',
1868-
'post_status' => addslashes( $feedback_status ),
1869-
'post_parent' => $this->current_post ? (int) self::get_post_property( $this->current_post, 'ID' ) : 0,
1870-
'post_title' => addslashes( wp_kses( $feedback_title, array() ) ),
1871-
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.InterpolatedVariableNotSnakeCase, WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.PHP.DevelopmentFunctions.error_log_print_r
1872-
'post_content' => addslashes( wp_kses( "$comment_content\n<!--more-->\nAUTHOR: {$comment_author}\nAUTHOR EMAIL: {$comment_author_email}\nAUTHOR URL: {$comment_author_url}\nSUBJECT: {$subject}\n{$comment_ip_text}JSON_DATA\n" . @wp_json_encode( $all_values, true ), array() ) ), // so that search will pick up this data
1873-
'post_name' => $feedback_id,
1874-
)
1875-
);
1855+
$post_id = 0;
1856+
$feedback_post = $response->save();
1857+
if ( $feedback_post instanceof WP_Post ) {
1858+
$post_id = $feedback_post->ID;
1859+
}
18761860

18771861
// once insert has finished we don't need this filter any more
18781862
remove_filter( 'wp_insert_post_data', array( $plugin, 'insert_feedback_filter' ), 10 );

projects/packages/forms/tests/php/contact-form/Contact_Form_Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public function test_process_submission_will_store_subject_when_specified() {
421421
$response = Feedback::get( $feedback_id );
422422

423423
// Default metadata should be saved.
424-
$this->assertEquals( "I\'m sorry, but the party\'s over", $response->get_subject(), 'The stored subject didn\'t match the given' );
424+
$this->assertEquals( "I'm sorry, but the party's over", $response->get_subject(), 'The stored subject didn\'t match the given' );
425425
}
426426

427427
/**

0 commit comments

Comments
 (0)