← All changes
|
Libs/adminify-framework/fields/dimensions/dimensions.php
+75
-76
4.2.11
→
3.2.4.1
View file →
| @@ -1,5 +1,6 @@ | ||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 1 | +<?php if ( ! defined( 'ABSPATH' ) ) { | |
| 2 | + die; } // Cannot access directly. | |
| 2 | 3 | /** |
| 3 | 4 | * |
| 4 | 5 | * Field: dimensions |
| 5 | 6 | * |
| @@ -4,98 +5,96 @@ | ||
| 4 | 5 | * Field: dimensions |
| 5 | 6 | * |
| 6 | 7 | * @since 1.0.0 |
| 7 | 8 | * @version 1.0.0 |
| 8 | - * | |
| 9 | 9 | */ |
| 10 | 10 | if ( ! class_exists( 'ADMINIFY_Field_dimensions' ) ) { |
| 11 | - class ADMINIFY_Field_dimensions extends ADMINIFY_Fields { | |
| 11 | + class ADMINIFY_Field_dimensions extends ADMINIFY_Fields { | |
| 12 | 12 | |
| 13 | - public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { | |
| 14 | - parent::__construct( $field, $value, $unique, $where, $parent ); | |
| 15 | - } | |
| 13 | + public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { | |
| 14 | + parent::__construct( $field, $value, $unique, $where, $parent ); | |
| 15 | + } | |
| 16 | 16 | |
| 17 | - public function render() { | |
| 17 | + public function render() { | |
| 18 | + $args = wp_parse_args( | |
| 19 | + $this->field, | |
| 20 | + [ | |
| 21 | + 'width_icon' => '<i class="fas fa-arrows-alt-h"></i>', | |
| 22 | + 'height_icon' => '<i class="fas fa-arrows-alt-v"></i>', | |
| 23 | + 'width_placeholder' => esc_html__( 'width', 'adminify' ), | |
| 24 | + 'height_placeholder' => esc_html__( 'height', 'adminify' ), | |
| 25 | + 'width' => true, | |
| 26 | + 'height' => true, | |
| 27 | + 'unit' => true, | |
| 28 | + 'show_units' => true, | |
| 29 | + 'units' => [ 'px', '%', 'em' ], | |
| 30 | + ] | |
| 31 | + ); | |
| 18 | 32 | |
| 19 | - $args = wp_parse_args( $this->field, array( | |
| 20 | - 'width_icon' => '<i class="fas fa-arrows-alt-h"></i>', | |
| 21 | - 'height_icon' => '<i class="fas fa-arrows-alt-v"></i>', | |
| 22 | - 'width_placeholder' => esc_html__( 'width', 'adminify' ), | |
| 23 | - 'height_placeholder' => esc_html__( 'height', 'adminify' ), | |
| 24 | - 'width' => true, | |
| 25 | - 'height' => true, | |
| 26 | - 'unit' => true, | |
| 27 | - 'show_units' => true, | |
| 28 | - 'units' => array( 'px', '%', 'em' ) | |
| 29 | - ) ); | |
| 33 | + $default_values = [ | |
| 34 | + 'width' => '', | |
| 35 | + 'height' => '', | |
| 36 | + 'unit' => 'px', | |
| 37 | + ]; | |
| 30 | 38 | |
| 31 | - $default_values = array( | |
| 32 | - 'width' => '', | |
| 33 | - 'height' => '', | |
| 34 | - 'unit' => 'px', | |
| 35 | - ); | |
| 39 | + $value = wp_parse_args( $this->value, $default_values ); | |
| 40 | + $unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : ''; | |
| 41 | + $is_unit = ( ! empty( $unit ) ) ? ' adminify--is-unit' : ''; | |
| 36 | 42 | |
| 37 | - $value = wp_parse_args( $this->value, $default_values ); | |
| 38 | - $unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : ''; | |
| 39 | - $is_unit = ( ! empty( $unit ) ) ? ' adminify--is-unit' : ''; | |
| 43 | + echo wp_kses_post( $this->field_before() ); | |
| 40 | 44 | |
| 41 | - echo wp_kses_post( $this->field_before() ); | |
| 45 | + echo '<div class="adminify--inputs" data-depend-id="' . esc_attr( $this->field['id'] ) . '">'; | |
| 42 | 46 | |
| 43 | - echo '<div class="adminify--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">'; | |
| 47 | + if ( ! empty( $args['width'] ) ) { | |
| 48 | + $placeholder = ( ! empty( $args['width_placeholder'] ) ) ? ' placeholder="' . esc_attr( $args['width_placeholder'] ) . '"' : ''; | |
| 49 | + echo '<div class="adminify--input">'; | |
| 50 | + echo ( ! empty( $args['width_icon'] ) ) ? '<span class="adminify--label adminify--icon">' . wp_kses_post( $args['width_icon'] ) . '</span>' : ''; | |
| 51 | + echo '<input type="number" name="' . esc_attr( $this->field_name( '[width]' ) ) . '" value="' . esc_attr( $value['width'] ) . '"' . esc_attr( $placeholder ) . ' class="adminify-input-number' . esc_attr( $is_unit ) . '" step="any" />'; | |
| 52 | + echo ( ! empty( $unit ) ) ? '<span class="adminify--label adminify--unit">' . esc_attr( $args['units'][0] ) . '</span>' : ''; | |
| 53 | + echo '</div>'; | |
| 54 | + } | |
| 44 | 55 | |
| 45 | - if ( ! empty( $args['width'] ) ) { | |
| 46 | - $placeholder = ( ! empty( $args['width_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['width_placeholder'] ) .'"' : ''; | |
| 47 | - echo '<div class="adminify--input">'; | |
| 48 | - echo ( ! empty( $args['width_icon'] ) ) ? '<span class="adminify--label adminify--icon">'. wp_kses_post( $args['width_icon'] ) .'</span>' : ''; | |
| 49 | - echo '<input type="number" name="'. esc_attr( $this->field_name( '[width]' ) ) .'" value="'. esc_attr( $value['width'] ) .'"'. $placeholder .' class="adminify-input-number'. esc_attr( $is_unit ) .'" step="any" />'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- attribute value pre-escaped with esc_attr() where built. | |
| 50 | - echo ( ! empty( $unit ) ) ? '<span class="adminify--label adminify--unit">'. esc_attr( $args['units'][0] ) .'</span>' : ''; | |
| 51 | - echo '</div>'; | |
| 52 | - } | |
| 56 | + if ( ! empty( $args['height'] ) ) { | |
| 57 | + $placeholder = ( ! empty( $args['height_placeholder'] ) ) ? ' placeholder="' . esc_attr( $args['height_placeholder'] ) . '"' : ''; | |
| 58 | + echo '<div class="adminify--input">'; | |
| 59 | + echo ( ! empty( $args['height_icon'] ) ) ? '<span class="adminify--label adminify--icon">' . wp_kses_post( $args['height_icon'] ) . '</span>' : ''; | |
| 60 | + echo '<input type="number" name="' . esc_attr( $this->field_name( '[height]' ) ) . '" value="' . esc_attr( $value['height'] ) . '"' . esc_attr( $placeholder ) . ' class="adminify-input-number' . esc_attr( $is_unit ) . '" step="any" />'; | |
| 61 | + echo ( ! empty( $unit ) ) ? '<span class="adminify--label adminify--unit">' . esc_attr( $args['units'][0] ) . '</span>' : ''; | |
| 62 | + echo '</div>'; | |
| 63 | + } | |
| 53 | 64 | |
| 54 | - if ( ! empty( $args['height'] ) ) { | |
| 55 | - $placeholder = ( ! empty( $args['height_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['height_placeholder'] ) .'"' : ''; | |
| 56 | - echo '<div class="adminify--input">'; | |
| 57 | - echo ( ! empty( $args['height_icon'] ) ) ? '<span class="adminify--label adminify--icon">'. wp_kses_post( $args['height_icon'] ) .'</span>' : ''; | |
| 58 | - echo '<input type="number" name="'. esc_attr( $this->field_name( '[height]' ) ) .'" value="'. esc_attr( $value['height'] ) .'"'. $placeholder .' class="adminify-input-number'. esc_attr( $is_unit ) .'" step="any" />'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- attribute value pre-escaped with esc_attr() where built. | |
| 59 | - echo ( ! empty( $unit ) ) ? '<span class="adminify--label adminify--unit">'. esc_attr( $args['units'][0] ) .'</span>' : ''; | |
| 60 | - echo '</div>'; | |
| 61 | - } | |
| 65 | + if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) { | |
| 66 | + echo '<div class="adminify--input">'; | |
| 67 | + echo '<select name="' . esc_attr( $this->field_name( '[unit]' ) ) . '">'; | |
| 68 | + foreach ( $args['units'] as $unit ) { | |
| 69 | + $selected = ( $value['unit'] === $unit ) ? ' selected' : ''; | |
| 70 | + echo '<option value="' . esc_attr( $unit ) . '"' . esc_attr( $selected ) . '>' . esc_attr( $unit ) . '</option>'; | |
| 71 | + } | |
| 72 | + echo '</select>'; | |
| 73 | + echo '</div>'; | |
| 74 | + } | |
| 62 | 75 | |
| 63 | - if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) { | |
| 64 | - echo '<div class="adminify--input">'; | |
| 65 | - echo '<select name="'. esc_attr( $this->field_name( '[unit]' ) ) .'">'; | |
| 66 | - foreach ( $args['units'] as $unit ) { | |
| 67 | - $selected = ( $value['unit'] === $unit ) ? ' selected' : ''; | |
| 68 | - echo '<option value="'. esc_attr( $unit ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $unit ) .'</option>'; | |
| 69 | - } | |
| 70 | - echo '</select>'; | |
| 71 | - echo '</div>'; | |
| 72 | - } | |
| 76 | + echo '</div>'; | |
| 73 | 77 | |
| 74 | - echo '</div>'; | |
| 78 | + echo wp_kses_post( $this->field_after() ); | |
| 79 | + } | |
| 75 | 80 | |
| 76 | - echo wp_kses_post( $this->field_after() ); | |
| 81 | + public function output() { | |
| 82 | + $output = ''; | |
| 83 | + $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; | |
| 84 | + $prefix = ( ! empty( $this->field['output_prefix'] ) ) ? $this->field['output_prefix'] . '-' : ''; | |
| 85 | + $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; | |
| 86 | + $unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px'; | |
| 87 | + $width = ( isset( $this->value['width'] ) && $this->value['width'] !== '' ) ? $prefix . 'width:' . $this->value['width'] . $unit . $important . ';' : ''; | |
| 88 | + $height = ( isset( $this->value['height'] ) && $this->value['height'] !== '' ) ? $prefix . 'height:' . $this->value['height'] . $unit . $important . ';' : ''; | |
| 77 | 89 | |
| 78 | - } | |
| 90 | + if ( $width !== '' || $height !== '' ) { | |
| 91 | + $output = $element . '{' . $width . $height . '}'; | |
| 92 | + } | |
| 79 | 93 | |
| 80 | - public function output() { | |
| 94 | + $this->parent->output_css .= $output; | |
| 81 | 95 | |
| 82 | - $output = ''; | |
| 83 | - $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; | |
| 84 | - $prefix = ( ! empty( $this->field['output_prefix'] ) ) ? $this->field['output_prefix'] .'-' : ''; | |
| 85 | - $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; | |
| 86 | - $unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px'; | |
| 87 | - $width = ( isset( $this->value['width'] ) && $this->value['width'] !== '' ) ? $prefix .'width:'. $this->value['width'] . $unit . $important .';' : ''; | |
| 88 | - $height = ( isset( $this->value['height'] ) && $this->value['height'] !== '' ) ? $prefix .'height:'. $this->value['height'] . $unit . $important .';' : ''; | |
| 96 | + return $output; | |
| 97 | + } | |
| 89 | 98 | |
| 90 | - if ( $width !== '' || $height !== '' ) { | |
| 91 | - $output = $element .'{'. $width . $height .'}'; | |
| 92 | - } | |
| 93 | - | |
| 94 | - $this->parent->output_css .= $output; | |
| 95 | - | |
| 96 | - return $output; | |
| 97 | - | |
| 98 | - } | |
| 99 | - | |
| 100 | - } | |
| 99 | + } | |
| 101 | 100 | } |