Bloquear los exámenes suspendidos en LearnDash

    Bloquea a los alumnos del examen final durante 4 horas después de que hayan fallado.

    <?php
    /** * LearnDash - Filter Quiz Content * lock students out of the final exam for 4 hours after they fail * * @param $quiz_content - html page content containing the quiz to display to the user * @param $quiz_post - WP_Post Quiz object. * * @return $quiz_content replacement quiz content to display to the user */
    add_filter('learndash_quiz_content', function($quiz_content = '', WP_Post $quiz_post) {
    	// Set this logic to only effect certain Quizzes. Leave blank for all.
    	$check_quiz_only = array( 107 );
    	// Set our threshold limit. See https://codex.WordPress.org/Easier_Expression_of_Time_Constants for handy time constants
    	$time_complete_threshold = 4*HOUR_IN_SECONDS;
    	if ( ( !empty( $quiz_post ) ) && ( ( empty( $check_quiz_only ) ) || ( in_array( $quiz_post->ID, $check_quiz_only ) === true ) ) ) {
    		$user_id = get_current_user_id();
    		$user_quiz_results = get_user_meta( $user_id, '_sfwd-quizzes', true );
    		if ( !empty( $user_quiz_results ) ) { 
    			// We reverse the user quizzes since newer items are added to the bottom. $user_quiz_results = array_reverse( $user_quiz_results );
    			// Then we loop newest to oldest...
    			foreach($user_quiz_results as $user_quiz_result ) {
    				// ...until we find a match between the result quiz ID and the quiz post ID.
    				if ( $user_quiz_result['quiz'] == $quiz_post->ID ) {
    					// Check if the result quiz completed time is within out threshold.
    					if ( ( $user_quiz_result['completed'] + $time_complete_threshold ) > time() ) {
    						// If it is we display an alternate quiz content.
    						$quiz_content = '<p>Too soon. Try again in about '. human_time_diff( ($user_quiz_result['completed'] + $time_complete_threshold), time()) .'.</p>';
    					}
    				}
    			}
    		}
    	}
    // Always return $quiz_content;
    return $quiz_content; }, 10, 2);