Skip to content

Commit

Permalink
Fix Gravity Forms confirmations filtering
Browse files Browse the repository at this point in the history
We need to strip all HTML tags from the confirmation messages for the comparison to work properly
  • Loading branch information
mleray committed Sep 29, 2022
1 parent 8f2b7ae commit 07cbb03
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/GravityFormsExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,31 +266,32 @@ public function p4_gf_custom_confirmation( $confirmation, $form ) {

$post = Timber::query_post( false, Post::class );

$default_confirmation_array = array_filter(
$current_confirmation_array = array_filter(
$form['confirmations'],
function ( $conf ) use ( $confirmation ) {
return str_contains( $confirmation, $conf['message'] );
// We need to strip all HTML tags for proper comparison.
return wp_strip_all_tags( $confirmation ) === wp_strip_all_tags( $conf['message'] );
}
);

$default_confirmation = reset( $default_confirmation_array );
$current_confirmation = reset( $current_confirmation_array );

// In case we don't find the corresponding confirmation, we return the current one.
if ( ! $default_confirmation ) {
// In case we don't find the current confirmation object, we return the $confirmation param.
if ( ! $current_confirmation ) {
return $confirmation;
}

$confirmation_fields = [
'confirmation' => $default_confirmation['message'],
'confirmation' => $confirmation,
'share_platforms' => [
'facebook' => $default_confirmation['facebook'] ?? true,
'twitter' => $default_confirmation['twitter'] ?? true,
'whatsapp' => $default_confirmation['whatsapp'] ?? true,
'native' => $default_confirmation['native'] ?? true,
'email' => $default_confirmation['email'] ?? true,
'facebook' => $current_confirmation['facebook'] ?? true,
'twitter' => $current_confirmation['twitter'] ?? true,
'whatsapp' => $current_confirmation['whatsapp'] ?? true,
'native' => $current_confirmation['native'] ?? true,
'email' => $current_confirmation['email'] ?? true,
],
'share_text' => $default_confirmation['p4_gf_share_text_override'] ?? '',
'share_url' => $default_confirmation['p4_gf_share_url_override'] ?? '',
'share_text' => $current_confirmation['p4_gf_share_text_override'] ?? '',
'share_url' => $current_confirmation['p4_gf_share_url_override'] ?? '',
'post' => $post,
];

Expand Down

0 comments on commit 07cbb03

Please sign in to comment.