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.

Looking to add an action to wp_head but only if the user is in "theme customizer" mode. Does anyone know if there's a conditional for this?

share|improve this question
    
What does "theme customizer mode" mean? Do you mean if the current user has the capability to edit_theme_options? If so: if ( current_user_can('edit_theme_options') ) { // do your stuff } –  vancoder Apr 1 '13 at 23:18
    
Nope, the theme customizer is where a user can adjust certain front-end aspects (e.g. "Link Color", "Background Image", etc.) and see changes in "real time" before committing them. Here's the full drilldown: codex.wordpress.org/Theme_Customization_API –  Brian Apr 1 '13 at 23:19
    
It works by showing the user the site "live" as changes are made and shows the latest version in an iframe which can then be "Save & Publish"'d when changes are satisfactory. –  Brian Apr 1 '13 at 23:20
add comment

2 Answers

up vote 1 down vote accepted

Hook a function to the customize_preview_init action. In that function, do your add_action for the wp_head.

The customize_preview_init action runs in the call that renders the frame that the preview page is displayed on, and happens early enough to hook onto wp_head.

share|improve this answer
    
Thanks Otto - that's what I was looking for I think. I've been reading your post on this a fair bit lately :) –  Brian Apr 1 '13 at 23:24
add comment

If you mean a hook that fires when you are actually customizing the theme at wp-admin/customizer.php, with the tool bar on the left, then there are several hooks on that page. For example (but not an exhaustive list)...

do_action( 'customize_controls_init' );
// ...
do_action( 'customize_controls_enqueue_scripts' );

You should be able to narrow things down with the available hooks. I don't know if a boolean is set anywhere, such as a constant like WP_DEBUG

share|improve this answer
    
Thanks, I think Otto's answer was a bit more specific, though this was helpful as well. –  Brian Apr 1 '13 at 23:24
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.