WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#39815 closed defect (bug) (wontfix)

Format for the default image of WP_Customize_Media_Control and WP_Customize_Cropped_Image_Control

Reported by: srikat Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.2
Component: Customize Keywords:
Focuses: Cc:

Description

https://make.wordpress.org/core/2015/07/16/new-customizer-media-controls-in-4-3-and-4-2/ states:

However, note that the default value of the setting must still be a URL, since a default attachment id doesn’t really make sense.

but when I specify the URL of an image as the default value for the control's setting, it does not appear in the Customizer.

Here's the code I've added inside in twentyseventeen_customize_register() of wp-content/themes/twentyseventeen/inc/customizer.php:

/**
 * My Test.
 */
$wp_customize->add_section(	'my-settings', array(
	'description' => __( 'Use the included default image or personalize your site by uploading your own image.<br /><br />The default images is <strong>1600 pixels wide and 1050 pixels tall</strong>.', 'twentyseventeen' ),
	'title'       => __( 'My Section Background Image', 'twentyseventeen' ),
) );

$wp_customize->add_setting(	'my-custom-image', array(
	'default'           => sprintf( '%s/assets/images/sandwich.jpg', get_template_directory_uri() ),
	'sanitize_callback' => 'absint',
) );

$wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'my-custom-image',array(
	'section'     => 'my-settings',
	'label'       => sprintf( __( 'My Section Image:', 'twentyseventeen' ), $image ),
) ) );

Full code: http://pastebin.com/raw/ajyXmnBY

What I expect to see:

http://d.pr/i/d8OT+

What I see:

http://d.pr/i/PYft

If I specify an attachment ID, it works.

It would be of great convenience if this works by specifying image URL rather than ID especially when we are inside a foreach loop where we can use the placeholders for outputting the default images (like bg-1.jpg, bg-2.jpg).

If I replace WP_Customize_Media_Control with WP_Customize_Image_Control, the default image appears fine.

Change History (3)

#1 @westonruter
5 years ago

@srikat I don't think that it's feasible to supply a default image specifically in this way, given that the setting is expecting to model an integer attachment ID. The closest thing in core to what you want to do here I think is actually something seen in the starter content feature added in 4.7, where an image can be loaded into the customized state (changeset) and uploaded into the media library as an attachment with the auto-draft status. In this way, the attachment can be used as the default value for a given setting, but only after first uploading the image into the media library in that transitory state.

#2 @srikat
5 years ago

@westonruter Thanks, makes sense.

Shall I set 'resolve as' of this ticket to 'invalid'? (I am new to trac)

#3 @westonruter
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I think it might be rather a wontfix. While it would be possible to re-architect a setting to represent a URL or an ID, there could be a lot of problems for backwards compatibility for existing code that only expect attachment IDs.

Note: See TracTickets for help on using tickets.