Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to achieve the following (using a copy of twentytwelve):

  • Turn off custom-header theme support to prevent users being able to upload their own images (achieved)
  • Create own section in customize admin area (achieved)
  • Add a list containing thumbnails to be selected to replace header image. No upload capabilities.

I am trying to hook into customize_register and utilize WP_Customize_Image_Control but get it to only display a predefined list of images without the upload options. This post explains how to use the customize_register and in the additional notes towards the bottom goes onto describe what each control can do. It suggests WP_Customize_Image_Control is used to upload AND display a list of images. I just want a list.

This post shows you how to add the images to a 'default' tab but the original custom-header theme support has to be switched on which gives users the option to add header images from the admin page.

I know I could do it using a simple drop down menu but I like the selector window which provides a visual prompt.

Does anyone have a suggestion as to how I might utilize customize_register to achieve this?

share|improve this question
1  
Post your code please, even if it isn't much. –  s_ha_dum Aug 5 '13 at 14:05
    
You can try adding wordpress media uploader as custom control. –  Sisir Aug 5 '13 at 14:32
add comment

2 Answers 2

I suggest you to build your own WP_Customize_Control class that does exactly what you want. You can copy-paste the core WP_Customize_Image_Control code on your own class and modify it to fit your needs.

You can follow Otto's guide to create a new control.

I personally use the Customizer API to modify the background-position CSS property of the background image using the mouse dragging movement (see the git repo).

share|improve this answer
    
Please don't just post links. Add the relevant codes to your answer, so the answer doesn't suffer from potential link rot. –  kaiser Aug 5 '13 at 15:30
    
Instead of copy-pasting the existing code from WP_Customize_Image_Control into a new class, extend the class and change the relevant pieces to not have the upload control, if that's the desired behavior. Copy-pasta is usually a bad idea. –  Otto Aug 5 '13 at 16:22
    
You find in this public repo also many examples and ready to use class for the WP Customizer. –  bueltge Aug 6 '13 at 8:28
add comment
up vote 0 down vote accepted

Thank you all for your responses. Being new to both WordPress and OOP, creating my own class seemed rather daunting. I have pieced together another solution which does the job.

To start, I turned custom-header theme support back on and then modified my functions.php file.

Firstly, I wanted to prevent users from accessing the 'Header' link from the main wp menu. From the header link they are able to upload images and therefore by adding the following code snippet, I was able to remove this from the admin menu:

add_action( 'admin_menu', 'adjust_the_wp_menu', 999 );
function adjust_the_wp_menu() {
  $page = remove_submenu_page( 'themes.php', 'custom-header' );
}

I then utilized the register_default_headers() function to load default images into the existing custom_header. I am not certain how, but this has also provided the required functionality of stopping uploads from the customize window. A tab called 'Default' has been created alongside 'Uploaded' under Header Image in the customize theme view.

add_action( 'after_setup_theme', 'add_default_banner_images' );    
if ( ! function_exists('add_default_banner_images') ):    
    define( 'HEADER_IMAGE', '[path-to-file]/wp-content/global/banners/5.jpg' );     
    register_default_headers( 
        array (
            'head' => array (
                'url' => '[path-to-file]/wp-content/global/banners/1.jpg',
                'thumbnail_url' => '[path-to-file]/wp-content/global/banners/1.jpg',
                'description' => __( 'Image 01', 'twentytwelve_mod' )
            ),
            'vision' => array (
                'url' => '[path-to-file]/wp-content/global/banners/2.jpg',
                'thumbnail_url' => '[path-to-file]/wp-content/global/banners/2.jpg',
                'description' => __( 'Image 02', 'twentytwelve_mod' )
            ),
            'gallery' => array (
                'url' => '[path-to-file]/wp-content/global/banners/3.jpg',
                'thumbnail_url' => '[path-to-file]/wp-content/global/banners/3.jpg',
                'description' => __( 'Image 03', 'twentytwelve_mod' )
            ),
            'sea' => array (
                'url' => '[path-to-file]/wp-content/global/banners/4.jpg',
                'thumbnail_url' => '[path-to-file]/wp-content/global/banners/4.jpg',
                'description' => __( 'Image 04', 'twentytwelve_mod' )
            ),
            'orangeworld' => array (
                'url' => '[path-to-file]/wp-content/global/banners/5.jpg',
                'thumbnail_url' => '[path-to-file]/wp-content/global/banners/5.jpg',
                'description' => __( 'Image 05', 'twentytwelve_mod' )
            )           
        ) 
    );
}
endif;

And finally, I removed the unwanted 'Uploaded' tab under Header Image by utilizing the 'cusomize_register' hook:

add_action( 'customize_register', 'customize_register_mytheme' );
function customize_register_mytheme( $wp_customize ) {

    //Remove 'uploaded' tab from control 'header_image'
    $controlHeaderImage = $wp_customize->get_control( 'header_image' );     
    $controlHeaderImage->remove_tab( 'uploaded' );
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.