PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.6
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.6
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 3.1.6, at lib/adminify-framework/fields/spacing/spacing.php

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