PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 2.0.0
Adminify – White Label, Admin Menu Editor, Login Customizer v2.0.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 / lib / adminify-framework / fields / spacing / spacing.php

spacing.php in Adminify – White Label, Admin Menu Editor, Login Customizer 2.0.0, at lib/adminify-framework/fields/spacing/spacing.php

172 lines 6.8 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 *
4 * Field: spacing
5 *
6 * @since 1.0.0
7 * @version 1.0.0
8 *
9 */
10 if ( ! class_exists( 'ADMINIFY_Field_spacing' ) ) {
11 class ADMINIFY_Field_spacing extends ADMINIFY_Fields {
12
13 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
14 parent::__construct( $field, $value, $unique, $where, $parent );
15 }
16
17 public function render() {
18
19 $args = wp_parse_args( $this->field, array(
20 'top_icon' => '<i class="fas fa-long-arrow-alt-up"></i>',
21 'right_icon' => '<i class="fas fa-long-arrow-alt-right"></i>',
22 'bottom_icon' => '<i class="fas fa-long-arrow-alt-down"></i>',
23 'left_icon' => '<i class="fas fa-long-arrow-alt-left"></i>',
24 'all_icon' => '<i class="fas fa-arrows-alt"></i>',
25 'top_placeholder' => esc_html__( 'top', 'adminify' ),
26 'right_placeholder' => esc_html__( 'right', 'adminify' ),
27 'bottom_placeholder' => esc_html__( 'bottom', 'adminify' ),
28 'left_placeholder' => esc_html__( 'left', 'adminify' ),
29 'all_placeholder' => esc_html__( 'all', 'adminify' ),
30 'top' => true,
31 'left' => true,
32 'bottom' => true,
33 'right' => true,
34 'unit' => true,
35 'show_units' => true,
36 'all' => false,
37 'units' => array( 'px', '%', 'em' )
38 ) );
39
40 $default_values = array(
41 'top' => '',
42 'right' => '',
43 'bottom' => '',
44 'left' => '',
45 'all' => '',
46 'unit' => 'px',
47 );
48
49 $value = wp_parse_args( $this->value, $default_values );
50 $unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : '';
51 $is_unit = ( ! empty( $unit ) ) ? ' adminify--is-unit' : '';
52
53 echo $this->field_before();
54
55 echo '<div class="adminify--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
56
57 if ( ! empty( $args['all'] ) ) {
58
59 $placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['all_placeholder'] ) .'"' : '';
60
61 echo '<div class="adminify--input">';
62 echo ( ! empty( $args['all_icon'] ) ) ? '<span class="adminify--label adminify--icon">'. $args['all_icon'] .'</span>' : '';
63 echo '<input type="number" name="'. esc_attr( $this->field_name( '[all]' ) ) .'" value="'. esc_attr( $value['all'] ) .'"'. $placeholder .' class="adminify-input-number'. esc_attr( $is_unit ) .'" step="any" />';
64 echo ( $unit ) ? '<span class="adminify--label adminify--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
65 echo '</div>';
66
67 } else {
68
69 $properties = array();
70
71 foreach ( array( 'top', 'right', 'bottom', 'left' ) as $prop ) {
72 if ( ! empty( $args[$prop] ) ) {
73 $properties[] = $prop;
74 }
75 }
76
77 $properties = ( $properties === array( 'right', 'left' ) ) ? array_reverse( $properties ) : $properties;
78
79 foreach ( $properties as $property ) {
80
81 $placeholder = ( ! empty( $args[$property.'_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args[$property.'_placeholder'] ) .'"' : '';
82
83 echo '<div class="adminify--input">';
84 echo ( ! empty( $args[$property.'_icon'] ) ) ? '<span class="adminify--label adminify--icon">'. $args[$property.'_icon'] .'</span>' : '';
85 echo '<input type="number" name="'. esc_attr( $this->field_name( '['. $property .']' ) ) .'" value="'. esc_attr( $value[$property] ) .'"'. $placeholder .' class="adminify-input-number'. esc_attr( $is_unit ) .'" step="any" />';
86 echo ( $unit ) ? '<span class="adminify--label adminify--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
87 echo '</div>';
88
89 }
90
91 }
92
93 if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) {
94 echo '<div class="adminify--input">';
95 echo '<select name="'. esc_attr( $this->field_name( '[unit]' ) ) .'">';
96 foreach ( $args['units'] as $unit ) {
97 $selected = ( $value['unit'] === $unit ) ? ' selected' : '';
98 echo '<option value="'. esc_attr( $unit ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $unit ) .'</option>';
99 }
100 echo '</select>';
101 echo '</div>';
102 }
103
104 echo '</div>';
105
106 echo $this->field_after();
107
108 }
109
110 public function output() {
111
112 $output = '';
113 $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
114 $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
115 $unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
116
117 $mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'padding';
118
119 if ( $mode === 'border-radius' || $mode === 'radius' ) {
120
121 $top = 'border-top-left-radius';
122 $right = 'border-top-right-radius';
123 $bottom = 'border-bottom-right-radius';
124 $left = 'border-bottom-left-radius';
125
126 } else if ( $mode === 'relative' || $mode === 'absolute' || $mode === 'none' ) {
127
128 $top = 'top';
129 $right = 'right';
130 $bottom = 'bottom';
131 $left = 'left';
132
133 } else {
134
135 $top = $mode .'-top';
136 $right = $mode .'-right';
137 $bottom = $mode .'-bottom';
138 $left = $mode .'-left';
139
140 }
141
142 if ( ! empty( $this->field['all'] ) && isset( $this->value['all'] ) && $this->value['all'] !== '' ) {
143
144 $output = $element .'{';
145 $output .= $top .':'. $this->value['all'] . $unit . $important .';';
146 $output .= $right .':'. $this->value['all'] . $unit . $important .';';
147 $output .= $bottom .':'. $this->value['all'] . $unit . $important .';';
148 $output .= $left .':'. $this->value['all'] . $unit . $important .';';
149 $output .= '}';
150
151 } else {
152
153 $top = ( isset( $this->value['top'] ) && $this->value['top'] !== '' ) ? $top .':'. $this->value['top'] . $unit . $important .';' : '';
154 $right = ( isset( $this->value['right'] ) && $this->value['right'] !== '' ) ? $right .':'. $this->value['right'] . $unit . $important .';' : '';
155 $bottom = ( isset( $this->value['bottom'] ) && $this->value['bottom'] !== '' ) ? $bottom .':'. $this->value['bottom'] . $unit . $important .';' : '';
156 $left = ( isset( $this->value['left'] ) && $this->value['left'] !== '' ) ? $left .':'. $this->value['left'] . $unit . $important .';' : '';
157
158 if ( $top !== '' || $right !== '' || $bottom !== '' || $left !== '' ) {
159 $output = $element .'{'. $top . $right . $bottom . $left .'}';
160 }
161
162 }
163
164 $this->parent->output_css .= $output;
165
166 return $output;
167
168 }
169
170 }
171 }
172