Make WordPress Core

Opened 7 years ago

Last modified 3 years ago

#42075 new defect (bug)

Do not show default image on using WP_Customize_Cropped_Image_Control.

Reported by: toro_unit's profile Toro_Unit Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.2
Component: Customize Keywords: needs-patch
Focuses: Cc:


Add New Control use WP_Customize_Cropped_Image_Control.
Do not Show default image.

But show Default button. When click the button, nothing happens.

Instead of using WP_Customize_Image_Control, Show image.

function foo_customize_register( WP_Customize_Manager $wp_customize ) {

        $wp_customize->add_section( 'theme_options', array(
                'title'    => __( 'Theme Options' ),
        ) );

        $wp_customize->add_setting( 'custom_image', array(
                'default' => get_parent_theme_file_uri( '/images/default-header.jpg' ),
        ) );

        $wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'custom_image', array(
                                'label'   => __( 'Upload an Image' ),
                                'section' => 'theme_options',
                                'width'              => 1920,
                                'height'             => 1080,

add_action( 'customize_register', 'foo_customize_register' );

Attachments (1)

patch.diff (648 bytes) - added by Toro_Unit 7 years ago.

Download all attachments as: .zip

Change History (9)

7 years ago

#1 @Toro_Unit
7 years ago

  • Version set to 4.8.2

#2 @Toro_Unit
7 years ago

  • Keywords has-patch added

#3 follow-up: @celloexpressions
7 years ago

patch.diff seems likely to potentially break a lot of things. Can you please explain what the issue is in more detail @Toro_Unit? Hopefully there's a fix within the JS for the cropped image control, rather than my changing which control it extends (which has other implications).

#4 in reply to: ↑ 3 @Toro_Unit
7 years ago

Thanks reply @celloexpressions !

Created sample theme

And Movie.

Do not set default setting, There is no problem.

WP_Customize_Cropped_Image_Control support default image support. But not support in the case of js.

#5 @dlh
4 years ago

  • Focuses administration removed
  • Keywords needs-patch added; has-patch removed
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 4.8.2 to 4.2

If I'm following correctly, the unexpected behavior here stems from setAttachmentDataAndRenderContent(), added in [37701] for #36521.

The function dictates that unless a control extends UploadControl, the value of the control's setting must be an ID. Otherwise, the attachment data is deleted before the control template is rendered.

Hence, when the default of a setting using the WP_Customize_Cropped_Image_Control is a URL, then clicking the "Default" button has no visual effect because the CroppedImageControl extends MediaControl and so the value expected to be an ID.

@celloexpressions suggested in ticket:36521#comment:9 that [37701] might have been a little overbroad:

deleting the attachment param based on the value may not be the safest approach. Probably not worth changing anything in core for at this point, and unlikely to affect others if they haven't reported it yet

Perhaps there's room for the function to be more accommodating.

#6 @Schwarttzy
4 years ago

Any chance this will ever get properly addressed?

This is a huge oversight. A theme developer can not set the default image still to this day when using WP_Customize_Cropped_Image_Control because WordPress is looking for an image ID number.

Could we get around to fixing the default image display to work with a URL and then switch to an ID when an image is selected?

#7 @dlh
4 years ago

#49823 was marked as a duplicate.

#8 @celloexpressions
3 years ago

WP_Customize_Media_Control and its child controls are specifically designed to work with attachment IDs. This does create complexities for specifying default values. But I'm not sure that it would ever be appropriate to use setting values other than an attachment post ID with these controls.

Is there any reason that themes and plugins can't default to a fallback value in their output of settings when the media control values are empty? Rather than assigning the default value to the setting, I would expect empty settings to be interpreted as applying the default/fallback value.

Note: See TracTickets for help on using tickets.