-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: error not showing after post form submission #1510
base: develop
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,7 +173,7 @@ | |
public function draft_post() { | ||
check_ajax_referer( 'wpuf_form_add' ); | ||
add_filter( 'wpuf_form_fields', [ $this, 'add_field_settings' ] ); | ||
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); | ||
Check warning on line 176 in includes/Frontend/Frontend_Form.php
|
||
|
||
$form_id = isset( $_POST['form_id'] ) ? intval( wp_unslash( $_POST['form_id'] ) ) : 0; | ||
$form = new Form( $form_id ); | ||
|
@@ -181,7 +181,7 @@ | |
$this->form_fields = $form->get_fields(); | ||
$pay_per_post = $form->is_enabled_pay_per_post(); | ||
|
||
[ $post_vars, $taxonomy_vars, $meta_vars ] = $this->get_input_fields( $this->form_fields ); | ||
|
||
$entry_fields = $form->prepare_entries(); | ||
$allowed_tags = wp_kses_allowed_html( 'post' ); | ||
|
@@ -275,7 +275,7 @@ | |
|
||
wpuf_clear_buffer(); | ||
|
||
echo json_encode( | ||
[ | ||
'post_id' => $post_id, | ||
'action' => isset( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '', | ||
|
@@ -309,7 +309,7 @@ | |
$this->form_fields = $form->get_fields(); | ||
$this->form_settings = $form->get_settings(); | ||
$this->generate_auth_link(); // Translate tag %login% %registration% to login registartion url | ||
[ $user_can_post, $info ] = $form->is_submission_open( $form, $this->form_settings ); | ||
$info = apply_filters( 'wpuf_addpost_notice', $info, $id, $this->form_settings ); | ||
$user_can_post = apply_filters( 'wpuf_can_post', $user_can_post, $id, $this->form_settings ); | ||
|
||
|
@@ -330,9 +330,9 @@ | |
* @since 2.5.8 | ||
*/ | ||
public function publish_guest_post() { | ||
$post_msg = isset( $_GET['post_msg'] ) ? sanitize_text_field( wp_unslash( $_GET['post_msg'] ) ) : ''; | ||
Check warning on line 333 in includes/Frontend/Frontend_Form.php
|
||
$pid = isset( $_GET['p_id'] ) ? sanitize_text_field( wp_unslash( $_GET['p_id'] ) ) : ''; | ||
Check warning on line 334 in includes/Frontend/Frontend_Form.php
|
||
$fid = isset( $_GET['f_id'] ) ? sanitize_text_field( wp_unslash( $_GET['f_id'] ) ) : ''; | ||
Check warning on line 335 in includes/Frontend/Frontend_Form.php
|
||
|
||
if ( $post_msg !== 'verified' ) { | ||
return; | ||
|
@@ -360,9 +360,9 @@ | |
get_permalink( wpuf_get_option( 'payment_page', 'wpuf_payment' ) ) | ||
); | ||
|
||
wp_redirect( $response['redirect_to'] ); | ||
Check warning on line 363 in includes/Frontend/Frontend_Form.php
|
||
wpuf_clear_buffer(); | ||
wp_send_json( $response ); | ||
wp_send_json_error( $response ); | ||
} | ||
} else { | ||
$p_status = get_post_status( $post_id ); | ||
|
@@ -437,10 +437,10 @@ | |
public function get_edit_post_link( $url, $post_id ) { | ||
if ( | ||
current_user_can( 'edit_post', $post_id ) | ||
&& ! current_user_can( 'administrator' ) | ||
&& ! current_user_can( 'editor' ) | ||
&& ! current_user_can( 'author' ) | ||
&& ! current_user_can( 'contributor' ) | ||
) { | ||
$post = get_post( $post_id ); | ||
$form_id = get_post_meta( $post_id, '_wpuf_form_id', true ); | ||
|
@@ -497,7 +497,7 @@ | |
* @return void | ||
*/ | ||
public function send_mail_to_admin_after_guest_mail_verified() { | ||
$post_id = ! empty( $_GET['p_id'] ) ? wpuf_decryption( sanitize_text_field( wp_unslash( $_GET['p_id'] ) ) ) : 0; | ||
$form_id = ! empty( $_GET['f_id'] ) ? wpuf_decryption( sanitize_text_field( wp_unslash( $_GET['f_id'] ) ) ) : 0; | ||
|
||
if ( empty( $post_id ) || empty( $form_id ) ) { | ||
|
@@ -591,7 +591,7 @@ | |
|
||
// custom fields | ||
preg_match_all( '/{custom_([\w-]*)\b}/', $content, $matches ); | ||
[ $search, $replace ] = $matches; | ||
|
||
if ( $replace ) { | ||
foreach ( $replace as $index => $meta_key ) { | ||
|
@@ -617,7 +617,7 @@ | |
$meta_val = $val; | ||
} | ||
$is_first = false; | ||
} else { | ||
if ( get_post_mime_type( (int) $val ) ) { | ||
$meta_val = $meta_val . ', ' . wp_get_attachment_url( $val ); | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Breaking change: Response structure modified
The change from
wp_send_json
towp_send_json_error
modifies the response structure. Clients expecting the response data at the root level will need to access it via thedata
property instead. This change requires corresponding updates in the frontend code that handles the response.Let's verify if the frontend code has been updated to handle this change:
🏁 Script executed:
Length of output: 22151
Based on our review, there’s a breaking change on the server side: using
wp_send_json_error()
returns an object of the forminstead of just a raw response at the root level. This means that any client code handling the response must now look for the result under the
data
property. Our initial search of the frontend JS (inassets/js/frontend-form.js
) did not reveal any clear handling of the updated structure (for example, checks looking forresponse.data
when processing error responses).Please verify that the JavaScript handling of the AJAX response (especially in the
formSubmit
function inassets/js/frontend-form.js
) has been updated to expect the payload inside thedata
property. Any code that was previously accessing the response directly (e.g. viaresponse
instead ofresponse.data
) will need updating to avoid breaking error handling downstream.Actionable items:
assets/js/frontend-form.js
so that error responses properly extract the error details fromresponse.data
.