Quiz Master Next Shortcodes

Below, you’ll find a detailed guide on how to add the Quiz Master Next Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Quiz Master Next Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Quiz Master Next Plugin and the shortcodes it provides:

Plugin Icon
Quiz And Survey Master – Best Quiz, Exam and Survey Plugin for WordPress

"Quiz And Survey Master is the ultimate WordPress plugin for creating engaging quizzes, exams, and surveys. With this plugin, you can easily create interactive content to engage your audience."

★★★★☆ (1217) Active Installs: 40000+ Tested with: 6.3.2 PHP Version: 5.4
Included Shortcodes:
  • [mlw_quizmaster]
  • [qsm_result]
  • [qsm_link]
  • [qsm_recent_quizzes]

Quiz Master Next [mlw_quizmaster] Shortcode

The Quiz Master Next shortcode is used to display a quiz on a webpage. It retrieves a specified quiz and its questions from the database, prepares the quiz for display, and enqueues necessary scripts and styles.

Shortcode: [mlw_quizmaster]

Parameters

Here is a list of all possible mlw_quizmaster shortcode parameters and attributes:

  • quiz – specifies the ID of the quiz to be displayed
  • question_amount – limits the number of questions in the quiz

Examples and Usage

Basic example – Display a quiz using its ID

[mlw_quizmaster quiz=1 /]

Advanced example – Display a quiz using its ID and limit the number of questions displayed

[mlw_quizmaster quiz=1 question_amount=10 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [mlw_quizmaster] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'mlw_quizmaster', array( $this, 'display_shortcode' ) );

Shortcode PHP function:

function display_shortcode( $atts ) {
		$shortcode_args  = shortcode_atts(
			array(
				'quiz'            => 0,
				'question_amount' => 0,
			),
			$atts
		);
		$quiz            = intval( $shortcode_args['quiz'] );
		$question_amount = intval( $shortcode_args['question_amount'] );

		ob_start();
		global $wpdb, $mlwQuizMasterNext;
		if ( isset( $_GET['result_id'] ) && '' !== $_GET['result_id'] ) {
			$result_unique_id = sanitize_text_field( wp_unslash( $_GET['result_id'] ) );
			$result           = $wpdb->get_row( $wpdb->prepare( "SELECT `result_id`, `quiz_id` FROM {$wpdb->prefix}mlw_results WHERE unique_id = %s", $result_unique_id ), ARRAY_A );
			if ( ! empty( $result ) && isset( $result['result_id'] ) ) {
				$mlwQuizMasterNext->pluginHelper->prepare_quiz( $result['quiz_id'] );
				$qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();

				// If quiz options isn't found, stop function.
				if ( is_null( $qmn_quiz_options ) || 1 == $qmn_quiz_options->deleted ) {
					return __( 'This quiz is no longer available.', 'quiz-master-next' );
				}

				wp_enqueue_style( 'qmn_quiz_common_style', $this->common_css, array(), $mlwQuizMasterNext->version );
				wp_style_add_data( 'qmn_quiz_common_style', 'rtl', 'replace' );
				wp_enqueue_style( 'dashicons' );
				wp_enqueue_script( 'jquery' );
				wp_enqueue_script( 'jquery-ui-tooltip' );
				wp_enqueue_script( 'qsm_quiz', QSM_PLUGIN_JS_URL . '/qsm-quiz.js', array( 'wp-util', 'underscore', 'jquery', 'jquery-ui-tooltip' ), $mlwQuizMasterNext->version, false );
				wp_enqueue_script( 'qsm_common', QSM_PLUGIN_JS_URL . '/qsm-common.js', array(), $mlwQuizMasterNext->version, true );
				$disable_mathjax = isset( $qmn_quiz_options->disable_mathjax ) ? $qmn_quiz_options->disable_mathjax : '';
				if ( 1 != $disable_mathjax ) {
					wp_enqueue_script( 'math_jax', $this->mathjax_url, false, $this->mathjax_version, true );
					wp_add_inline_script( 'math_jax', self::$default_MathJax_script, 'before' );
				}

				$result_id      = $result['result_id'];
				$return_display = do_shortcode( '[qsm_result id="' . $result_id . '"]' );
				$return_display = str_replace( '%FB_RESULT_ID%', $result_unique_id, $return_display );
			} else {
				$return_display = 'Result id is wrong!';
			}
			$return_display .= ob_get_clean();
		} else {
			global $qmn_allowed_visit;
			global $qmn_json_data;
			$qmn_json_data     = array();
			$qmn_allowed_visit = true;
			$success           = $mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz );
			if ( false === $success ) {
				return __( 'It appears that this quiz is not set up correctly', 'quiz-master-next' );
			}

			global $mlw_qmn_quiz;
			$mlw_qmn_quiz = $quiz;
			$return_display   = '';
			$qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
			// Legacy variable.
			/**
			 * Filter Quiz Options before Quiz Display
			 */
			$qmn_quiz_options = apply_filters( 'qsm_shortcode_quiz_options', $qmn_quiz_options );

			// If quiz options isn't found, stop function.
			if ( is_null( $qmn_quiz_options ) || 1 == $qmn_quiz_options->deleted ) {
				return __( 'This quiz is no longer available.', 'quiz-master-next' );
			}

			// If quiz options isn't found, stop function.
			if ( is_null( $qmn_quiz_options ) || empty( $qmn_quiz_options->quiz_name ) ) {
				return __( 'It appears that this quiz is not set up correctly', 'quiz-master-next' );
			}

			// Loads Quiz Template.
			wp_enqueue_style( 'qmn_quiz_animation_style', QSM_PLUGIN_CSS_URL . '/animate.css', array(), $mlwQuizMasterNext->version );
			wp_enqueue_style( 'qmn_quiz_common_style', $this->common_css, array(), $mlwQuizMasterNext->version );
			wp_style_add_data( 'qmn_quiz_common_style', 'rtl', 'replace' );
			wp_enqueue_style( 'dashicons' );
			// The quiz_stye is misspelled because it has always been misspelled and fixing it would break many sites :(.
			if ( 'default' == $qmn_quiz_options->theme_selected ) {
				$return_display .= '<style type="text/css">' . preg_replace( '#<script(.*?)>(.*?)</script>#is', '', htmlspecialchars_decode( $qmn_quiz_options->quiz_stye ) ) . '</style>';
				wp_enqueue_style( 'qmn_quiz_style', QSM_PLUGIN_CSS_URL . '/qmn_quiz.css', array(), $mlwQuizMasterNext->version );
				wp_style_add_data( 'qmn_quiz_style', 'rtl', 'replace' );
			} else {
				$registered_template = $mlwQuizMasterNext->pluginHelper->get_quiz_templates( $qmn_quiz_options->theme_selected );
				// Check direct file first, then check templates folder in plugin, then check templates file in theme.
				// If all fails, then load custom styling instead.
				if ( $registered_template && file_exists( ABSPATH . $registered_template['path'] ) ) {
					wp_enqueue_style( 'qmn_quiz_template', site_url( $registered_template['path'] ), array(), $mlwQuizMasterNext->version );
				} elseif ( $registered_template && file_exists( plugin_dir_path( __FILE__ ) . '../../templates/' . $registered_template['path'] ) ) {
					wp_enqueue_style( 'qmn_quiz_template', plugins_url( '../../templates/' . $registered_template['path'], __FILE__ ), array(), $mlwQuizMasterNext->version );
				} elseif ( $registered_template && file_exists( get_theme_file_path( '/templates/' . $registered_template['path'] ) ) ) {
					wp_enqueue_style( 'qmn_quiz_template', get_stylesheet_directory_uri() . '/templates/' . $registered_template['path'], array(), $mlwQuizMasterNext->version );
				}
				if ( ! empty( $qmn_quiz_options->quiz_stye ) ) {
					echo "<style type='text/css' id='qmn_quiz_template-css'>" . wp_kses_post( htmlspecialchars_decode( $qmn_quiz_options->quiz_stye ) ) . '</style>';
				}
			}
			$saved_quiz_theme = $mlwQuizMasterNext->theme_settings->get_active_quiz_theme_path( $quiz );
			$folder_name      = QSM_THEME_PATH . $saved_quiz_theme . '/';
			if ( file_exists( $folder_name . 'functions.php' ) ) {
				include_once $folder_name . 'functions.php';
			}
			do_action( 'qsm_enqueue_script_style', $qmn_quiz_options );

			// Starts to prepare variable array for filters.
			$qmn_array_for_variables = array(
				'quiz_id'     => $qmn_quiz_options->quiz_id,
				'quiz_name'   => $qmn_quiz_options->quiz_name,
				'quiz_system' => $qmn_quiz_options->system,
				'user_ip'     => $this->get_user_ip(),
			);
			$return_display         .= '<script>
                            if (window.qmn_quiz_data === undefined) {
                                    window.qmn_quiz_data = new Object();
                            }
                    </script>';
			$qpages                  = array();
			$qpages_arr              = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'qpages', array() );
			if ( ! empty( $qpages_arr ) ) {
				foreach ( $qpages_arr as $key => $qpage ) {
					unset( $qpage['questions'] );
					if ( isset( $qpage['id'] ) ) {
						$qpages[ $qpage['id'] ] = $qpage;
					}
				}
			}
			$correct_answer_text = sanitize_text_field( $qmn_quiz_options->quick_result_correct_answer_text );
			$correct_answer_text = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $correct_answer_text, "quiz_quick_result_correct_answer_text-{$qmn_array_for_variables['quiz_id']}" );
			$wrong_answer_text = sanitize_text_field( $qmn_quiz_options->quick_result_wrong_answer_text );
			$wrong_answer_text = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $wrong_answer_text, "quiz_quick_result_wrong_answer_text-{$qmn_array_for_variables['quiz_id']}" );
			$quiz_processing_message = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $qmn_quiz_options->quiz_processing_message, "quiz_quiz_processing_message-{$qmn_array_for_variables['quiz_id']}" );
			$quiz_limit_choice = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $qmn_quiz_options->quiz_limit_choice, "quiz_quiz_limit_choice-{$qmn_array_for_variables['quiz_id']}" );
			$qmn_json_data = array(
				'quiz_id'                            => $qmn_array_for_variables['quiz_id'],
				'quiz_name'                          => $qmn_array_for_variables['quiz_name'],
				'disable_answer'                     => $qmn_quiz_options->disable_answer_onselect,
				'ajax_show_correct'                  => $qmn_quiz_options->ajax_show_correct,
				'progress_bar'                       => $qmn_quiz_options->progress_bar,
				'contact_info_location'              => $qmn_quiz_options->contact_info_location,
				'qpages'                             => $qpages,
				'skip_validation_time_expire'        => $qmn_quiz_options->skip_validation_time_expire,
				'timer_limit_val'                    => $qmn_quiz_options->timer_limit,
				'disable_scroll_next_previous_click' => $qmn_quiz_options->disable_scroll_next_previous_click,
				'disable_first_page'                 => $qmn_quiz_options->disable_first_page,
				'enable_result_after_timer_end'      => isset( $qmn_quiz_options->enable_result_after_timer_end ) ? $qmn_quiz_options->enable_result_after_timer_end : '',
				'enable_quick_result_mc'             => isset( $qmn_quiz_options->enable_quick_result_mc ) ? $qmn_quiz_options->enable_quick_result_mc : '',
				'end_quiz_if_wrong'                  => isset( $qmn_quiz_options->end_quiz_if_wrong ) ? $qmn_quiz_options->end_quiz_if_wrong : 0,
				'form_disable_autofill'              => isset( $qmn_quiz_options->form_disable_autofill ) ? $qmn_quiz_options->form_disable_autofill : '',
				'disable_mathjax'                    => isset( $qmn_quiz_options->disable_mathjax ) ? $qmn_quiz_options->disable_mathjax : '',
				'enable_quick_correct_answer_info'   => isset( $qmn_quiz_options->enable_quick_correct_answer_info ) ? $qmn_quiz_options->enable_quick_correct_answer_info : 0,
				'quick_result_correct_answer_text'   => $correct_answer_text,
				'quick_result_wrong_answer_text'     => $wrong_answer_text,
				'quiz_processing_message'            => $quiz_processing_message,
				'quiz_limit_choice'                  => $quiz_limit_choice,
				'not_allow_after_expired_time'       => $qmn_quiz_options->not_allow_after_expired_time,
				'scheduled_time_end'                 => strtotime( $qmn_quiz_options->scheduled_time_end ),
			);

			$return_display = apply_filters( 'qmn_begin_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables, $shortcode_args );

			// Checks if we should be showing quiz or results page.
			if ( $qmn_allowed_visit && ! isset( $_POST['complete_quiz'] ) && ! empty( $qmn_quiz_options->quiz_name ) ) {
				$return_display .= $this->display_quiz( $qmn_quiz_options, $qmn_array_for_variables, $question_amount, $shortcode_args );
			} elseif ( isset( $_POST['complete_quiz'], $_POST['qmn_quiz_id'] ) && 'confirmation' == sanitize_text_field( wp_unslash( $_POST['complete_quiz'] ) ) && sanitize_text_field( wp_unslash( $_POST['qmn_quiz_id'] ) ) == $qmn_array_for_variables['quiz_id'] ) {
				$return_display .= $this->display_results( $qmn_quiz_options, $qmn_array_for_variables );
			}

			$qmn_filtered_json = apply_filters( 'qmn_json_data', $qmn_json_data, $qmn_quiz_options, $qmn_array_for_variables, $shortcode_args );
			$qmn_settings_array = maybe_unserialize( $qmn_quiz_options->quiz_settings );
			$quiz_options = maybe_unserialize( $qmn_settings_array['quiz_options'] );
			$correct_answer_logic = ! empty( $quiz_options['correct_answer_logic'] ) ? $quiz_options['correct_answer_logic'] : '';
			$encryption['correct_answer_logic'] = $correct_answer_logic;
			$enc_questions = array();
			if ( ! empty( $qpages_arr ) ) {
				foreach ( $qpages_arr as $item ) {
					$enc_questions = array_merge($enc_questions, $item['questions']);
				}
			}
			$enc_questions = implode(',', $enc_questions);
			$question_array = $wpdb->get_results(
				"SELECT quiz_id, question_id, answer_array, question_answer_info, question_type_new, question_settings
				FROM {$wpdb->prefix}mlw_questions
				WHERE question_id IN ($enc_questions)", ARRAY_A);
			foreach ( $question_array as $key => $question ) {
				$encryption[ $question['question_id'] ]['question_type_new'] = $question['question_type_new'];
				$encryption[ $question['question_id'] ]['answer_array'] = maybe_unserialize( $question['answer_array'] );
				$encryption[ $question['question_id'] ]['settings'] = maybe_unserialize( $question['question_settings'] );
				$encryption[ $question['question_id'] ]['correct_info_text'] = isset( $question['question_answer_info'] ) ? html_entity_decode( $question['question_answer_info'] ) : '';
				$encryption[ $question['question_id'] ]['correct_info_text'] = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $encryption[ $question['question_id'] ]['correct_info_text'], "correctanswerinfo-{$question['question_id']}" );
			}
			if ( ( isset($qmn_json_data['end_quiz_if_wrong']) && 0 < $qmn_json_data['end_quiz_if_wrong'] ) || ( ! empty( $qmn_json_data['enable_quick_result_mc'] ) && 1 == $qmn_json_data['enable_quick_result_mc'] ) ) {
				$quiz_id = $qmn_json_data['quiz_id'];
				$qsm_inline_encrypt_js = '
				if (encryptionKey === undefined) {
                       var encryptionKey = {};
                }
                if (data === undefined) {
                       var data = {};
                }
                if (jsonString === undefined) {
                        var jsonString = {};
                }
                if (encryptedData === undefined) {
                      var encryptedData = {};
                }
				    
				    
				    
				    

				encryptionKey['.$quiz_id.'] = "'.hash('sha256',time().$quiz_id).'";
				
				data['.$quiz_id.'] = '.wp_json_encode($encryption).';
				jsonString['.$quiz_id.'] = JSON.stringify(data['.$quiz_id.']);
				encryptedData['.$quiz_id.'] = CryptoJS.AES.encrypt(jsonString['.$quiz_id.'], encryptionKey['.$quiz_id.']).toString();';
				wp_add_inline_script('qsm_encryption', $qsm_inline_encrypt_js, 'after');
			}

			$return_display .= '<script>window.qmn_quiz_data["' . $qmn_json_data['quiz_id'] . '"] = ' . wp_json_encode( $qmn_filtered_json ) . '
                    </script>';

			$return_display .= ob_get_clean();
			$return_display  = apply_filters( 'qmn_end_shortcode', $return_display, $qmn_quiz_options, $qmn_array_for_variables, $shortcode_args );

		}
		return $return_display;
	}

Code file location:

quiz-master-next/quiz-master-next/php/classes/class-qmn-quiz-manager.php

Quiz Master Next [qsm_result] Shortcode

The Quiz Master Next shortcode, ‘qsm_result’, is designed to display quiz results. It uses a shortcode function, ‘shortcode_display_result’, which retrieves the quiz results based on the result id. This shortcode function first checks if the result id is valid. If not, it fetches the id from the URL. If the id is valid and numeric, it retrieves the corresponding quiz results from the database. It then enqueues necessary styles and scripts, and prepares the response data, which includes details like quiz id, quiz name, user details, and quiz results. The function finally returns the quiz results in a formatted manner. If the result id is invalid, it displays an error message.

Shortcode: [qsm_result]

Parameters

Here is a list of all possible qsm_result shortcode parameters and attributes:

  • id – Unique identifier for the quiz result to display

Examples and Usage

Basic example – Displays the quiz result by referencing the result ID.

[qsm_result id=1 /]

Advanced examples

Using the shortcode to display a quiz result by referencing the result ID through a URL parameter. This allows for dynamic loading of quiz results based on the result ID present in the URL.

Add the result id in the URL like this: www.yourwebsite.com/your-page/?result_id=1

Then use the shortcode without any id attribute in the page where you want to display the result. The shortcode will automatically fetch the result id from the URL.

[qsm_result /]

Please note that this advanced usage requires your PHP code to have the functionality to retrieve the ‘result_id’ from the URL, as shown in the related shortcode PHP code above.

PHP Function Code

In case you have difficulties debugging what causing issues with [qsm_result] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'qsm_result', array( $this, 'shortcode_display_result' ) );

Shortcode PHP function:

function shortcode_display_result( $atts ) {

		$args = shortcode_atts(
			array(
				'id' => 0,
			),
			$atts
		);

		$id = intval( $args['id'] );

		ob_start();
		if ( 0 === $id ) {
			$id = (int) isset( $_GET['result_id'] ) ? sanitize_text_field( wp_unslash( $_GET['result_id'] ) ) : 0;
		}
		if ( $id && is_numeric( $id ) ) {
			global $mlwQuizMasterNext;
			global $wpdb;
			$result_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mlw_results WHERE result_id = %d", $id ), ARRAY_A );
			if ( $result_data ) {
				wp_enqueue_style( 'qmn_quiz_common_style', $this->common_css, array(), $mlwQuizMasterNext->version );
				wp_style_add_data( 'qmn_quiz_common_style', 'rtl', 'replace' );
				wp_enqueue_style( 'dashicons' );
				wp_enqueue_style( 'qsm_primary_css', plugins_url( '../../templates/qmn_primary.css', __FILE__ ), array(), $mlwQuizMasterNext->version );

				wp_enqueue_script( 'math_jax', $this->mathjax_url, false, $this->mathjax_version, true );
				wp_add_inline_script( 'math_jax', self::$default_MathJax_script, 'before' );
				$quiz_result   = maybe_unserialize( $result_data['quiz_results'] );
				$response_data = array(
					'quiz_id'                => $result_data['quiz_id'],
					'quiz_name'              => $result_data['quiz_name'],
					'quiz_system'            => $result_data['quiz_system'],
					'form_type'              => $result_data['form_type'],
					'quiz_payment_id'        => '',
					'user_ip'                => $result_data['user_ip'],
					'user_name'              => $result_data['name'],
					'user_business'          => $result_data['business'],
					'user_email'             => $result_data['email'],
					'user_phone'             => $result_data['phone'],
					'user_id'                => $result_data['user'],
					'timer'                  => 0,
					'time_taken'             => $result_data['time_taken'],
					'contact'                => $quiz_result['contact'],
					'total_points'           => $result_data['point_score'],
					'total_score'            => $result_data['correct_score'],
					'total_correct'          => $result_data['correct'],
					'total_questions'        => $result_data['total'],
					'question_answers_array' => $quiz_result[1],
					'comments'               => '',
					'result_id'              => $id,
				);
				$data          = QSM_Results_Pages::generate_pages( $response_data );
				echo wp_kses_post( htmlspecialchars_decode( $data['display'] ) );
			} else {
				esc_html_e( 'Invalid result id!', 'quiz-master-next' );
			}
		} else {
			esc_html_e( 'Invalid result id!', 'quiz-master-next' );
		}
		$content = ob_get_clean();
		return $content;
	}

Code file location:

quiz-master-next/quiz-master-next/php/classes/class-qmn-quiz-manager.php

Quiz Master Next [qsm_link] Shortcode

The Quiz Master Next shortcode ‘qsm_link’ generates a link to a specific quiz. It takes three parameters: ‘id’, ‘class’, and ‘target’. The ‘id’ parameter corresponds to the quiz’s ID. ‘class’ allows for custom styling, and ‘target’ determines how the link opens. This shortcode can be used to seamlessly integrate quizzes into posts or pages.

Shortcode: [qsm_link]

Parameters

Here is a list of all possible qsm_link shortcode parameters and attributes:

  • id – Unique identifier of the quiz
  • class – CSS class to style the quiz link
  • target – Controls where the quiz link opens

Examples and Usage

Basic example – A straightforward usage of the ‘qsm_link’ shortcode to display a quiz link by referencing the ID of the quiz. The quiz link will load based on the specified ID.

[qsm_link id=1 /]

Advanced examples

Using the shortcode to display a quiz link with a specific CSS class. This allows for custom styling of the quiz link.

[qsm_link id=1 class="my-custom-class" /]

Utilizing the shortcode to display a quiz link that opens in a new browser tab or window. This is achieved by defining the ‘target’ attribute as ‘_blank’.

[qsm_link id=1 target="_blank" /]

Combining multiple parameters to create a more complex shortcode. This example displays a quiz link with a custom CSS class that opens in a new browser tab or window.

[qsm_link id=1 class="my-custom-class" target="_blank" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [qsm_link] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'qsm_link', 'qsm_quiz_link_shortcode' );

Shortcode PHP function:

function qsm_quiz_link_shortcode( $atts, $content = '' ) {

	$args = shortcode_atts(
		array(
			'id'     => 0,
			'class'  => '',
			'target' => '',
		),
		$atts
	);

	$id = intval( $args['id'] );
	$class = $args['class'];
	$target = $args['target'];

	// Find the permalink by finding the post with the meta_key 'quiz_id' of supplied quiz
	$permalink = '';
	$my_query  = new WP_Query(
		array(
			'post_type'      => 'qsm_quiz',
			'meta_key'       => 'quiz_id',
			'meta_value'     => $id,
			'posts_per_page' => 1,
			'post_status'    => 'publish',
		)
	);
	if ( $my_query->have_posts() ) {
		while ( $my_query->have_posts() ) {
			$my_query->the_post();
			$permalink = get_permalink();
		}
	}
	wp_reset_postdata();

	// Craft the target attribute if one is passed to shortcode
	$target_html = '';
	if ( ! empty( $target ) ) {
		return "<a href='" . esc_url( $permalink ) . "' target='" . esc_attr( $target ) . "' class='" . esc_attr( $class ) . "'>" . esc_html( $content ) . '</a>';
	} else {
		return "<a href='" . esc_url( $permalink ) . "' class='" . esc_attr( $class ) . "'>" . esc_html( $content ) . '</a>';
	}
}

Code file location:

quiz-master-next/quiz-master-next/php/shortcodes.php

Quiz Master Next [qsm_recent_quizzes] Shortcode

The Quiz Master Next plugin shortcode is designed to display recent quizzes on your WordPress site. It fetches quizzes from the database and displays them in descending order. The shortcode also allows customization of the number of quizzes to display and whether to include quizzes scheduled for the future. The output is a div structure with each quiz title and a link to take the quiz. If no quiz is found, it displays ‘No quiz found’.

Shortcode: [qsm_recent_quizzes]

Parameters

Here is a list of all possible qsm_recent_quizzes shortcode parameters and attributes:

  • no_of_quizzes – Determines the number of quizzes to display.
  • include_future_quizzes – Controls whether to include quizzes scheduled for future.

Examples and Usage

Basic example – This shortcode displays the most recent quizzes up to a maximum of 10 by default.

[qsm_recent_quizzes /]

Advanced examples

Displaying the most recent 5 quizzes. If the number of quizzes is not specified, it will default to showing the 10 most recent quizzes.

[qsm_recent_quizzes no_of_quizzes=5 /]

Displaying the most recent quizzes excluding future quizzes. By default, future quizzes are included. However, you can exclude them by setting the ‘include_future_quizzes’ attribute to ‘no’.

[qsm_recent_quizzes include_future_quizzes=no /]

Displaying the most recent 5 quizzes excluding future quizzes. This example combines the two previous examples to display the most recent 5 quizzes that are not scheduled for the future.

[qsm_recent_quizzes no_of_quizzes=5 include_future_quizzes=no /]

PHP Function Code

In case you have difficulties debugging what causing issues with [qsm_recent_quizzes] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'qsm_recent_quizzes', 'qsm_display_recent_quizzes' );

Shortcode PHP function:

function qsm_display_recent_quizzes( $attrs ) {
	global $mlwQuizMasterNext;
	$no_of_quizzes          = isset( $attrs['no_of_quizzes'] ) ? $attrs['no_of_quizzes'] : 10;
	$include_future_quizzes = isset( $attrs['include_future_quizzes'] ) ? $attrs['include_future_quizzes'] : true;
	global $wpdb;
	wp_enqueue_style( 'quizzes-list', QSM_PLUGIN_CSS_URL.'/quizzes-list.css', array(), $mlwQuizMasterNext->version );

	$quizzes = $mlwQuizMasterNext->pluginHelper->get_quizzes( false, 'quiz_id', 'DESC' );
	$result  = '<div class="outer-con">';
	$i       = 0;
	foreach ( $quizzes as $quiz ) {
		if ( $i < $no_of_quizzes ) {
			$setting = maybe_unserialize( $quiz->quiz_settings );
			$options = maybe_unserialize( $setting['quiz_options'] );
			$start_date = strtotime( $options['scheduled_time_start'] );
			$end_date   = strtotime( $options['scheduled_time_end'] );
			$now      = strtotime( current_time( 'm/d/Y H:i' ) );
			if ( $end_date && $end_date < $now ) {
				continue;
			} elseif ( $start_date && $start_date > $now && 'no' === $include_future_quizzes ) {
				continue;
			} else {
				$title   = $quiz->quiz_name;
				$id      = $quiz->quiz_id;
				$url     = do_shortcode( "[qsm_link id='$id'] Take Quiz [/qsm_link]" );
				$result .= "<div class='ind-quiz'>
                                <div class='quiz-heading'>
                                    {$title}
                                </div>
                                <div class='quiz-url'>
                                    {$url}
                                </div>
                            </div>";
				$result .= "<div class='clear'></div>";
				$i++;
			}
		}
	}
	if ( 0 === $i ) {
		$result .= __( 'No quiz found', 'quiz-master-next' );
	}
	$result .= '</div>';
	return $result;
}

Code file location:

quiz-master-next/quiz-master-next/php/shortcodes.php

Conclusion

Now that you’ve learned how to embed the Quiz Master Next Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *