• Hi guys,

    I’m working on a theme with multiple sections, around 4 or 5 and each of them has a background image. I’m using the customizer API to select background images for my sections.

    The problem that I encounter is that when I instantiate a WP_Customize_Image_Control object like in the code below, as long as my theme is active, I can no longer select or upload any image, whether it’s from the customizer menu or when editing a post, setting a featured image or whatever.

    Here’s the code I got from codex and I’m having trouble with:

    $wp_customize->add_setting( 'heading_bgimage',
    		array(
    			'default' => '',
    			'type' => 'theme_mod',
    			'capability' => array('edit_theme_options', 'upload_files', 'edit_files'),
    			'transport' => 'postMessage',
    		)
    	);
    
    	$wp_customize->add_control(new WP_Customize_Image_Control(
    			$wp_customize,
    			'heading_bgimage',
    			array(
    				'label'      => __( 'Upload an image', 'chef' ),
    				'section'    => 'chef_options',
    				'settings'   => 'heading_bgimage',
    				'context'    => 'my_theme_name'
    			)
    		)
    	);

    I suspect that there’s something related to the context, changed it but to no avail…

    1) Are there any other arguments I should provide to the WP_Customize_Image_Control constructor to have access to all the other already uploaded images and be able to upload images with it?

    2) The error that I get when I try to upload an image is
    "An error occurred in the upload. Please try again later".
    I looked at async-upload.php and it outputs:

    {"success":true,"data":{"id":31,"title":"2","filename":"2-2.jpg","url":"h...

    so it looks like the upload works and there’s something else. It would be useful some info to at least further debug on what’s happening…

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter imads

    (@imads)

    Ok so I grabbed the snipped of code from another theme on which image upload/select works without issue and it just won’t work on my. My theme is based on underscores and has pretty much everything enabled if talking of theme support.

    So, does anyone have any idea which setting should be enabled further for this to work? Even WP_DEBUG won’t output anything, moreover, the file is uploaded but is not shown in the gallery.

    I just don’t find anything different that may be related to image upload in the other theme..

Viewing 1 replies (of 1 total)
  • The topic ‘Using WP_Customize_Image_Control and can no longer upload/select images’ is closed to new replies.