'' ); public $field_defaults = array( 'background-color' => true, 'background-repeat' => true, 'background-attachment' => true, 'background-position' => true, 'background-image' => true, 'background-gradient' => false, 'background-clip' => false, 'background-origin' => false, 'background-size' => true, 'preview_media' => true, 'preview' => true, 'preview_height' => '200px', 'transparent' => true, ); /** * Render the control's content. * * @since 3.4.0 */ public function render_content() { // ensure some values $this->value = $this->value(); $this->field = array_merge( $this->field, $this->field_defaults ); if ( $this->field['background-image'] === true ) { // NO defaults for now // if ( empty( $this->value ) && ! empty( $this->field['default'] ) ) { // If there are standard values and value is empty // if ( is_array( $this->field['default'] ) ) { // if ( ! empty( $this->field['default']['media']['id'] ) ) { // $this->value['media']['id'] = $this->field['default']['media']['id']; // } else if ( ! empty( $this->field['default']['id'] ) ) { // $this->value['media']['id'] = $this->field['default']['id']; // } // // if ( ! empty( $this->field['default']['url'] ) ) { // $this->value['background-image'] = $this->field['default']['url']; // } else if ( ! empty( $this->field['default']['media']['url'] ) ) { // $this->value['background-image'] = $this->field['default']['media']['url']; // } else if ( ! empty( $this->field['default']['background-image'] ) ) { // $this->value['background-image'] = $this->field['default']['background-image']; // } // // } else { // if ( is_numeric( $this->field['default'] ) ) { // Check if it's an attachment ID // $this->value['media']['id'] = $this->field['default']; // } else { // Must be a URL // $this->value['background-image'] = $this->field['default']; // } // } // } if ( empty( $this->value['background-image'] ) && ! empty( $this->value['media']['id'] ) ) { $img = wp_get_attachment_image_src( $this->value['media']['id'], 'full' ); $this->value['background-image'] = $img[0]; $this->value['media']['width'] = $img[1]; $this->value['media']['height'] = $img[2]; } if ( ! is_array( $this->value ) || ! isset( $this->value['media'] ) || empty( $this->value['media'] ) ) { $this->value = array(); $media_array = array( 'id' => '', 'height' => '', 'width' => '', 'thumbnail' => '' ); $this->value['media'] = $media_array; } $hide = 'hide '; if ( ( isset( $this->field['preview_media'] ) && $this->field['preview_media'] === false ) ) { $this->field['class'] .= " noPreview"; } if ( ( ! empty( $this->field['background-image'] ) && $this->field['background-image'] === true ) || isset( $this->field['preview'] ) && $this->field['preview'] === false ) { $hide = ''; } $placeholder = isset( $this->field['placeholder'] ) ? $this->field['placeholder'] : __( 'No media selected', 'customify' ); if ( ! isset( $this->value['background-image'] ) ) { $this->value['background-image'] = ''; } echo ''; echo ''; echo ''; echo ''; echo ''; //Preview $hide = ''; if ( ( isset( $this->field['preview_media'] ) && $this->field['preview_media'] === false ) || empty( $this->value['background-image'] ) ) { $hide = 'hide '; } if ( empty( $this->value['media']['thumbnail'] ) && ! empty( $this->value['background-image'] ) ) { // Just in case if ( ! empty( $this->value['media']['id'] ) ) { $image = wp_get_attachment_image_src( $this->value['media']['id'], array( 150 ) ); $this->value['media']['thumbnail'] = $image[0]; } else { $this->value['media']['thumbnail'] = $this->value['background-image']; } } echo '