Skip to content

Commit

Permalink
Improve redirect to entry n case the entry has been deleted.
Browse files Browse the repository at this point in the history
See #39 (comment) for details.
  • Loading branch information
remcotolsma committed May 13, 2024
1 parent 4c7ecb3 commit cddab3b
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit cddab3b

Please sign in to comment.