← All changes
|
frameworks/codestar-framework/fields/image_select/image_select.php
+79
-79
2.3.4
→
2.4.0
View file →
| @@ -1,79 +1,79 @@ | ||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 2 | -/** | |
| 3 | - * | |
| 4 | - * Field: image_select | |
| 5 | - * | |
| 6 | - * @since 1.0.0 | |
| 7 | - * @version 1.0.0 | |
| 8 | - * | |
| 9 | - */ | |
| 10 | -if ( ! class_exists( 'CSF_Field_image_select' ) ) { | |
| 11 | - class CSF_Field_image_select extends CSF_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 | - 'multiple' => false, | |
| 21 | - 'inline' => false, | |
| 22 | - 'options' => array(), | |
| 23 | - ) ); | |
| 24 | - | |
| 25 | - $inline = ( $args['inline'] ) ? ' csf--inline-list' : ''; | |
| 26 | - | |
| 27 | - $value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); | |
| 28 | - | |
| 29 | - echo $this->field_before(); | |
| 30 | - | |
| 31 | - if ( ! empty( $args['options'] ) ) { | |
| 32 | - | |
| 33 | - echo '<div class="csf-siblings csf--image-group'. esc_attr( $inline ) .'" data-multiple="'. esc_attr( $args['multiple'] ) .'">'; | |
| 34 | - | |
| 35 | - $num = 1; | |
| 36 | - | |
| 37 | - foreach ( $args['options'] as $key => $option ) { | |
| 38 | - | |
| 39 | - $type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; | |
| 40 | - $extra = ( $args['multiple'] ) ? '[]' : ''; | |
| 41 | - $active = ( in_array( $key, $value ) ) ? ' csf--active' : ''; | |
| 42 | - $checked = ( in_array( $key, $value ) ) ? ' checked' : ''; | |
| 43 | - | |
| 44 | - echo '<div class="csf--sibling csf--image'. esc_attr( $active ) .'">'; | |
| 45 | - echo '<figure>'; | |
| 46 | - echo '<img src="'. esc_url( $option ) .'" alt="img-'. esc_attr( $num++ ) .'" />'; | |
| 47 | - echo '<input type="'. esc_attr( $type ) .'" name="'. esc_attr( $this->field_name( $extra ) ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>'; | |
| 48 | - echo '</figure>'; | |
| 49 | - echo '</div>'; | |
| 50 | - | |
| 51 | - } | |
| 52 | - | |
| 53 | - echo '</div>'; | |
| 54 | - | |
| 55 | - } | |
| 56 | - | |
| 57 | - echo $this->field_after(); | |
| 58 | - | |
| 59 | - } | |
| 60 | - | |
| 61 | - public function output() { | |
| 62 | - | |
| 63 | - $output = ''; | |
| 64 | - $bg_image = array(); | |
| 65 | - $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; | |
| 66 | - $elements = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; | |
| 67 | - | |
| 68 | - if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) { | |
| 69 | - $output = $elements .'{background-image:url('. $this->value .')'. $important .';}'; | |
| 70 | - } | |
| 71 | - | |
| 72 | - $this->parent->output_css .= $output; | |
| 73 | - | |
| 74 | - return $output; | |
| 75 | - | |
| 76 | - } | |
| 77 | - | |
| 78 | - } | |
| 79 | -} | |
| 1 | +<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 2 | +/** | |
| 3 | + * | |
| 4 | + * Field: image_select | |
| 5 | + * | |
| 6 | + * @since 1.0.0 | |
| 7 | + * @version 1.0.0 | |
| 8 | + * | |
| 9 | + */ | |
| 10 | +if ( ! class_exists( 'CSF_Field_image_select' ) ) { | |
| 11 | + class CSF_Field_image_select extends CSF_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 | + 'multiple' => false, | |
| 21 | + 'inline' => false, | |
| 22 | + 'options' => array(), | |
| 23 | + ) ); | |
| 24 | + | |
| 25 | + $inline = ( $args['inline'] ) ? ' csf--inline-list' : ''; | |
| 26 | + | |
| 27 | + $value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); | |
| 28 | + | |
| 29 | + echo $this->field_before(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 30 | + | |
| 31 | + if ( ! empty( $args['options'] ) ) { | |
| 32 | + | |
| 33 | + echo '<div class="csf-siblings csf--image-group'. esc_attr( $inline ) .'" data-multiple="'. esc_attr( $args['multiple'] ) .'">'; | |
| 34 | + | |
| 35 | + $num = 1; | |
| 36 | + | |
| 37 | + foreach ( $args['options'] as $key => $option ) { | |
| 38 | + | |
| 39 | + $type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; | |
| 40 | + $extra = ( $args['multiple'] ) ? '[]' : ''; | |
| 41 | + $active = ( in_array( $key, $value ) ) ? ' csf--active' : ''; | |
| 42 | + $checked = ( in_array( $key, $value ) ) ? ' checked' : ''; | |
| 43 | + | |
| 44 | + echo '<div class="csf--sibling csf--image'. esc_attr( $active ) .'">'; | |
| 45 | + echo '<figure>'; | |
| 46 | + echo '<img src="'. esc_url( $option ) .'" alt="img-'. esc_attr( $num++ ) .'" />'; | |
| 47 | + echo '<input type="'. esc_attr( $type ) .'" name="'. esc_attr( $this->field_name( $extra ) ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 48 | + echo '</figure>'; | |
| 49 | + echo '</div>'; | |
| 50 | + | |
| 51 | + } | |
| 52 | + | |
| 53 | + echo '</div>'; | |
| 54 | + | |
| 55 | + } | |
| 56 | + | |
| 57 | + echo $this->field_after(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 58 | + | |
| 59 | + } | |
| 60 | + | |
| 61 | + public function output() { | |
| 62 | + | |
| 63 | + $output = ''; | |
| 64 | + $bg_image = array(); | |
| 65 | + $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; | |
| 66 | + $elements = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; | |
| 67 | + | |
| 68 | + if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) { | |
| 69 | + $output = $elements .'{background-image:url('. $this->value .')'. $important .';}'; | |
| 70 | + } | |
| 71 | + | |
| 72 | + $this->parent->output_css .= $output; | |
| 73 | + | |
| 74 | + return $output; | |
| 75 | + | |
| 76 | + } | |
| 77 | + | |
| 78 | + } | |
| 79 | +} | |