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