-
- tabs as $id => $tab ): ?>
- -
-
-
-
-
- tabs as $id => $tab ): ?>
-
-
+
+
+
+
+
+ <# } else { #>
+
+
+
+
+
+ button_labels['placeholder']; ?>
+
+
-
+
-
-
+ <# if ( data.defaultAttachment ) { #>
+
+ <# } #>
+
+
-
+ <# } #>
tabs[ $id ] = array(
- 'label' => $label,
- 'callback' => $callback,
- );
+ public function to_json() {
+ parent::to_json();
+
+ $value = $this->value();
+ if ( $value ) {
+ // Get the attachment model for the existing file.
+ $attachment_id = attachment_url_to_postid( $value );
+ if ( $attachment_id ) {
+ $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id );
+ }
+ }
}
+}
+
+/**
+ * Customize Image Control class.
+ *
+ * @since 3.4.0
+ *
+ * @see WP_Customize_Upload_Control
+ */
+class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
+ public $type = 'image';
+ public $mime_type = 'image';
/**
- * Remove a tab from the control.
+ * Constructor.
*
* @since 3.4.0
+ * @uses WP_Customize_Upload_Control::__construct()
*
+ * @param WP_Customize_Manager $manager
* @param string $id
+ * @param array $args
*/
- public function remove_tab( $id ) {
- unset( $this->tabs[ $id ] );
+ public function __construct( $manager, $id, $args = array() ) {
+ parent::__construct( $manager, $id, $args );
+
+ $this->button_labels = array(
+ 'select' => __( 'Select Image' ),
+ 'change' => __( 'Change Image' ),
+ 'remove' => __( 'Remove' ),
+ 'default' => __( 'Default' ),
+ 'placeholder' => __( 'No image selected' ),
+ 'frame_title' => __( 'Select Image' ),
+ 'frame_button' => __( 'Choose Image' ),
+ );
}
+ /**
+ * @since 3.4.2
+ * @deprecated 4.1.0
+ */
+ public function prepare_control() {}
+
/**
* @since 3.4.0
+ * @deprecated 4.1.0
+ *
+ * @param string $id
+ * @param string $label
+ * @param mixed $callback
*/
- public function tab_upload_new() {
- if ( ! _device_can_upload() ) {
- echo '
' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the native app for your device instead.'), 'https://wordpress.org/mobile/' ) . '
';
- } else {
- ?>
-
- select a file.'); ?>
-
-
-
-
-
-
-
-
-
-
- __( 'Background Image' ),
'section' => 'background_image',
- 'context' => 'custom-background',
- 'get_url' => 'get_background_image',
) );
-
- if ( $this->setting->default )
- $this->add_tab( 'default', __('Default'), array( $this, 'tab_default_background' ) );
}
/**
- * @since 3.4.0
+ * Enqueue control related scripts/styles.
+ *
+ * @since 4.1.0
*/
- public function tab_uploaded() {
- $backgrounds = get_posts( array(
- 'post_type' => 'attachment',
- 'meta_key' => '_wp_attachment_is_custom_background',
- 'meta_value' => $this->manager->get_stylesheet(),
- 'orderby' => 'none',
- 'nopaging' => true,
- ) );
-
- ?>
print_tab_image( esc_url_raw( $background->guid ) );
- }
+ public function enqueue() {
+ parent::enqueue();
- /**
- * @since 3.4.0
- * @uses WP_Customize_Image_Control::print_tab_image()
- */
- public function tab_default_background() {
- $this->print_tab_image( $this->setting->default );
+ wp_localize_script( 'customize-controls', '_wpCustomizeBackground', array(
+ 'nonces' => array(
+ 'add' => wp_create_nonce( 'background-add' ),
+ ),
+ ) );
}
}
+/**
+ * Customize Header Image Control class.
+ *
+ * @since 3.4.0
+ *
+ * @see WP_Customize_Image_Control
+ */
class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
public $type = 'header';
+ public $uploaded_headers;
+ public $default_headers;
+ /**
+ * @param WP_Customize_Manager $manager
+ */
public function __construct( $manager ) {
parent::__construct( $manager, 'header_image', array(
'label' => __( 'Header Image' ),
@@ -719,17 +1015,12 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
'data' => 'header_image_data',
),
'section' => 'header_image',
- 'context' => 'custom-header',
'removed' => 'remove-header',
'get_url' => 'get_header_image',
) );
}
- public function to_json() {
- parent::to_json();
- }
-
public function enqueue() {
wp_enqueue_media();
wp_enqueue_script( 'customize-views' );
@@ -767,7 +1058,7 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
$this->uploaded_headers = $custom_image_header->get_uploaded_header_images();
}
- function print_header_image_template() {
+ public function print_header_image_template() {
?>