Custom Functions Showcase
Explore exclusive custom functions we’ve developed for specific client requests. While not part of our official releases, these tailored solutions showcase QSM’s flexibility. Need a custom feature? Contact us to discuss your requirements!
Table of Contents
Dynamic Redirect URL Template Variable
We developed a custom function that introduces a new template variable, %QSM_REDIRECT_URL%, allowing dynamic redirection within the quiz result template.
How It Works:
Instead of manually setting multiple custom redirect fields, users can now define a single “Redirect” field and use %QSM_REDIRECT_URL% as its value. This variable dynamically replaces the redirect URL based on the user’s quiz results.
Implementation:
To use this feature, add the following code to the functions.php file of your active child theme. Avoid placing it in a plugin, as updates may remove the code.
add_action( 'qsm_after_results_page', 'qsm_addon_activecampaign_after_results_page', 10, 2 );
function qsm_addon_activecampaign_after_results_page( $response_data, $page_index ) {
global $mlwQuizMasterNext, $wpdb;
$quiz_id = isset( $response_data['quiz_id'] ) ? intval( $response_data['quiz_id'] ) : 0;
$quiz_after_text = '';
$results = $wpdb->get_var( $wpdb->prepare( "SELECT message_after FROM {$wpdb->prefix}mlw_quizzes WHERE quiz_id = %d", $quiz_id ) );
$quiz_after_text = maybe_unserialize( $results );
add_option( 'qsm_addon_activecampaign_redirect_url_' . $response_data['result_id'], $quiz_after_text[$page_index]['redirect'] );
}
add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_addon_activecampaign_template_variable_results_page', 10, 2 );
function qsm_addon_activecampaign_template_variable_results_page( $content, $results_array ) {
if ( false !== strpos( $content, '%QSM_REDIRECT_URL%' ) ) {
$redirect_url = get_option( 'qsm_addon_activecampaign_redirect_url_' . $results_array['result_id'] );
$content = str_replace( '%QSM_REDIRECT_URL%', $redirect_url, $content );
delete_option( 'qsm_addon_activecampaign_redirect_url_' . $results_array['result_id'] );
}
return $content;
}
Note:
This is a client-specific customization and is not part of an official QSM release. If you need a similar custom function, feel free to reach out! 🚀