PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / 4.0.0
پارسی دیت – Parsi Date v4.0.0
6.1 5.1.6 5.1.7 5.1.8 5.1.8.2 6.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.0.0-alpha 2.1 2.1.1 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0.1 2.3.0.2 2.3.1 2.3.2 2.3.3 2.3.4 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5
wp-parsidate / includes / settings.php
wp-parsidate / includes Last commit date
admin 4 years ago plugins 4 years ago widget 4 years ago fixes-archive.php 4 years ago fixes-archives.php 4 years ago fixes-calendar.php 4 years ago fixes-dates.php 4 years ago fixes-misc.php 4 years ago fixes-permalinks.php 4 years ago general.php 4 years ago install.php 4 years ago parsidate.php 4 years ago settings.php 4 years ago
settings.php
703 lines
1 <?php
2
3 defined( 'ABSPATH' ) or exit( 'No direct script access allowed' );
4
5 /**
6 * Adds settings part to plugin
7 * Originally, wrote by Pippin Williamson
8 *
9 * @author Pippin Williamson
10 * @author Ehsaan
11 * @author Morteza Geransayeh
12 * @author Mobin Ghasempoor
13 * @package WP-Parsidate
14 * @subpackage Admin/Settings
15 */
16 add_action( 'admin_menu', 'wpp_add_settings_menu', 11 );
17
18 /**
19 * Add WP-Parsidate admin page settings
20 * */
21 function wpp_add_settings_menu() {
22 if ( wpp_is_active( 'submenu_move' ) ) {
23 add_submenu_page(
24 'options-general.php',
25 __( 'Parsi Settings', 'wp-parsidate' ),
26 __( 'Parsi Settings', 'wp-parsidate' ),
27 'manage_options',
28 'wp-parsi-settings',
29 'wpp_render_settings'
30 );
31 } else {
32 add_menu_page(
33 __( 'Parsi Settings', 'wp-parsidate' ),
34 __( 'Parsi Settings', 'wp-parsidate' ),
35 'manage_options',
36 'wp-parsi-settings',
37 'wpp_render_settings',
38 'dashicons-admin-site'
39 );
40 }
41
42 add_action( 'admin_enqueue_scripts', 'wpp_enqueue_setting_page_style' );
43 }
44
45 /**
46 * Gets saved settings from WP core
47 *
48 * @return array Parsi Settings
49 * @since 2.0
50 */
51 function wp_parsi_get_settings() {
52 $settings = get_option( 'wpp_settings' );
53
54 if ( empty( $settings ) ) {
55 update_option( 'wpp_settings', array(
56 'admin_lang' => 'disable',
57 'user_lang' => 'disable',
58 'persian_date' => 'disable',
59 'disable_widget_block' => 'disable',
60 'submenu_move' => 'disable',
61 'dev_mode' => 'disable',
62 'conv_title' => 'disable',
63 'conv_contents' => 'disable',
64 'conv_excerpt' => 'disable',
65 'conv_comments' => 'disable',
66 'conv_comment_count' => 'disable',
67 'conv_dates' => 'disable',
68 'conv_cats' => 'disable',
69 'conv_arabic' => 'disable',
70 'conv_permalinks' => 'disable',
71 'news_source' => 'parsi'
72 ) );
73 }
74 // Check settings synced with wpp version 4.0.0
75 /*if ( ! empty( $settings ) ) {
76 $settings_ver = get_option( 'wpp_settings_ver' );
77
78 if ( empty( $settings_ver ) ) {
79 $settings = wpp_sync_setting_version( $settings );
80 }
81 }*/
82
83 return apply_filters( 'wpp_get_settings', $settings );
84 }
85
86 /**
87 * Registers settings in WP core
88 *
89 * @return void
90 * @since 2.0
91 */
92 function wpp_register_settings() {
93 if ( false == get_option( 'wpp_settings' ) ) {
94 add_option( 'wpp_settings', array() );
95 }
96
97 foreach ( wpp_get_registered_settings() as $tab => $settings ) {
98 add_settings_section(
99 'wpp_settings_' . $tab,
100 __return_null(),
101 '__return_false',
102 'wpp_settings_' . $tab
103 );
104
105 foreach ( $settings as $option ) {
106 $name = isset( $option['name'] ) ? $option['name'] : '';
107
108 add_settings_field(
109 'wpp_settings[' . $option['id'] . ']',
110 $name,
111 function_exists( 'wpp_' . $option['type'] . '_callback' ) ? 'wpp_' . $option['type'] . '_callback' : 'wpp_missing_callback',
112 'wpp_settings_' . $tab,
113 'wpp_settings_' . $tab,
114 array(
115 'id' => isset( $option['id'] ) ? $option['id'] : null,
116 'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '',
117 'name' => isset( $option['name'] ) ? $option['name'] : null,
118 'section' => $tab,
119 'size' => isset( $option['size'] ) ? $option['size'] : null,
120 'options' => isset( $option['options'] ) ? $option['options'] : '',
121 'std' => isset( $option['std'] ) ? $option['std'] : ''
122 )
123 );
124
125 register_setting( 'wpp_settings', 'wpp_settings', 'wpp_settings_sanitize' );
126 }
127 }
128 }
129
130 add_action( 'admin_init', 'wpp_register_settings' );
131
132 /**
133 * Gets settings tabs
134 *
135 * @return array Tabs list
136 * @since 2.0
137 */
138 function wpp_get_tabs() {
139 return array(
140 'core' => sprintf( __( '%s Core', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-site"></span>' ),
141 'conv' => sprintf( __( '%s Converts', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-settings"></span>' ),
142 'plugins' => sprintf( __( '%s Plugins compatibility', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-plugins"></span>' )
143 );
144 }
145
146 /**
147 * Sanitizes and saves settings after submit
148 *
149 * @param array $input Settings input
150 *
151 * @return array New settings
152 * @since 2.0
153 *
154 */
155 function wpp_settings_sanitize( $input = array() ) {
156 global $wpp_settings;
157
158 if ( empty( $_POST['_wp_http_referer'] ) ) {
159 return $input;
160 }
161
162 parse_str( $_POST['_wp_http_referer'], $referrer );
163
164 $settings = wpp_get_registered_settings();
165 $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'core';
166 $input = $input ?: array();
167 $input = apply_filters( 'wpp_settings_' . $tab . '_sanitize', $input );
168
169 // Loop through each setting being saved and pass it through a sanitization filter
170 foreach ( $input as $key => $value ) {
171 // Get the setting type (checkbox, select, etc.)
172 $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false;
173
174 if ( $type ) {
175 // Field type specific filter
176 $input[ $key ] = apply_filters( 'wpp_settings_sanitize_' . $type, $value, $key );
177 }
178
179 // General filter
180 $input[ $key ] = apply_filters( 'wpp_settings_sanitize', $value, $key );
181 }
182
183 // Loop through the whitelist and unset any that are empty for the tab being saved
184 if ( ! empty( $settings[ $tab ] ) ) {
185 foreach ( $settings[ $tab ] as $key => $value ) {
186 // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
187 if ( is_numeric( $key ) ) {
188 $key = $value['id'];
189 }
190
191 if ( empty( $input[ $key ] ) ) {
192 unset( $wpp_settings[ $key ] );
193 }
194 }
195 }
196
197 // Merge our new settings with the existing
198 return array_merge( $wpp_settings, $input );
199 }
200
201 /**
202 * Get settings fields
203 *
204 * @return array Fields
205 * @since 2.0
206 */
207 function wpp_get_registered_settings() {
208 $options = array(
209 'enable' => __( 'Enable', 'wp-parsidate' ),
210 'disable' => __( 'Disable', 'wp-parsidate' )
211 );
212
213 return apply_filters( 'wpp_registered_settings', array(
214 'core' => apply_filters( 'wpp_core_settings', array(
215 'admin_lang' => array(
216 'id' => 'admin_lang',
217 'name' => __( 'Change Locale in admin', 'wp-parsidate' ),
218 'type' => 'checkbox',
219 'options' => 'enable',
220 'std' => 0,
221 'desc' => __( 'This option change WordPress locale to Persian in Admin', 'wp-parsidate' )
222 ),
223 'user_lang' => array(
224 'id' => 'user_lang',
225 'name' => __( 'Change Locale in theme', 'wp-parsidate' ),
226 'type' => 'checkbox',
227 'options' => 'enable',
228 'std' => 0,
229 'desc' => __( 'This option change WordPress locale to Persian in theme', 'wp-parsidate' )
230 ),
231 'persian_date' => array(
232 'id' => 'persian_date',
233 'name' => __( 'Shamsi date', 'wp-parsidate' ),
234 'type' => 'checkbox',
235 'options' => 'enable',
236 'std' => 0,
237 'desc' => __( 'By enabling this, Dates will convert to Shamsi (Jalali) dates', 'wp-parsidate' )
238 ),
239 'disable_widget_block' => array(
240 'id' => 'disable_widget_block',
241 'name' => __( 'Disable Widget Block', 'wp-parsidate' ),
242 'type' => 'checkbox',
243 'options' => 'enable',
244 'std' => 0,
245 'desc' => __( 'By enabling this, Widget Block Editor disabled', 'wp-parsidate' )
246 ),
247 'submenu_move' => array(
248 'id' => 'submenu_move',
249 'name' => __( 'Move page to submenu?', 'wp-parsidate' ),
250 'type' => 'checkbox',
251 'options' => 'enable',
252 'std' => 0,
253 'desc' => __( 'By enabling this option, page item will be moved to Settings menu as submenu.', 'wp-parsidate' )
254 ),
255 'dev_mode' => array(
256 'id' => 'dev_mode',
257 'name' => __( 'Debug Mode', 'wp-parsidate' ),
258 'type' => 'checkbox',
259 'options' => 'enable',
260 'std' => 0,
261 'desc' => __( 'By enabling this option, the uncompressed version of the JS and CSS files will be loaded.', 'wp-parsidate' )
262 ),
263 ) ),
264 'conv' => apply_filters( 'wpp_conv_settings', array(
265 'conv_nums' => array(
266 'id' => 'conv_nums',
267 'name' => __( 'Persian digits', 'wp-parsidate' ),
268 'type' => 'header'
269 ),
270 'conv_page_title' => array(
271 'id' => 'conv_page_title',
272 'name' => __( 'Page title', 'wp-parsidate' ),
273 'type' => 'checkbox',
274 'options' => 'enable',
275 'std' => 0
276 ),
277 'conv_title' => array(
278 'id' => 'conv_title',
279 'name' => __( 'Post title', 'wp-parsidate' ),
280 'type' => 'checkbox',
281 'options' => 'enable',
282 'std' => 0
283 ),
284 'conv_contents' => array(
285 'id' => 'conv_contents',
286 'name' => __( 'Post content', 'wp-parsidate' ),
287 'type' => 'checkbox',
288 'options' => 'enable',
289 'std' => 'enable'
290 ),
291 'conv_excerpt' => array(
292 'id' => 'conv_excerpt',
293 'name' => __( 'Post excerpt', 'wp-parsidate' ),
294 'type' => 'checkbox',
295 'options' => 'enable',
296 'std' => 0
297 ),
298 'conv_comments' => array(
299 'id' => 'conv_comments',
300 'name' => __( 'Comments text', 'wp-parsidate' ),
301 'type' => 'checkbox',
302 'options' => 'enable',
303 'std' => 0
304 ),
305 'conv_comment_count' => array(
306 'id' => 'conv_comment_count',
307 'name' => __( 'Comments count', 'wp-parsidate' ),
308 'type' => 'checkbox',
309 'options' => 'enable',
310 'std' => 0
311 ),
312 'conv_dates' => array(
313 'id' => 'conv_dates',
314 'name' => __( 'Dates', 'wp-parsidate' ),
315 'type' => 'checkbox',
316 'options' => 'enable',
317 'std' => 0
318 ),
319 'conv_cats' => array(
320 'id' => 'conv_cats',
321 'name' => __( 'Categories', 'wp-parsidate' ),
322 'type' => 'checkbox',
323 'options' => 'enable',
324 'std' => 0
325 ),
326 'sep' => array(
327 'id' => 'sep',
328 'type' => 'header'
329 ),
330 'conv_arabic' => array(
331 'id' => 'conv_arabic',
332 'name' => __( 'Fix arabic characters', 'wp-parsidate' ),
333 'type' => 'checkbox',
334 'options' => 'enable',
335 'std' => 'disable',
336 'desc' => __( 'Fixes arabic characters caused by wrong keyboard layouts', 'wp-parsidate' )
337 ),
338 'conv_permalinks' => array(
339 'id' => 'conv_permalinks',
340 'name' => __( 'Fix permalinks dates', 'wp-parsidate' ),
341 'type' => 'checkbox',
342 'options' => 'enable',
343 'std' => 0,
344 'desc' => __( 'By enabling this, dates in permalinks converted to Shamsi (Jalali) date', 'wp-parsidate' )
345 ),
346 'sep_font' => array(
347 'id' => 'sep_font',
348 'type' => 'header'
349 )
350 ) ),
351 'plugins' => apply_filters( 'wpp_plugins_compatibility_settings', array() )
352 ) );
353 }
354
355 /* Form Callbacks Made by EDD Development Team */
356 /**
357 * @param $args
358 */
359 function wpp_header_callback( $args ) {
360 echo '<hr/>';
361 }
362
363 /**
364 * @param $args
365 */
366 function wpp_checkbox_callback( $args ) {
367 global $wpp_settings;
368
369 $checked = isset( $wpp_settings[ $args['id'] ] ) ? checked( 'enable', $wpp_settings[ $args['id'] ], false ) : '';
370 $html = sprintf( '<input type="checkbox" id="wpp_settings[%1$s]" name="wpp_settings[%1$s]" value="enable" %2$s/>' .
371 '<label for="wpp_settings[%1$s]" class="wpp-checkbox-label %3$s"><span></span> %4$s</label>',
372 $args['id'],
373 $checked,
374 empty( $args['desc'] ) ? 'empty-label' : '',
375 $args['desc']
376 );
377
378 echo $html;
379 }
380
381 /**
382 * @param $args
383 */
384 function wpp_multicheck_callback( $args ) {
385 $html = '';
386
387 foreach ( $args['options'] as $key => $value ) {
388 $option_name = $args['id'] . '-' . $key;
389
390 wpp_checkbox_callback( array(
391 'id' => $option_name,
392 'desc' => $value
393 ) );
394
395 echo '<br>';
396 }
397
398 echo $html;
399 }
400
401 /**
402 * @param $args
403 */
404 function wpp_radio_callback( $args ) {
405 global $wpp_settings;
406
407 foreach ( $args['options'] as $key => $option ) :
408 $checked = false;
409
410 if ( isset( $wpp_settings[ $args['id'] ] ) && $wpp_settings[ $args['id'] ] == $key ) {
411 $checked = true;
412 } elseif ( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpp_settings[ $args['id'] ] ) ) {
413 $checked = true;
414 }
415
416 echo '<input name="wpp_settings[' . $args['id'] . ']"" id="wpp_settings[' . $args['id'] . '][' . $key . ']" type="radio" value="' . $key . '" ' . checked( true, $checked, false ) . '/>';
417 echo '<label for="wpp_settings[' . $args['id'] . '][' . $key . ']">' . $option . '</label>&nbsp;&nbsp;';
418 endforeach;
419
420 echo '<p class="description">' . $args['desc'] . '</p>';
421 }
422
423 /**
424 * @param $args
425 */
426 function wpp_text_callback( $args ) {
427 global $wpp_settings;
428
429 if ( isset( $wpp_settings[ $args['id'] ] ) ) {
430 $value = $wpp_settings[ $args['id'] ];
431 } else {
432 $value = isset( $args['std'] ) ? $args['std'] : '';
433 }
434
435 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
436 $html = '<input type="text" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
437 $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
438
439 echo $html;
440 }
441
442 /**
443 * @param $args
444 */
445 function wpp_number_callback( $args ) {
446 global $wpp_settings;
447
448 if ( isset( $wpp_settings[ $args['id'] ] ) ) {
449 $value = $wpp_settings[ $args['id'] ];
450 } else {
451 $value = isset( $args['std'] ) ? $args['std'] : '';
452 }
453
454 $max = isset( $args['max'] ) ? $args['max'] : 999999;
455 $min = isset( $args['min'] ) ? $args['min'] : 0;
456 $step = isset( $args['step'] ) ? $args['step'] : 1;
457 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
458 $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
459 $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
460
461 echo $html;
462 }
463
464 /**
465 * @param $args
466 */
467 function wpp_textarea_callback( $args ) {
468 global $wpp_settings;
469
470 if ( isset( $wpp_settings[ $args['id'] ] ) ) {
471 $value = $wpp_settings[ $args['id'] ];
472 } else {
473 $value = isset( $args['std'] ) ? $args['std'] : '';
474 }
475
476 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
477 $html = '<textarea class="large-text" cols="50" rows="5" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
478 $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
479
480 echo $html;
481 }
482
483 /**
484 * @param $args
485 */
486 function wpp_password_callback( $args ) {
487 global $wpp_settings;
488
489 if ( isset( $wpp_settings[ $args['id'] ] ) ) {
490 $value = $wpp_settings[ $args['id'] ];
491 } else {
492 $value = isset( $args['std'] ) ? $args['std'] : '';
493 }
494
495 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
496 $html = '<input type="password" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>';
497 $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
498
499 echo $html;
500 }
501
502 /**
503 * @param $args
504 *
505 * @return false
506 */
507 function wpp_missing_callback( $args ) {
508 echo '&ndash;';
509
510 return false;
511 }
512
513
514 /**
515 * @param $args
516 */
517 function wpp_select_callback( $args ) {
518 global $wpp_settings;
519
520 if ( isset( $wpp_settings[ $args['id'] ] ) ) {
521 $value = $wpp_settings[ $args['id'] ];
522 } else {
523 $value = isset( $args['std'] ) ? $args['std'] : '';
524 }
525
526 $html = '<select id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']"/>';
527
528 foreach ( $args['options'] as $option => $name ) :
529 $selected = selected( $option, $value, false );
530 $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>';
531 endforeach;
532
533 $html .= '</select>';
534 $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
535
536 echo $html;
537 }
538
539 /**
540 * @param $args
541 */
542 function wpp_color_select_callback( $args ) {
543 global $wpp_settings;
544
545 if ( isset( $wpp_settings[ $args['id'] ] ) ) {
546 $value = $wpp_settings[ $args['id'] ];
547 } else {
548 $value = isset( $args['std'] ) ? $args['std'] : '';
549 }
550
551 $html = '<select id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']"/>';
552
553 foreach ( $args['options'] as $option => $color ) :
554 $selected = selected( $option, $value, false );
555 $html .= '<option value="' . $option . '" ' . $selected . '>' . $color['label'] . '</option>';
556 endforeach;
557
558 $html .= '</select>';
559 $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
560
561 echo $html;
562 }
563
564 /**
565 * @param $args
566 */
567 function wpp_rich_editor_callback( $args ) {
568 global $wpp_settings, $wp_version;
569
570 if ( isset( $wpp_settings[ $args['id'] ] ) ) {
571 $value = $wpp_settings[ $args['id'] ];
572 } else {
573 $value = isset( $args['std'] ) ? $args['std'] : '';
574 }
575
576 if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
577 ob_start();
578
579 wp_editor( stripslashes( $value ), 'wpp_settings[' . $args['id'] . ']', array( 'textarea_name' => 'wpp_settings[' . $args['id'] . ']' ) );
580
581 $html = ob_get_contents();
582
583 ob_end_clean();
584 } else {
585 $html = '<textarea class="large-text" rows="10" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
586 }
587
588 $html .= '<br/><label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
589
590 echo $html;
591 }
592
593 /**
594 * @param $args
595 */
596 function wpp_upload_callback( $args ) {
597 global $wpp_settings;
598
599 if ( isset( $wpp_settings[ $args['id'] ] ) ) {
600 $value = $wpp_settings[ $args['id'] ];
601 } else {
602 $value = isset( $args['std'] ) ? $args['std'] : '';
603 }
604
605 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
606 $html = '<input type="text" class="' . $size . '-text wpp_upload_field" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
607 $html .= '<span>&nbsp;<input type="button" class="wpp_settings_upload_button button-secondary" value="' . __( 'Upload File', 'wpp' ) . '"/></span>';
608 $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
609
610 echo $html;
611 }
612
613 /**
614 * @param $args
615 */
616 function wpp_color_callback( $args ) {
617 global $wpp_settings;
618
619 if ( isset( $wpp_settings[ $args['id'] ] ) ) {
620 $value = $wpp_settings[ $args['id'] ];
621 } else {
622 $value = isset( $args['std'] ) ? $args['std'] : '';
623 }
624
625 $default = isset( $args['std'] ) ? $args['std'] : '';
626 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
627 $html = '<input type="text" class="wpp-color-picker" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
628 $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>';
629
630 echo $html;
631 }
632
633 function wpp_render_settings() {
634 $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], wpp_get_tabs() ) ? $_GET['tab'] : 'core';
635
636 ob_start();
637 ?>
638 <div class="wrap wpp-settings-wrap">
639 <h2><?php _e( 'Parsi Settings', 'wp-parsidate' ) ?></h2>
640 <h2 class="nav-tab-wrapper">
641 <?php
642 foreach ( wpp_get_tabs() as $tab_id => $tab_name ) {
643
644 $tab_url = add_query_arg( array(
645 'settings-updated' => false,
646 'tab' => $tab_id
647 ) );
648
649 $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
650
651 echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
652 echo $tab_name;
653 echo '</a>';
654 }
655 ?>
656 </h2>
657 <?php settings_errors( 'wpp-notices' ); ?>
658 <div id="tab_container">
659 <form method="post" action="options.php">
660 <table class="form-table">
661 <?php
662 settings_fields( 'wpp_settings' );
663 do_settings_fields( 'wpp_settings_' . $active_tab, 'wpp_settings_' . $active_tab );
664 ?>
665 </table>
666 <?php submit_button(); ?>
667 </form>
668 </div><!-- #tab_container-->
669 </div><!-- .wrap -->
670 <?php
671 echo ob_get_clean();
672 }
673
674 /**
675 * Gets an option name and check that option is active or not
676 *
677 * @param $option_name
678 *
679 * @return bool
680 * @since 4.0.0
681 */
682 function wpp_is_active( $option_name ) {
683 global $wpp_settings;
684
685 return ! empty($wpp_settings[$option_name]) && 'enable' === $wpp_settings[$option_name];
686 }
687
688 /**
689 * Enqueue setting page style
690 *
691 * @param $hook
692 *
693 * @since 4.0.0
694 */
695 function wpp_enqueue_setting_page_style( $hook ) {
696 if ( ! in_array( $hook, array( 'toplevel_page_wp-parsi-settings', 'settings_page_wp-parsi-settings' ) ) ) {
697 return;
698 }
699
700 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || wpp_is_active( 'dev_mode' ) ? '' : '.min';
701
702 wp_enqueue_style( 'wpp_option_page', WP_PARSI_URL . "assets/css/settings$suffix.css", null, WP_PARSI_VER );
703 }