[wp-trac] [WordPress Trac] #39815: Format for the default image of WP_Customize_Media_Control and WP_Customize_Cropped_Image_Control
WordPress Trac
noreply at wordpress.org
Wed Feb 8 19:38:17 UTC 2017
#39815: Format for the default image of WP_Customize_Media_Control and
WP_Customize_Cropped_Image_Control
--------------------------+-----------------------------
Reporter: srikat | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Customize | Version: 4.7.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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:
[[Image(http://d.pr/i/d8OT+)]]
What I see:
[[Image(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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39815>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list