llms_get_picture_choice_question_cols( int $num_choices )

Retrieve the number of columns needed for a picture choice question.


Parameters Parameters

$num_choices

(int) (Required) Number of choices.


Top ↑

Return Return

(int)


Top ↑

Source Source

File: includes/functions/llms.functions.quiz.php

function llms_get_picture_choice_question_cols( $num_choices ) {

	/**
	 * Allow 3rd parties to override this function with a custom number of columns.
	 *
	 * If this responds with a non null will bypass column counter function return it immediately
	 *
	 * @since 3.16.0
	 *
	 * @param null|int $cols        Number of columns needed for a picture choice question.
	 * @param int      $num_choices Number of choices.
	 */
	$cols = apply_filters( 'llms_get_picture_choice_question_cols', null, $num_choices );

	if ( 1 === $num_choices ) {
		$cols = 1;
	} elseif ( $num_choices >= 25 ) {
		$cols = 5;
	} elseif ( $num_choices >= 10 ) {
		$max_cols = 5;
		$min_cols = 3;
	} else {
		$max_cols = 4;
		$min_cols = 2;
	}

	if ( is_null( $cols ) ) {

		$i = $max_cols;
		while ( $i >= $min_cols ) {
			if ( 0 === $num_choices % $i ) {
				$cols = $i;
				break;
			}
			$i--;
		}

		if ( ! $cols ) {
			$cols = llms_get_picture_choice_question_cols( $num_choices + 1 );
		}
	}

	/** This filter is documented above */
	return apply_filters( 'llms_get_picture_choice_question_cols', $cols, $num_choices );

}


Top ↑

Changelog Changelog

Changelog
Version Description
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.