quiz_navigation_switcher_admin.php
3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* Displays the Quiz Switcher displayed within the Quiz Questions admin widget.
* Available Variables:
* none
*
* @since 2.6.0
*
* @package LearnDash\Templates\Legacy
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Builder', 'shared_questions' ) !== 'yes' ) {
return;
}
if ( ( isset( $_GET['post'] ) ) && ( ! empty( $_GET['post'] ) ) ) {
$post = get_post( intval( $_GET['post'] ) );
if ( is_a( $post, 'WP_Post' ) && ( in_array( $post->post_type, array( 'sfwd-question' ) ) ) ) {
$cb_quizzes = learndash_get_quizzes_for_question( $post->ID );
$count_primary = 0;
$count_secondary = 0;
if ( isset( $cb_quizzes['primary'] ) ) {
$count_primary = count( $cb_quizzes['primary'] );
}
if ( isset( $cb_quizzes['secondary'] ) ) {
$count_secondary = count( $cb_quizzes['secondary'] );
}
if ( ( $count_primary > 0 ) || ( $count_secondary > 0 ) ) {
$default_quiz_id = learndash_get_quiz_id( $post->ID, true );
if ( ( 1 === $count_primary ) && ( empty( $count_secondary ) ) ) {
if ( isset( $cb_quizzes['primary'][ $default_quiz_id ] ) ) {
return;
}
}
$use_select_opt_groups = false;
if ( ( $count_primary > 0 ) && ( $count_secondary > 0 ) ) {
$use_select_opt_groups = true;
}
$quiz_post_id = 0;
if ( isset( $_GET['quiz_id'] ) ) {
$quiz_post_id = intval( $_GET['quiz_id'] );
}
?><p class="widget_quiz_switcher">
<?php
echo sprintf(
// translators: placeholder: Quiz.
esc_html_x( '%s switcher', 'placeholder: Quiz', 'learndash' ),
LearnDash_Custom_Label::get_label( 'quiz' )
);
?>
<br />
<?php
$item_url = get_edit_post_link( $post->ID );
?>
<input type="hidden" id="ld-quiz-primary" name="ld-quiz-primary" value="<?php echo $default_quiz_id; ?>" />
<select name="ld-quiz-switcher" id="ld-quiz-switcher">
<option value="">
<?php
echo sprintf(
// translators: placeholder: Quiz.
esc_html_x( 'Select a %s', 'placeholder: Quiz', 'learndash' ),
LearnDash_Custom_Label::get_label( 'Quiz' )
);
?>
</option>
<?php
foreach ( $cb_quizzes as $quiz_key => $quiz_set ) {
if ( true === $use_select_opt_groups ) {
if ( 'primary' === $quiz_key ) {
?>
<optgroup label="
<?php
echo sprintf(
// translators: placeholder: Quiz.
esc_html_x( 'Primary %s', 'placeholder: Quiz', 'learndash' ),
LearnDash_Custom_Label::get_label( 'Quiz' )
);
?>
">
<?php
} elseif ( 'secondary' === $quiz_key ) {
?>
<optgroup label="
<?php
echo sprintf(
// translators: placeholder: Quizzes.
esc_html_x( 'Other %s', 'placeholder: Quizzes', 'learndash' ),
LearnDash_Custom_Label::get_label( 'quizzes' )
);
?>
">
<?php
}
}
foreach ( $quiz_set as $quiz_id => $quiz_title ) {
$item_url = add_query_arg( 'quiz_id', $quiz_id, $item_url );
$selected = '';
if ( 'sfwd-quiz' == $post->post_type ) {
if ( $quiz_id == $quiz_post_id ) {
$selected = ' selected="selected" ';
}
} else {
if ( ( $quiz_id == $quiz_post_id ) || ( ( empty( $quiz_post_id ) ) && ( $quiz_id == $default_quiz_id ) ) ) {
$selected = ' selected="selected" ';
}
}
?>
<option <?php echo $selected; ?> data-course_id="<?php echo $quiz_id; ?>" value="<?php echo $item_url; ?>"><?php echo get_the_title( $quiz_id ); ?></option>
<?php
}
if ( $use_select_opt_groups === true ) {
?>
</optgroup>
<?php
}
}
?>
</select></p>
<?php
}
}
}