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; } /**