'' ); 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 '
'; echo ''; echo ''; echo ''; echo '
'; //Upload controls DIV echo '
'; //If the user has WP3.5+ show upload/remove button echo '' . __( 'Upload', 'customify' ) . ''; $hide = ''; if ( empty( $this->value['background-image'] ) || $this->value['background-image'] == '' ) { $hide = ' hide'; } echo '' . __( 'Remove', 'customify' ) . ''; echo '
'; } if ( $this->field['background-repeat'] === true ) { $array = array( 'no-repeat' => 'No Repeat', 'repeat' => 'Repeat All', 'repeat-x' => 'Repeat Horizontally', 'repeat-y' => 'Repeat Vertically', 'inherit' => 'Inherit', ); if ( ! isset( $this->value['background-repeat'] ) ) { $this->value['background-repeat'] = ''; } echo ''; } if ( $this->field['background-clip'] === true ) { $array = array( 'inherit' => 'Inherit', 'border-box' => 'Border Box', 'content-box' => 'Content Box', 'padding-box' => 'Padding Box', ); if ( ! isset( $this->value['background-clip'] ) ) { $this->value['background-clip'] = ''; } echo ''; } if ( $this->field['background-origin'] === true ) { $array = array( 'inherit' => 'Inherit', 'border-box' => 'Border Box', 'content-box' => 'Content Box', 'padding-box' => 'Padding Box', ); if ( ! isset( $this->value['background-origin'] ) ) { $this->value['background-origin'] = ''; } echo ''; } if ( $this->field['background-size'] === true ) { $array = array( 'inherit' => 'Inherit', 'cover' => 'Cover', 'contain' => 'Contain', ); if ( ! isset( $this->value['background-size'] ) ) { $this->value['background-size'] = ''; } echo ''; } if ( $this->field['background-attachment'] === true ) { $array = array( 'fixed' => 'Fixed', 'scroll' => 'Scroll', 'inherit' => 'Inherit', ); if ( ! isset( $this->value['background-attachment'] ) ) { $this->value['background-attachment'] = ''; } echo ''; } if ( $this->field['background-position'] === true ) { $array = array( 'left top' => 'Left Top', 'left center' => 'Left center', 'left bottom' => 'Left Bottom', 'center top' => 'Center Top', 'center center' => 'Center Center', 'center bottom' => 'Center Bottom', 'right top' => 'Right Top', 'right center' => 'Right center', 'right bottom' => 'Right Bottom', ); if ( ! isset( $this->value['background-position'] ) ) { $this->value['background-position'] = ''; } echo ''; } } static function css_output() { } }