PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Libs / adminify-framework / fields / checkbox / checkbox.php

checkbox.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.0, at Libs/adminify-framework/fields/checkbox/checkbox.php

104 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2
3 use WPAdminify\Inc\Utils;
4 /**
5 *
6 * Field: checkbox
7 *
8 * @since 1.0.0
9 * @version 1.0.0
10 *
11 */
12 if ( ! class_exists( 'ADMINIFY_Field_checkbox' ) ) {
13 class ADMINIFY_Field_checkbox extends ADMINIFY_Fields {
14
15 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
16 parent::__construct( $field, $value, $unique, $where, $parent );
17 }
18
19 public function render() {
20
21 $args = wp_parse_args( $this->field, array(
22 'inline' => false,
23 'query_args' => array(),
24 'check_all' => false,
25 'check_all_text' => esc_html__( 'Check/Uncheck All' ),
26 ) );
27
28 $inline_class = ( $args['inline'] ) ? ' class="adminify--inline-list"' : '';
29
30 echo $this->field_before();
31
32 if ( isset( $this->field['options'] ) ) {
33
34 $value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
35 $options = $this->field['options'];
36 $options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) );
37
38 if ( is_array( $options ) && ! empty( $options ) ) {
39
40 echo '<ul'. $inline_class .'>';
41
42 foreach ( $options as $option_key => $option_value ) {
43
44 if ( is_array( $option_value ) && ! empty( $option_value ) ) {
45
46 echo '<li>';
47 echo '<ul>';
48 echo '<li><strong>'. esc_attr( $option_key ) .'</strong></li>';
49 foreach ( $option_value as $sub_key => $sub_value ) {
50 $checked = ( in_array( $sub_key, $value ) ) ? ' checked' : '';
51 echo '<li>';
52 echo '<label>';
53 echo '<input type="checkbox" name="'. esc_attr( $this->field_name( '[]' ) ) .'" value="'. esc_attr( $sub_key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
54 echo '<span class="adminify--text">'. Utils::wp_kses_custom( $sub_value ) .'</span>';
55 echo '</label>';
56 echo '</li>';
57 }
58 echo '</ul>';
59 echo '</li>';
60
61 } else {
62
63 $checked = ( in_array( $option_key, $value ) ) ? ' checked' : '';
64
65 echo '<li>';
66 echo '<label>';
67 echo '<input type="checkbox" name="'. esc_attr( $this->field_name( '[]' ) ) .'" value="'. esc_attr( $option_key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
68 echo '<span class="adminify--text">'. Utils::wp_kses_custom( $option_value ) .'</span>';
69 echo '</label>';
70 echo '</li>';
71
72 }
73
74 }
75
76 echo '</ul>';
77
78 if ( $args['check_all'] ) {
79 echo '<div class="adminify-checkbox-all">'. esc_html( $args['check_all_text'] ) .'</div>';
80 }
81
82 } else {
83
84 echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'adminify' );
85
86 }
87
88 } else {
89
90 echo '<label class="adminify-checkbox">';
91 echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. $this->value .'" class="adminify--input"'. $this->field_attributes() .'/>';
92 echo '<input type="checkbox" name="_pseudo" class="adminify--checkbox"'. esc_attr( checked( $this->value, 1, false ) ) . $this->field_attributes() .'/>';
93 echo ( ! empty( $this->field['label'] ) ) ? '<span class="adminify--text">'. Utils::wp_kses_custom( $this->field['label'] ) .'</span>' : '';
94 echo '</label>';
95
96 }
97
98 echo $this->field_after();
99
100 }
101
102 }
103 }
104