From cddab3b4ba8f284c47a0a6ac58aeb4ce027d2b74 Mon Sep 17 00:00:00 2001 From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com> Date: Mon, 13 May 2024 13:59:56 +0200 Subject: [PATCH] Improve redirect to entry n case the entry has been deleted. See https://github.com/pronamic/wp-pronamic-pay-gravityforms/issues/39#issuecomment-2107214283 for details. --- src/Admin.php | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Admin.php b/src/Admin.php index 32f94b8..5a2c7fe 100644 --- a/src/Admin.php +++ b/src/Admin.php @@ -202,33 +202,38 @@ public static function custom_merge_tags( $merge_tags ) { } /** - * Maybe redirect to Gravity Forms entry + * Maybe redirect to Gravity Forms entry. + * + * @return void */ public static function maybe_redirect_to_entry() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $lead_id = \array_key_exists( 'pronamic_gf_lid', $_GET ) ? \sanitize_text_field( \wp_unslash( $_GET['pronamic_gf_lid'] ) ) : null; - - if ( null === $lead_id ) { + if ( ! \array_key_exists( 'pronamic_gf_lid', $_GET ) ) { return; } + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $lead_id = \sanitize_text_field( \wp_unslash( $_GET['pronamic_gf_lid'] ) ); + $lead = RGFormsModel::get_lead( $lead_id ); - if ( ! empty( $lead ) ) { - $url = add_query_arg( - [ - 'page' => 'gf_entries', - 'view' => 'entry', - 'id' => $lead['form_id'], - 'lid' => $lead_id, - ], - admin_url( 'admin.php' ) - ); + if ( false === $lead ) { + \wp_die( \esc_html__( 'The requested Gravity Forms entry could not be found.', 'pronamic_ideal' ) ); + } - wp_safe_redirect( $url ); + $url = \add_query_arg( + [ + 'page' => 'gf_entries', + 'view' => 'entry', + 'id' => $lead['form_id'], + 'lid' => $lead_id, + ], + admin_url( 'admin.php' ) + ); - exit; - } + wp_safe_redirect( $url ); + + exit; } /**