← All changes
|
frameworks/codestar-framework/fields/background/background.php
+340
-340
2.3.4
→
2.4.0
View file →
| @@ -1,340 +1,340 @@ | ||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 2 | -/** | |
| 3 | - * | |
| 4 | - * Field: background | |
| 5 | - * | |
| 6 | - * @since 1.0.0 | |
| 7 | - * @version 1.0.0 | |
| 8 | - * | |
| 9 | - */ | |
| 10 | -if ( ! class_exists( 'CSF_Field_background' ) ) { | |
| 11 | - class CSF_Field_background 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 | - 'background_color' => true, | |
| 21 | - 'background_image' => true, | |
| 22 | - 'background_position' => true, | |
| 23 | - 'background_repeat' => true, | |
| 24 | - 'background_attachment' => true, | |
| 25 | - 'background_size' => true, | |
| 26 | - 'background_origin' => false, | |
| 27 | - 'background_clip' => false, | |
| 28 | - 'background_blend_mode' => false, | |
| 29 | - 'background_gradient' => false, | |
| 30 | - 'background_gradient_color' => true, | |
| 31 | - 'background_gradient_direction' => true, | |
| 32 | - 'background_image_preview' => true, | |
| 33 | - 'background_auto_attributes' => false, | |
| 34 | - 'compact' => false, | |
| 35 | - 'background_image_library' => 'image', | |
| 36 | - 'background_image_placeholder' => esc_html__( 'Not selected', 'csf' ), | |
| 37 | - ) ); | |
| 38 | - | |
| 39 | - if ( $args['compact'] ) { | |
| 40 | - $args['background_color'] = false; | |
| 41 | - $args['background_auto_attributes'] = true; | |
| 42 | - } | |
| 43 | - | |
| 44 | - $default_value = array( | |
| 45 | - 'background-color' => '', | |
| 46 | - 'background-image' => '', | |
| 47 | - 'background-position' => '', | |
| 48 | - 'background-repeat' => '', | |
| 49 | - 'background-attachment' => '', | |
| 50 | - 'background-size' => '', | |
| 51 | - 'background-origin' => '', | |
| 52 | - 'background-clip' => '', | |
| 53 | - 'background-blend-mode' => '', | |
| 54 | - 'background-gradient-color' => '', | |
| 55 | - 'background-gradient-direction' => '', | |
| 56 | - ); | |
| 57 | - | |
| 58 | - $default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value; | |
| 59 | - | |
| 60 | - $this->value = wp_parse_args( $this->value, $default_value ); | |
| 61 | - | |
| 62 | - echo $this->field_before(); | |
| 63 | - | |
| 64 | - echo '<div class="csf--background-colors">'; | |
| 65 | - | |
| 66 | - // | |
| 67 | - // Background Color | |
| 68 | - if ( ! empty( $args['background_color'] ) ) { | |
| 69 | - | |
| 70 | - echo '<div class="csf--color">'; | |
| 71 | - | |
| 72 | - echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf--title">'. esc_html__( 'From', 'csf' ) .'</div>' : ''; | |
| 73 | - | |
| 74 | - CSF::field( array( | |
| 75 | - 'id' => 'background-color', | |
| 76 | - 'type' => 'color', | |
| 77 | - 'default' => $default_value['background-color'], | |
| 78 | - ), $this->value['background-color'], $this->field_name(), 'field/background' ); | |
| 79 | - | |
| 80 | - echo '</div>'; | |
| 81 | - | |
| 82 | - } | |
| 83 | - | |
| 84 | - // | |
| 85 | - // Background Gradient Color | |
| 86 | - if ( ! empty( $args['background_gradient_color'] ) && ! empty( $args['background_gradient'] ) ) { | |
| 87 | - | |
| 88 | - echo '<div class="csf--color">'; | |
| 89 | - | |
| 90 | - echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf--title">'. esc_html__( 'To', 'csf' ) .'</div>' : ''; | |
| 91 | - | |
| 92 | - CSF::field( array( | |
| 93 | - 'id' => 'background-gradient-color', | |
| 94 | - 'type' => 'color', | |
| 95 | - 'default' => $default_value['background-gradient-color'], | |
| 96 | - ), $this->value['background-gradient-color'], $this->field_name(), 'field/background' ); | |
| 97 | - | |
| 98 | - echo '</div>'; | |
| 99 | - | |
| 100 | - } | |
| 101 | - | |
| 102 | - // | |
| 103 | - // Background Gradient Direction | |
| 104 | - if ( ! empty( $args['background_gradient_direction'] ) && ! empty( $args['background_gradient'] ) ) { | |
| 105 | - | |
| 106 | - echo '<div class="csf--color">'; | |
| 107 | - | |
| 108 | - echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf---title">'. esc_html__( 'Direction', 'csf' ) .'</div>' : ''; | |
| 109 | - | |
| 110 | - CSF::field( array( | |
| 111 | - 'id' => 'background-gradient-direction', | |
| 112 | - 'type' => 'select', | |
| 113 | - 'options' => array( | |
| 114 | - '' => esc_html__( 'Gradient Direction', 'csf' ), | |
| 115 | - 'to bottom' => esc_html__( '⇓ top to bottom', 'csf' ), | |
| 116 | - 'to right' => esc_html__( '⇒ left to right', 'csf' ), | |
| 117 | - '135deg' => esc_html__( '⇘ corner top to right', 'csf' ), | |
| 118 | - '-135deg' => esc_html__( '⇙ corner top to left', 'csf' ), | |
| 119 | - ), | |
| 120 | - ), $this->value['background-gradient-direction'], $this->field_name(), 'field/background' ); | |
| 121 | - | |
| 122 | - echo '</div>'; | |
| 123 | - | |
| 124 | - } | |
| 125 | - | |
| 126 | - echo '</div>'; | |
| 127 | - | |
| 128 | - // | |
| 129 | - // Background Image | |
| 130 | - if ( ! empty( $args['background_image'] ) ) { | |
| 131 | - | |
| 132 | - echo '<div class="csf--background-image">'; | |
| 133 | - | |
| 134 | - CSF::field( array( | |
| 135 | - 'id' => 'background-image', | |
| 136 | - 'type' => 'media', | |
| 137 | - 'class' => 'csf-assign-field-background', | |
| 138 | - 'library' => $args['background_image_library'], | |
| 139 | - 'preview' => $args['background_image_preview'], | |
| 140 | - 'placeholder' => $args['background_image_placeholder'], | |
| 141 | - 'attributes' => array( 'data-depend-id' => $this->field['id'] ), | |
| 142 | - ), $this->value['background-image'], $this->field_name(), 'field/background' ); | |
| 143 | - | |
| 144 | - echo '</div>'; | |
| 145 | - | |
| 146 | - } | |
| 147 | - | |
| 148 | - $auto_class = ( ! empty( $args['background_auto_attributes'] ) ) ? ' csf--auto-attributes' : ''; | |
| 149 | - $hidden_class = ( ! empty( $args['background_auto_attributes'] ) && empty( $this->value['background-image']['url'] ) ) ? ' csf--attributes-hidden' : ''; | |
| 150 | - | |
| 151 | - echo '<div class="csf--background-attributes'. esc_attr( $auto_class . $hidden_class ) .'">'; | |
| 152 | - | |
| 153 | - // | |
| 154 | - // Background Position | |
| 155 | - if ( ! empty( $args['background_position'] ) ) { | |
| 156 | - | |
| 157 | - CSF::field( array( | |
| 158 | - 'id' => 'background-position', | |
| 159 | - 'type' => 'select', | |
| 160 | - 'options' => array( | |
| 161 | - '' => esc_html__( 'Background Position', 'csf' ), | |
| 162 | - 'left top' => esc_html__( 'Left Top', 'csf' ), | |
| 163 | - 'left center' => esc_html__( 'Left Center', 'csf' ), | |
| 164 | - 'left bottom' => esc_html__( 'Left Bottom', 'csf' ), | |
| 165 | - 'center top' => esc_html__( 'Center Top', 'csf' ), | |
| 166 | - 'center center' => esc_html__( 'Center Center', 'csf' ), | |
| 167 | - 'center bottom' => esc_html__( 'Center Bottom', 'csf' ), | |
| 168 | - 'right top' => esc_html__( 'Right Top', 'csf' ), | |
| 169 | - 'right center' => esc_html__( 'Right Center', 'csf' ), | |
| 170 | - 'right bottom' => esc_html__( 'Right Bottom', 'csf' ), | |
| 171 | - ), | |
| 172 | - ), $this->value['background-position'], $this->field_name(), 'field/background' ); | |
| 173 | - | |
| 174 | - } | |
| 175 | - | |
| 176 | - // | |
| 177 | - // Background Repeat | |
| 178 | - if ( ! empty( $args['background_repeat'] ) ) { | |
| 179 | - | |
| 180 | - CSF::field( array( | |
| 181 | - 'id' => 'background-repeat', | |
| 182 | - 'type' => 'select', | |
| 183 | - 'options' => array( | |
| 184 | - '' => esc_html__( 'Background Repeat', 'csf' ), | |
| 185 | - 'repeat' => esc_html__( 'Repeat', 'csf' ), | |
| 186 | - 'no-repeat' => esc_html__( 'No Repeat', 'csf' ), | |
| 187 | - 'repeat-x' => esc_html__( 'Repeat Horizontally', 'csf' ), | |
| 188 | - 'repeat-y' => esc_html__( 'Repeat Vertically', 'csf' ), | |
| 189 | - ), | |
| 190 | - ), $this->value['background-repeat'], $this->field_name(), 'field/background' ); | |
| 191 | - | |
| 192 | - } | |
| 193 | - | |
| 194 | - // | |
| 195 | - // Background Attachment | |
| 196 | - if ( ! empty( $args['background_attachment'] ) ) { | |
| 197 | - | |
| 198 | - CSF::field( array( | |
| 199 | - 'id' => 'background-attachment', | |
| 200 | - 'type' => 'select', | |
| 201 | - 'options' => array( | |
| 202 | - '' => esc_html__( 'Background Attachment', 'csf' ), | |
| 203 | - 'scroll' => esc_html__( 'Scroll', 'csf' ), | |
| 204 | - 'fixed' => esc_html__( 'Fixed', 'csf' ), | |
| 205 | - ), | |
| 206 | - ), $this->value['background-attachment'], $this->field_name(), 'field/background' ); | |
| 207 | - | |
| 208 | - } | |
| 209 | - | |
| 210 | - // | |
| 211 | - // Background Size | |
| 212 | - if ( ! empty( $args['background_size'] ) ) { | |
| 213 | - | |
| 214 | - CSF::field( array( | |
| 215 | - 'id' => 'background-size', | |
| 216 | - 'type' => 'select', | |
| 217 | - 'options' => array( | |
| 218 | - '' => esc_html__( 'Background Size', 'csf' ), | |
| 219 | - 'cover' => esc_html__( 'Cover', 'csf' ), | |
| 220 | - 'contain' => esc_html__( 'Contain', 'csf' ), | |
| 221 | - 'auto' => esc_html__( 'Auto', 'csf' ), | |
| 222 | - ), | |
| 223 | - ), $this->value['background-size'], $this->field_name(), 'field/background' ); | |
| 224 | - | |
| 225 | - } | |
| 226 | - | |
| 227 | - // | |
| 228 | - // Background Origin | |
| 229 | - if ( ! empty( $args['background_origin'] ) ) { | |
| 230 | - | |
| 231 | - CSF::field( array( | |
| 232 | - 'id' => 'background-origin', | |
| 233 | - 'type' => 'select', | |
| 234 | - 'options' => array( | |
| 235 | - '' => esc_html__( 'Background Origin', 'csf' ), | |
| 236 | - 'padding-box' => esc_html__( 'Padding Box', 'csf' ), | |
| 237 | - 'border-box' => esc_html__( 'Border Box', 'csf' ), | |
| 238 | - 'content-box' => esc_html__( 'Content Box', 'csf' ), | |
| 239 | - ), | |
| 240 | - ), $this->value['background-origin'], $this->field_name(), 'field/background' ); | |
| 241 | - | |
| 242 | - } | |
| 243 | - | |
| 244 | - // | |
| 245 | - // Background Clip | |
| 246 | - if ( ! empty( $args['background_clip'] ) ) { | |
| 247 | - | |
| 248 | - CSF::field( array( | |
| 249 | - 'id' => 'background-clip', | |
| 250 | - 'type' => 'select', | |
| 251 | - 'options' => array( | |
| 252 | - '' => esc_html__( 'Background Clip', 'csf' ), | |
| 253 | - 'border-box' => esc_html__( 'Border Box', 'csf' ), | |
| 254 | - 'padding-box' => esc_html__( 'Padding Box', 'csf' ), | |
| 255 | - 'content-box' => esc_html__( 'Content Box', 'csf' ), | |
| 256 | - ), | |
| 257 | - ), $this->value['background-clip'], $this->field_name(), 'field/background' ); | |
| 258 | - | |
| 259 | - } | |
| 260 | - | |
| 261 | - // | |
| 262 | - // Background Blend Mode | |
| 263 | - if ( ! empty( $args['background_blend_mode'] ) ) { | |
| 264 | - | |
| 265 | - CSF::field( array( | |
| 266 | - 'id' => 'background-blend-mode', | |
| 267 | - 'type' => 'select', | |
| 268 | - 'options' => array( | |
| 269 | - '' => esc_html__( 'Background Blend Mode', 'csf' ), | |
| 270 | - 'normal' => esc_html__( 'Normal', 'csf' ), | |
| 271 | - 'multiply' => esc_html__( 'Multiply', 'csf' ), | |
| 272 | - 'screen' => esc_html__( 'Screen', 'csf' ), | |
| 273 | - 'overlay' => esc_html__( 'Overlay', 'csf' ), | |
| 274 | - 'darken' => esc_html__( 'Darken', 'csf' ), | |
| 275 | - 'lighten' => esc_html__( 'Lighten', 'csf' ), | |
| 276 | - 'color-dodge' => esc_html__( 'Color Dodge', 'csf' ), | |
| 277 | - 'saturation' => esc_html__( 'Saturation', 'csf' ), | |
| 278 | - 'color' => esc_html__( 'Color', 'csf' ), | |
| 279 | - 'luminosity' => esc_html__( 'Luminosity', 'csf' ), | |
| 280 | - ), | |
| 281 | - ), $this->value['background-blend-mode'], $this->field_name(), 'field/background' ); | |
| 282 | - | |
| 283 | - } | |
| 284 | - | |
| 285 | - echo '</div>'; | |
| 286 | - | |
| 287 | - echo $this->field_after(); | |
| 288 | - | |
| 289 | - } | |
| 290 | - | |
| 291 | - public function output() { | |
| 292 | - | |
| 293 | - $output = ''; | |
| 294 | - $bg_image = array(); | |
| 295 | - $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; | |
| 296 | - $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; | |
| 297 | - | |
| 298 | - // Background image and gradient | |
| 299 | - $background_color = ( ! empty( $this->value['background-color'] ) ) ? $this->value['background-color'] : ''; | |
| 300 | - $background_gd_color = ( ! empty( $this->value['background-gradient-color'] ) ) ? $this->value['background-gradient-color'] : ''; | |
| 301 | - $background_gd_direction = ( ! empty( $this->value['background-gradient-direction'] ) ) ? $this->value['background-gradient-direction'] : ''; | |
| 302 | - $background_image = ( ! empty( $this->value['background-image']['url'] ) ) ? $this->value['background-image']['url'] : ''; | |
| 303 | - | |
| 304 | - | |
| 305 | - if ( $background_color && $background_gd_color ) { | |
| 306 | - $gd_direction = ( $background_gd_direction ) ? $background_gd_direction .',' : ''; | |
| 307 | - $bg_image[] = 'linear-gradient('. $gd_direction . $background_color .','. $background_gd_color .')'; | |
| 308 | - unset( $this->value['background-color'] ); | |
| 309 | - } | |
| 310 | - | |
| 311 | - if ( $background_image ) { | |
| 312 | - $bg_image[] = 'url('. $background_image .')'; | |
| 313 | - } | |
| 314 | - | |
| 315 | - if ( ! empty( $bg_image ) ) { | |
| 316 | - $output .= 'background-image:'. implode( ',', $bg_image ) . $important .';'; | |
| 317 | - } | |
| 318 | - | |
| 319 | - // Common background properties | |
| 320 | - $properties = array( 'color', 'position', 'repeat', 'attachment', 'size', 'origin', 'clip', 'blend-mode' ); | |
| 321 | - | |
| 322 | - foreach ( $properties as $property ) { | |
| 323 | - $property = 'background-'. $property; | |
| 324 | - if ( ! empty( $this->value[$property] ) ) { | |
| 325 | - $output .= $property .':'. $this->value[$property] . $important .';'; | |
| 326 | - } | |
| 327 | - } | |
| 328 | - | |
| 329 | - if ( $output ) { | |
| 330 | - $output = $element .'{'. $output .'}'; | |
| 331 | - } | |
| 332 | - | |
| 333 | - $this->parent->output_css .= $output; | |
| 334 | - | |
| 335 | - return $output; | |
| 336 | - | |
| 337 | - } | |
| 338 | - | |
| 339 | - } | |
| 340 | -} | |
| 1 | +<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 2 | +/** | |
| 3 | + * | |
| 4 | + * Field: background | |
| 5 | + * | |
| 6 | + * @since 1.0.0 | |
| 7 | + * @version 1.0.0 | |
| 8 | + * | |
| 9 | + */ | |
| 10 | +if ( ! class_exists( 'CSF_Field_background' ) ) { | |
| 11 | + class CSF_Field_background 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 | + 'background_color' => true, | |
| 21 | + 'background_image' => true, | |
| 22 | + 'background_position' => true, | |
| 23 | + 'background_repeat' => true, | |
| 24 | + 'background_attachment' => true, | |
| 25 | + 'background_size' => true, | |
| 26 | + 'background_origin' => false, | |
| 27 | + 'background_clip' => false, | |
| 28 | + 'background_blend_mode' => false, | |
| 29 | + 'background_gradient' => false, | |
| 30 | + 'background_gradient_color' => true, | |
| 31 | + 'background_gradient_direction' => true, | |
| 32 | + 'background_image_preview' => true, | |
| 33 | + 'background_auto_attributes' => false, | |
| 34 | + 'compact' => false, | |
| 35 | + 'background_image_library' => 'image', | |
| 36 | + 'background_image_placeholder' => esc_html__( 'Not selected', 'streamcast' ), | |
| 37 | + ) ); | |
| 38 | + | |
| 39 | + if ( $args['compact'] ) { | |
| 40 | + $args['background_color'] = false; | |
| 41 | + $args['background_auto_attributes'] = true; | |
| 42 | + } | |
| 43 | + | |
| 44 | + $default_value = array( | |
| 45 | + 'background-color' => '', | |
| 46 | + 'background-image' => '', | |
| 47 | + 'background-position' => '', | |
| 48 | + 'background-repeat' => '', | |
| 49 | + 'background-attachment' => '', | |
| 50 | + 'background-size' => '', | |
| 51 | + 'background-origin' => '', | |
| 52 | + 'background-clip' => '', | |
| 53 | + 'background-blend-mode' => '', | |
| 54 | + 'background-gradient-color' => '', | |
| 55 | + 'background-gradient-direction' => '', | |
| 56 | + ); | |
| 57 | + | |
| 58 | + $default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value; | |
| 59 | + | |
| 60 | + $this->value = wp_parse_args( $this->value, $default_value ); | |
| 61 | + | |
| 62 | + echo $this->field_before(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 63 | + | |
| 64 | + echo '<div class="csf--background-colors">'; | |
| 65 | + | |
| 66 | + // | |
| 67 | + // Background Color | |
| 68 | + if ( ! empty( $args['background_color'] ) ) { | |
| 69 | + | |
| 70 | + echo '<div class="csf--color">'; | |
| 71 | + | |
| 72 | + echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf--title">'. esc_html__( 'From', 'streamcast' ) .'</div>' : ''; | |
| 73 | + | |
| 74 | + CSF::field( array( | |
| 75 | + 'id' => 'background-color', | |
| 76 | + 'type' => 'color', | |
| 77 | + 'default' => $default_value['background-color'], | |
| 78 | + ), $this->value['background-color'], $this->field_name(), 'field/background' ); | |
| 79 | + | |
| 80 | + echo '</div>'; | |
| 81 | + | |
| 82 | + } | |
| 83 | + | |
| 84 | + // | |
| 85 | + // Background Gradient Color | |
| 86 | + if ( ! empty( $args['background_gradient_color'] ) && ! empty( $args['background_gradient'] ) ) { | |
| 87 | + | |
| 88 | + echo '<div class="csf--color">'; | |
| 89 | + | |
| 90 | + echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf--title">'. esc_html__( 'To', 'streamcast' ) .'</div>' : ''; | |
| 91 | + | |
| 92 | + CSF::field( array( | |
| 93 | + 'id' => 'background-gradient-color', | |
| 94 | + 'type' => 'color', | |
| 95 | + 'default' => $default_value['background-gradient-color'], | |
| 96 | + ), $this->value['background-gradient-color'], $this->field_name(), 'field/background' ); | |
| 97 | + | |
| 98 | + echo '</div>'; | |
| 99 | + | |
| 100 | + } | |
| 101 | + | |
| 102 | + // | |
| 103 | + // Background Gradient Direction | |
| 104 | + if ( ! empty( $args['background_gradient_direction'] ) && ! empty( $args['background_gradient'] ) ) { | |
| 105 | + | |
| 106 | + echo '<div class="csf--color">'; | |
| 107 | + | |
| 108 | + echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="csf---title">'. esc_html__( 'Direction', 'streamcast' ) .'</div>' : ''; | |
| 109 | + | |
| 110 | + CSF::field( array( | |
| 111 | + 'id' => 'background-gradient-direction', | |
| 112 | + 'type' => 'select', | |
| 113 | + 'options' => array( | |
| 114 | + '' => esc_html__( 'Gradient Direction', 'streamcast' ), | |
| 115 | + 'to bottom' => esc_html__( '⇓ top to bottom', 'streamcast' ), | |
| 116 | + 'to right' => esc_html__( '⇒ left to right', 'streamcast' ), | |
| 117 | + '135deg' => esc_html__( '⇘ corner top to right', 'streamcast' ), | |
| 118 | + '-135deg' => esc_html__( '⇙ corner top to left', 'streamcast' ), | |
| 119 | + ), | |
| 120 | + ), $this->value['background-gradient-direction'], $this->field_name(), 'field/background' ); | |
| 121 | + | |
| 122 | + echo '</div>'; | |
| 123 | + | |
| 124 | + } | |
| 125 | + | |
| 126 | + echo '</div>'; | |
| 127 | + | |
| 128 | + // | |
| 129 | + // Background Image | |
| 130 | + if ( ! empty( $args['background_image'] ) ) { | |
| 131 | + | |
| 132 | + echo '<div class="csf--background-image">'; | |
| 133 | + | |
| 134 | + CSF::field( array( | |
| 135 | + 'id' => 'background-image', | |
| 136 | + 'type' => 'media', | |
| 137 | + 'class' => 'csf-assign-field-background', | |
| 138 | + 'library' => $args['background_image_library'], | |
| 139 | + 'preview' => $args['background_image_preview'], | |
| 140 | + 'placeholder' => $args['background_image_placeholder'], | |
| 141 | + 'attributes' => array( 'data-depend-id' => $this->field['id'] ), | |
| 142 | + ), $this->value['background-image'], $this->field_name(), 'field/background' ); | |
| 143 | + | |
| 144 | + echo '</div>'; | |
| 145 | + | |
| 146 | + } | |
| 147 | + | |
| 148 | + $auto_class = ( ! empty( $args['background_auto_attributes'] ) ) ? ' csf--auto-attributes' : ''; | |
| 149 | + $hidden_class = ( ! empty( $args['background_auto_attributes'] ) && empty( $this->value['background-image']['url'] ) ) ? ' csf--attributes-hidden' : ''; | |
| 150 | + | |
| 151 | + echo '<div class="csf--background-attributes'. esc_attr( $auto_class . $hidden_class ) .'">'; | |
| 152 | + | |
| 153 | + // | |
| 154 | + // Background Position | |
| 155 | + if ( ! empty( $args['background_position'] ) ) { | |
| 156 | + | |
| 157 | + CSF::field( array( | |
| 158 | + 'id' => 'background-position', | |
| 159 | + 'type' => 'select', | |
| 160 | + 'options' => array( | |
| 161 | + '' => esc_html__( 'Background Position', 'streamcast' ), | |
| 162 | + 'left top' => esc_html__( 'Left Top', 'streamcast' ), | |
| 163 | + 'left center' => esc_html__( 'Left Center', 'streamcast' ), | |
| 164 | + 'left bottom' => esc_html__( 'Left Bottom', 'streamcast' ), | |
| 165 | + 'center top' => esc_html__( 'Center Top', 'streamcast' ), | |
| 166 | + 'center center' => esc_html__( 'Center Center', 'streamcast' ), | |
| 167 | + 'center bottom' => esc_html__( 'Center Bottom', 'streamcast' ), | |
| 168 | + 'right top' => esc_html__( 'Right Top', 'streamcast' ), | |
| 169 | + 'right center' => esc_html__( 'Right Center', 'streamcast' ), | |
| 170 | + 'right bottom' => esc_html__( 'Right Bottom', 'streamcast' ), | |
| 171 | + ), | |
| 172 | + ), $this->value['background-position'], $this->field_name(), 'field/background' ); | |
| 173 | + | |
| 174 | + } | |
| 175 | + | |
| 176 | + // | |
| 177 | + // Background Repeat | |
| 178 | + if ( ! empty( $args['background_repeat'] ) ) { | |
| 179 | + | |
| 180 | + CSF::field( array( | |
| 181 | + 'id' => 'background-repeat', | |
| 182 | + 'type' => 'select', | |
| 183 | + 'options' => array( | |
| 184 | + '' => esc_html__( 'Background Repeat', 'streamcast' ), | |
| 185 | + 'repeat' => esc_html__( 'Repeat', 'streamcast' ), | |
| 186 | + 'no-repeat' => esc_html__( 'No Repeat', 'streamcast' ), | |
| 187 | + 'repeat-x' => esc_html__( 'Repeat Horizontally', 'streamcast' ), | |
| 188 | + 'repeat-y' => esc_html__( 'Repeat Vertically', 'streamcast' ), | |
| 189 | + ), | |
| 190 | + ), $this->value['background-repeat'], $this->field_name(), 'field/background' ); | |
| 191 | + | |
| 192 | + } | |
| 193 | + | |
| 194 | + // | |
| 195 | + // Background Attachment | |
| 196 | + if ( ! empty( $args['background_attachment'] ) ) { | |
| 197 | + | |
| 198 | + CSF::field( array( | |
| 199 | + 'id' => 'background-attachment', | |
| 200 | + 'type' => 'select', | |
| 201 | + 'options' => array( | |
| 202 | + '' => esc_html__( 'Background Attachment', 'streamcast' ), | |
| 203 | + 'scroll' => esc_html__( 'Scroll', 'streamcast' ), | |
| 204 | + 'fixed' => esc_html__( 'Fixed', 'streamcast' ), | |
| 205 | + ), | |
| 206 | + ), $this->value['background-attachment'], $this->field_name(), 'field/background' ); | |
| 207 | + | |
| 208 | + } | |
| 209 | + | |
| 210 | + // | |
| 211 | + // Background Size | |
| 212 | + if ( ! empty( $args['background_size'] ) ) { | |
| 213 | + | |
| 214 | + CSF::field( array( | |
| 215 | + 'id' => 'background-size', | |
| 216 | + 'type' => 'select', | |
| 217 | + 'options' => array( | |
| 218 | + '' => esc_html__( 'Background Size', 'streamcast' ), | |
| 219 | + 'cover' => esc_html__( 'Cover', 'streamcast' ), | |
| 220 | + 'contain' => esc_html__( 'Contain', 'streamcast' ), | |
| 221 | + 'auto' => esc_html__( 'Auto', 'streamcast' ), | |
| 222 | + ), | |
| 223 | + ), $this->value['background-size'], $this->field_name(), 'field/background' ); | |
| 224 | + | |
| 225 | + } | |
| 226 | + | |
| 227 | + // | |
| 228 | + // Background Origin | |
| 229 | + if ( ! empty( $args['background_origin'] ) ) { | |
| 230 | + | |
| 231 | + CSF::field( array( | |
| 232 | + 'id' => 'background-origin', | |
| 233 | + 'type' => 'select', | |
| 234 | + 'options' => array( | |
| 235 | + '' => esc_html__( 'Background Origin', 'streamcast' ), | |
| 236 | + 'padding-box' => esc_html__( 'Padding Box', 'streamcast' ), | |
| 237 | + 'border-box' => esc_html__( 'Border Box', 'streamcast' ), | |
| 238 | + 'content-box' => esc_html__( 'Content Box', 'streamcast' ), | |
| 239 | + ), | |
| 240 | + ), $this->value['background-origin'], $this->field_name(), 'field/background' ); | |
| 241 | + | |
| 242 | + } | |
| 243 | + | |
| 244 | + // | |
| 245 | + // Background Clip | |
| 246 | + if ( ! empty( $args['background_clip'] ) ) { | |
| 247 | + | |
| 248 | + CSF::field( array( | |
| 249 | + 'id' => 'background-clip', | |
| 250 | + 'type' => 'select', | |
| 251 | + 'options' => array( | |
| 252 | + '' => esc_html__( 'Background Clip', 'streamcast' ), | |
| 253 | + 'border-box' => esc_html__( 'Border Box', 'streamcast' ), | |
| 254 | + 'padding-box' => esc_html__( 'Padding Box', 'streamcast' ), | |
| 255 | + 'content-box' => esc_html__( 'Content Box', 'streamcast' ), | |
| 256 | + ), | |
| 257 | + ), $this->value['background-clip'], $this->field_name(), 'field/background' ); | |
| 258 | + | |
| 259 | + } | |
| 260 | + | |
| 261 | + // | |
| 262 | + // Background Blend Mode | |
| 263 | + if ( ! empty( $args['background_blend_mode'] ) ) { | |
| 264 | + | |
| 265 | + CSF::field( array( | |
| 266 | + 'id' => 'background-blend-mode', | |
| 267 | + 'type' => 'select', | |
| 268 | + 'options' => array( | |
| 269 | + '' => esc_html__( 'Background Blend Mode', 'streamcast' ), | |
| 270 | + 'normal' => esc_html__( 'Normal', 'streamcast' ), | |
| 271 | + 'multiply' => esc_html__( 'Multiply', 'streamcast' ), | |
| 272 | + 'screen' => esc_html__( 'Screen', 'streamcast' ), | |
| 273 | + 'overlay' => esc_html__( 'Overlay', 'streamcast' ), | |
| 274 | + 'darken' => esc_html__( 'Darken', 'streamcast' ), | |
| 275 | + 'lighten' => esc_html__( 'Lighten', 'streamcast' ), | |
| 276 | + 'color-dodge' => esc_html__( 'Color Dodge', 'streamcast' ), | |
| 277 | + 'saturation' => esc_html__( 'Saturation', 'streamcast' ), | |
| 278 | + 'color' => esc_html__( 'Color', 'streamcast' ), | |
| 279 | + 'luminosity' => esc_html__( 'Luminosity', 'streamcast' ), | |
| 280 | + ), | |
| 281 | + ), $this->value['background-blend-mode'], $this->field_name(), 'field/background' ); | |
| 282 | + | |
| 283 | + } | |
| 284 | + | |
| 285 | + echo '</div>'; | |
| 286 | + | |
| 287 | + echo $this->field_after(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 288 | + | |
| 289 | + } | |
| 290 | + | |
| 291 | + public function output() { | |
| 292 | + | |
| 293 | + $output = ''; | |
| 294 | + $bg_image = array(); | |
| 295 | + $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; | |
| 296 | + $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; | |
| 297 | + | |
| 298 | + // Background image and gradient | |
| 299 | + $background_color = ( ! empty( $this->value['background-color'] ) ) ? $this->value['background-color'] : ''; | |
| 300 | + $background_gd_color = ( ! empty( $this->value['background-gradient-color'] ) ) ? $this->value['background-gradient-color'] : ''; | |
| 301 | + $background_gd_direction = ( ! empty( $this->value['background-gradient-direction'] ) ) ? $this->value['background-gradient-direction'] : ''; | |
| 302 | + $background_image = ( ! empty( $this->value['background-image']['url'] ) ) ? $this->value['background-image']['url'] : ''; | |
| 303 | + | |
| 304 | + | |
| 305 | + if ( $background_color && $background_gd_color ) { | |
| 306 | + $gd_direction = ( $background_gd_direction ) ? $background_gd_direction .',' : ''; | |
| 307 | + $bg_image[] = 'linear-gradient('. $gd_direction . $background_color .','. $background_gd_color .')'; | |
| 308 | + unset( $this->value['background-color'] ); | |
| 309 | + } | |
| 310 | + | |
| 311 | + if ( $background_image ) { | |
| 312 | + $bg_image[] = 'url('. $background_image .')'; | |
| 313 | + } | |
| 314 | + | |
| 315 | + if ( ! empty( $bg_image ) ) { | |
| 316 | + $output .= 'background-image:'. implode( ',', $bg_image ) . $important .';'; | |
| 317 | + } | |
| 318 | + | |
| 319 | + // Common background properties | |
| 320 | + $properties = array( 'color', 'position', 'repeat', 'attachment', 'size', 'origin', 'clip', 'blend-mode' ); | |
| 321 | + | |
| 322 | + foreach ( $properties as $property ) { | |
| 323 | + $property = 'background-'. $property; | |
| 324 | + if ( ! empty( $this->value[$property] ) ) { | |
| 325 | + $output .= $property .':'. $this->value[$property] . $important .';'; | |
| 326 | + } | |
| 327 | + } | |
| 328 | + | |
| 329 | + if ( $output ) { | |
| 330 | + $output = $element .'{'. $output .'}'; | |
| 331 | + } | |
| 332 | + | |
| 333 | + $this->parent->output_css .= $output; | |
| 334 | + | |
| 335 | + return $output; | |
| 336 | + | |
| 337 | + } | |
| 338 | + | |
| 339 | + } | |
| 340 | +} | |