Opened 12 years ago
Closed 11 years ago
#23509 closed enhancement (fixed)
Conditional function that lets you know if your site is being viewed through the Customizer
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Customize | Keywords: | has-patch |
Focuses: | template | Cc: |
Description
I can provide a use case if necessary, but this should be relatively simple.
If I need to do something special with my theme when my site is being viewed through the customizer, there's no easy way determine if it is.
A simple is_customizer()
(or similar) function would be incredibly useful in this scenario.
I'd write up a patch, but I don't know where to put the new function.
Attachments (2)
Change History (19)
#2
@
12 years ago
- Cc sammybeats added
- Keywords has-patch needs-testing added
Submitted a patch that creates a function is_customizer() that checks to make sure $wp_customize is of type WP_Customize_Manager and returns the value of $wp_customize->is_preview();
#7
@
11 years ago
- Cc matt@… added
I've refreshed and simplified the patch. We've been running this on WordPress.com since April and we should land it in 3.8.
#9
in reply to:
↑ description
@
11 years ago
- Focuses template added
- Keywords reporter-feedback added; 2nd-opinion needs-testing removed
#10
@
11 years ago
mattwiebe mentioned that they're using this on WordPress.com. He can probably provide a much more compelling use-case than I could.
#11
@
11 years ago
Here's some use cases from WP.com:
- Custom Fonts in the Customizer - we use a Typekit kit on a non-Customizer view, but all font rendering happens via a preview script in the Customizer. We use
is_customizer()
to decide which should be enqueued. - Stylesheet concatenation - turn off in the Customizer for Custom CSS users so that we can identify the specific stylesheet and remove it when the user edits their stylesheet.
- don't load stats scripts in the customizer
There's a few more that aren't as easy to explain.
#12
follow-up:
↓ 13
@
11 years ago
- Keywords reporter-feedback removed
- Milestone changed from Awaiting Review to 4.0
Thanks mattwiebe.
is_customizer
seems like a fine name, but isn't it more is_customize_preview
?
#13
in reply to:
↑ 12
@
11 years ago
Replying to ocean90:
Thanks mattwiebe.
is_customizer
seems like a fine name, but isn't it moreis_customize_preview
?
Both have some ambiguity. I've always thought is_previewing
bit of the Customizer seems a bit weird when you're not previewing a non-active theme, at least not at first.
I actually think in_customizer
is a bit clearer but most of our conditionals go with is_*
.
#14
@
11 years ago
Keep in mind we also have is_preview() for post previews.
#15
@
11 years ago
I would suggest either is_customize
, is_customizing
or is_customize_preview
. It's the customize preview in the sense that you're previewing the changes you're making to different settings, regardless of whether or not it's a theme preview.
In code, everything's customize
, not customizer
. However, considering the customizer
as the thing and customize
as the action, is_customizing
could also make sense. But is_customize_preview
is probably our best option here, all things considered.
This seems to work for me: