Browse: Home / Hooks /

learndash_quizinfo

apply_filters( 'learndash_quizinfo',  string $shortcode_output,  array $shortcode_attributes,  array $selected_quizinfo )

Filters quizinfo shortcode output.


Description #


Parameters #

$shortcode_output

(string) The output of quizinfo shortcode.

$shortcode_attributes

(array) An array of shortcode attributes.

$selected_quizinfo

(array) Quiz item array used for processing.


Source #

File: includes/shortcodes/ld_quizinfo.php


Examples #

Note: Extended code example below not guaranteed, you may need to consult with a developer

 <?php
/**
 * Example usage for learndash_quizinfo filter.
 */
add_filter(
	'learndash_quizinfo',
	function( $value, $shortcode_atts ) {

		if ( ( isset( $shortcode_atts['show'] ) ) && ( 'timestamp' === $shortcode_atts['show'] ) ) {
			if ( ( ! isset( $shortcode_atts['time'] ) ) || ( empty( $shortcode_atts['time'] ) ) ) {
				$shortcode_atts['time'] = ( isset( $_REQUEST['time'] ) ) ? absint( $_REQUEST['time'] ) : '';
			}
			if ( ( ! isset( $shortcode_atts['quiz'] ) ) || ( empty( $shortcode_atts['quiz'] ) ) ) {
				$shortcode_atts['quiz'] = ( isset( $_REQUEST['quiz'] ) ) ? absint( $_REQUEST['quiz'] ) : 0;
			}
			if ( ( ! isset( $shortcode_atts['user_id'] ) ) || ( empty( $shortcode_atts['user_id'] ) ) ) {
				$shortcode_atts['user_id'] = ( isset( $_REQUEST['user_id'] ) ) ? absint( $_REQUEST['user_id'] ) : get_current_user_id();
			}

			if ( ( ! empty( $shortcode_atts['time'] ) ) && ( ! empty( $shortcode_atts['quiz'] ) ) && ( ! empty( $shortcode_atts['user_id'] ) ) ) {
				$quizinfo = get_user_meta( $shortcode_atts['user_id'], '_sfwd-quizzes', true );

				$selected_quizinfo = '';
				foreach ( $quizinfo as $quiz_i ) {
					if ( ( isset( $quiz_i['time'] ) ) && ( $quiz_i['time'] == $shortcode_atts['time'] ) && ( $quiz_i['quiz'] == $shortcode_atts['quiz'] ) ) {
						$selected_quizinfo = $quiz_i;
						break;
					}
				}

				if ( ! empty( $selected_quizinfo ) ) {
					$value = learndash_adjust_date_time_display( $selected_quizinfo['time'], $shortcode_atts['format'] );
				}
			}
		}
		return $value;
	},
	30,
	2
);
 

Changelog #

Changelog
Version Description
3.1.4 Added $selected_quizinfo param.
2.1.0 Introduced.