' + if ( 'message' === $form->get_attribute( 'customThankyou' ) ) { + $message = wpautop( $form->get_attribute( 'customThankyouMessage' ) ); + } else { + $message = ''; + } + + return wp_kses( + $message, array( 'br' => array(), 'blockquote' => array( 'class' => array() ), @@ -2816,21 +2826,36 @@ function process_submission() { return self::success_message( $post_id, $this ); } - $redirect = wp_get_referer(); - if ( ! $redirect ) { // wp_get_referer() returns false if the referer is the same as the current page - $redirect = $_SERVER['REQUEST_URI']; + $redirect = ''; + $custom_redirect = false; + if ( 'redirect' === $this->get_attribute( 'customThankyou' ) ) { + $custom_redirect = true; + $redirect = esc_url( $this->get_attribute( 'customThankyouRedirect' ) ); } - $redirect = add_query_arg( - urlencode_deep( - array( - 'contact-form-id' => $id, - 'contact-form-sent' => $post_id, - 'contact-form-hash' => $this->hash, - '_wpnonce' => wp_create_nonce( "contact-form-sent-{$post_id}" ), // wp_nonce_url HTMLencodes :( - ) - ), $redirect - ); + if ( ! $redirect ) { + $custom_redirect = false; + $redirect = wp_get_referer(); + } + + if ( ! $redirect ) { // wp_get_referer() returns false if the referer is the same as the current page. + $custom_redirect = false; + $redirect = $_SERVER['REQUEST_URI']; + } + + if ( ! $custom_redirect ) { + $redirect = add_query_arg( + urlencode_deep( + array( + 'contact-form-id' => $id, + 'contact-form-sent' => $post_id, + 'contact-form-hash' => $this->hash, + '_wpnonce' => wp_create_nonce( "contact-form-sent-{$post_id}" ), // wp_nonce_url HTMLencodes :( . + ) + ), + $redirect + ); + } /** * Filter the URL where the reader is redirected after submitting a form. @@ -2845,7 +2870,8 @@ function process_submission() { */ $redirect = apply_filters( 'grunion_contact_form_redirect_url', $redirect, $id, $post_id ); - wp_safe_redirect( $redirect ); + // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- We intentially allow external redirects here. + wp_redirect( $redirect ); exit; } diff --git a/to-test.md b/to-test.md index 7fb5db57251e0..114d386d21b8e 100644 --- a/to-test.md +++ b/to-test.md @@ -8,6 +8,10 @@ We've made some changes to simplify the Jetpack Dashboard interface when your us We've made some changes to ensure that blocks are properly translated in the block editor. If you switch to a language that offers language packs, like French or Spanish, you should see that Jetpack Blocks will now be translated in the editor. +## Contact Form Block + +The Contact Form Block now includes options for showing a custom post-submission message, or to redirect to a different URL. + ### Carousel In this release, we've made some changes to how the Carousel metadata was added to each gallery. To test this:' . '', + . '' . join( '
', self::get_compiled_form( $feedback_id, $form ) ) . '
' - . '