Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CONTACT_X Variable Functionality #2712

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions php/template-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,23 @@ function mlw_qmn_variable_user_email( $content, $mlw_quiz_array ) {
* @return string The HTML for the content
*/
function qsm_contact_field_variable( $content, $results_array ) {
preg_match_all( '~%CONTACT_(.*?)%~i', $content, $matches );
for ( $i = 0; $i < count( $matches[0] ); $i++ ) {
$contact_index = intval($matches[1][ $i ]) - 1;
if ( isset($results_array['contact'][ $contact_index ]['value']) ) {
$content = str_replace('%CONTACT_' . $matches[1][ $i ] . '%', $results_array['contact'][ $contact_index ]['value'], $content);
preg_match_all( '~%CONTACT_(.*?)%~i', $content, $matches );
for ( $i = 0; $i < count( $matches[0] ); $i++ ) {
$contact_key = $matches[1][ $i ];
if ( is_numeric( $contact_key ) && intval( $contact_key ) > 0 ) {
$contact_index = intval( $contact_key ) - 1;

if ( isset( $results_array['contact'][ $contact_index ]['value'] ) ) {
$content = str_replace( '%CONTACT_' . $contact_key . '%', $results_array['contact'][ $contact_index ]['value'], $content );
} else {
$content = str_replace( '%CONTACT_' . $contact_key . '%', '', $content );
}
} else {
$content = str_replace( '%CONTACT_' . $contact_key . '%', '', $content );
}
}
return $content;
}
return $content;
}

/**
* Returns user values for all contact fields
Expand Down
Loading