PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
← All changes | inc/TemplateHooks/Admin/AdminTemplate.php +173 -9 4.4.04.4.8 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2 namespace LearnPress\TemplateHooks\Admin;
3 3
4 4 use LearnPress\Helpers\Template;
5 +use LP_Request;
5 6
6 7 /**
7 8 * Template Show list items to select in popup.
8 9 *
@@ -46,12 +47,20 @@
46 47 * HTML for popup items to select.
47 48 *
48 49 * @param array $tabs [ [ key => label ] ].
49 50 * @param string $html_items
50 - *
51 + * @param string $html_filter_fields @since LP v4.4.6
52 + * @param array $extra_data @since LP v4.4.6 { 'classes' => '' }
51 53 * @return string
54 + * @since 4.2.8.7.1
55 + * @version 1.0.1
52 56 */
53 - public static function html_popup_items_to_select_clone( array $tabs, string $html_items ): string {
57 + public static function html_popup_items_to_select_clone(
58 + array $tabs,
59 + string $html_items,
60 + string $html_filter_fields = '',
61 + array $extra_data = []
62 + ): string {
54 63 $html_tabs = '';
55 64 $i = 0;
56 65 foreach ( $tabs as $key => $label ) {
57 66 $tab_active = '';
@@ -80,9 +89,9 @@
80 89
81 90 $section_main = [
82 91 'wrap' => '<div class="main">',
83 92 'wrap_items' => '<div class="list-items-wrap">',
84 - 'search' => sprintf(
93 + 'search' => ! empty( $html_filter_fields ) ? $html_filter_fields : sprintf(
85 94 '<input class="%1$s" name="%1$s" type="text" placeholder="%2$s">',
86 95 'lp-search-title-item',
87 96 __( 'Type here to search for an item', 'learnpress' )
88 97 ),
@@ -100,10 +109,13 @@
100 109
101 110 $section_footer = [
102 111 'wrap' => '<div class="footer">',
103 112 'btn-add' => sprintf(
104 - '<button type="button" disabled="disabled" class="button lp-btn-add-items-selected lp-btn-edit-primary">%s</button>',
105 - __( 'Add', 'learnpress' )
113 + '<button type="button" disabled="disabled"
114 + class="button lp-btn-add-items-selected lp-btn-edit-primary %s" %s>%s</button>',
115 + esc_attr( $extra_data['btn-add-classes'] ?? '' ),
116 + $extra_data['btn-add-attrs'] ?? '', // No esc_attr here
117 + $extra_data['btn-add-label'] ?? __( 'Add', 'learnpress' )
106 118 ),
107 119 'count-items-selected' => sprintf(
108 120 '<button type="button" disabled="disabled" class="button lp-btn-count-items-selected">%s %s</button>',
109 121 sprintf( __( 'Selected items', 'learnpress' ), 0 ),
@@ -112,13 +124,17 @@
112 124 'btn-back' => sprintf(
113 125 '<button type="button" class="button lp-btn-back-to-select-items lp-hidden">%s</button>',
114 126 __( 'Back', 'learnpress' )
115 127 ),
128 + 'btn-custom' => $extra_data['btn-custom'] ?? '',
116 129 'wrap_end' => '</div>',
117 130 ];
118 131
119 132 $section = [
120 - 'wrap' => '<div class="lp-popup-items-to-select">',
133 + 'wrap' => sprintf(
134 + '<div class="lp-popup-items-to-select %s">',
135 + esc_attr( $extra_data['classes'] ?? '' )
136 + ),
121 137 'header' => Template::combine_components( $section_header ),
122 138 'main' => Template::combine_components( $section_main ),
123 139 'footer' => Template::combine_components( $section_footer ),
124 140 'wrap_end' => '</div>',
@@ -139,9 +155,9 @@
139 155 * }
140 156 *
141 157 * @return string
142 158 * @since 4.3.0
143 - * @version 1.0.0
159 + * @version 1.0.1
144 160 */
145 161 public static function html_tom_select( array $args = [] ): string {
146 162 $html_options = '';
147 163
@@ -150,8 +166,10 @@
150 166 $class_name = $args['class_name'] ?? '';
151 167 $default_value = $args['default_value'] ?? '';
152 168 $multiple = $args['multiple'] ?? false;
153 169 $multiple = $multiple ? 'multiple' : '';
170 + $struct = $args['struct'] ?? [];
171 + $saved = $args['saved'] ?? '';
154 172 foreach ( $options as $key => $value ) {
155 173 if ( is_array( $default_value ) ) {
156 174 $selected = in_array( $key, $default_value, true ) ? 'selected' : '';
157 175 } else {
@@ -162,12 +180,14 @@
162 180 }
163 181
164 182 $section = [
165 183 'select' => sprintf(
166 - '<select name="%s" class="%s lp-tom-select" %s>',
184 + '<select name="%s" class="%s lp-tom-select" %s data-struct="%s" data-save="%s">',
167 185 esc_attr( $name ),
168 186 esc_attr( $class_name ),
169 - $multiple
187 + esc_attr( $multiple ),
188 + esc_attr( htmlentities2( json_encode( $struct ) ) ),
189 + esc_attr( htmlentities2( json_encode( $saved ) ) ),
170 190 ),
171 191 'options' => $html_options,
172 192 'select-end' => '</select>',
173 193 ];
@@ -172,6 +192,150 @@
172 192 'select-end' => '</select>',
173 193 ];
174 194
175 195 return Template::combine_components( $section );
196 + }
197 +
198 + /**
199 + * Render a toggle switch (checkbox + track) for enabling or disabling a setting.
200 + *
201 + * @param array $data Toggle configuration. Accepts:
202 + * - classes: CSS classes for the input.
203 + * - name: Input name attribute (default: 'lp_toggle_enable').
204 + * - value: Current value (truthy/falsy).
205 + *
206 + * @return string HTML markup for the toggle switch.
207 + * @since 4.4.5
208 + * @version 1.0.0
209 + */
210 + public static function html_toggle_enable( array $data = [] ): string {
211 + $classes = $data['classes'] ?? '';
212 + $name = $data['name'] ?? 'lp_toggle_enable';
213 + $value = $data['value'] ?? 0;
214 + $checked = $value ? 'checked' : '';
215 +
216 + $section = [
217 + 'wrapper' => sprintf(
218 + '<label class="lp-toggle-enable %s">',
219 + $value ? 'is-enabled' : ''
220 + ),
221 + 'input' => sprintf(
222 + '<input type="checkbox" class="lp-toggle-enable__input %s"
223 + name="%s"
224 + value="%s"
225 + data-info="%s"
226 + %s/>',
227 + esc_attr( $classes ),
228 + esc_attr( $name ),
229 + esc_attr( $value ),
230 + esc_attr( Template::convert_data_to_json( $data ) ),
231 + esc_attr( $checked )
232 + ),
233 + 'track' => '<span class="lp-toggle-enable__track"></span>',
234 + 'wrapper-end' => '</label>',
235 + ];
236 +
237 + return Template::combine_components( $section );
238 + }
239 +
240 + /**
241 + * HTML form filter
242 + *
243 + * @param array $data
244 + * @return string
245 + * @since 4.4.5
246 + * @version 1.0.0
247 + */
248 + public static function html_form_filter( array $data = [] ): string {
249 + $form_classes = $data['form_classes'] ?? '';
250 + $id = $data['id'] ?? '';
251 + $html_fields = $data['fields'] ?? '';
252 + $html_btn_actions = $data['btn_actions'] ?? '';
253 +
254 + $sections = array(
255 + 'wrap' => sprintf(
256 + '<form class="lp-form-filter %s"%s>',
257 + esc_attr( $form_classes ),
258 + $id ? sprintf( ' id="%s"', esc_attr( $id ) ) : ''
259 + ),
260 + 'fields' => sprintf(
261 + '<div class="lp-form-filter__fields">%s</div>',
262 + $html_fields
263 + ),
264 + 'btn-actions' => sprintf(
265 + '<div class="lp-form-filter__actions">%s</div>',
266 + $html_btn_actions
267 + ),
268 + 'wrap_end' => '</form>',
269 + );
270 +
271 + return Template::combine_components( $sections );
272 + }
273 +
274 + /**
275 + * Display content html by format WP Admin Screen
276 + *
277 + * @param array $data ['tabs' => [ 'tab' => 'name' ], 'content' => '', 'title' => '', 'id' => ''].
278 + * @return string
279 + * @since 4.4.5
280 + * @version 1.0.0
281 + */
282 + public static function html_on_wp_admin_screen( array $data = [] ): string {
283 + $tabs = $data['tabs'] ?? [];
284 + $active_tab = LP_Request::get_param( 'tab' );
285 + if ( empty( $active_tab ) || ! isset( $tabs[ $active_tab ] ) ) {
286 + $tab_keys = array_keys( $tabs );
287 + $active_tab = reset( $tab_keys );
288 + }
289 + $content = $data['content'] ?? '';
290 + $title = $data['title'] ?? '';
291 + $id = $data['id'] ?? '';
292 +
293 + $classes = array( 'wrap' );
294 + if ( $id ) {
295 + $classes[] = $id;
296 + }
297 +
298 + $html_tabs = '';
299 + if ( $tabs ) {
300 + foreach ( $tabs as $tab => $tab_title ) {
301 + $active_class = ( $tab == $active_tab ) ? ' nav-tab-active' : '';
302 +
303 + if ( $active_class ) {
304 + $html_tabs .= sprintf(
305 + '<span class="nav-tab%s">%s</span>',
306 + esc_attr( $active_class ),
307 + esc_html( $tab_title )
308 + );
309 + } else {
310 + $html_tabs .= sprintf(
311 + '<a class="nav-tab" href="?page=%s&tab=%s">%s</a>',
312 + esc_attr( $id ),
313 + esc_attr( $tab ),
314 + esc_html( $tab_title )
315 + );
316 + }
317 + }
318 + }
319 +
320 + $sections = array(
321 + 'wrap' => sprintf(
322 + '<div class="%s">',
323 + esc_attr( implode( ' ', $classes ) )
324 + ),
325 + 'heading' => $title ? sprintf(
326 + '<h1 class="wp-heading-inline">%s</h1>',
327 + wp_kses_post( $title )
328 + ) : '',
329 + 'tabs' => $tabs ? sprintf(
330 + '<h2 class="nav-tab-wrapper">%s</h2>',
331 + $html_tabs
332 + ) : '',
333 + 'wrap-content' => '<div class="lp-admin-tabs">',
334 + 'content' => $content,
335 + 'wrap-content-end' => '</div>',
336 + 'wrap-end' => '</div>',
337 + );
338 +
339 + return Template::combine_components( $sections );
176 340 }
177 341 }