WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 months ago

#25104 closed defect (bug) (invalid)

is_admin() conditional tag is not true on the Customizer page

Reported by: ScottSmith Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Customize Keywords: needs-docs
Focuses: Cc:

Description

Steps to Reproduce:

  1. Add the following code or similar to any page of the theme to test whether the is_admin() conditional tag is true or false.
<?php if ( ! is_admin() ) {
     echo "You are viewing the theme";
} else {
     echo "You are viewing the WordPress Administration Panels";
}?>
  1. Open theme customizer

Expected: Text should read "You are viewing the WordPress Administration Panels" because the theme customizer is an admin panel.

Result: Text reads "You are viewing the theme," when in fact, you are in an admin panel.

Change History (6)

comment:1 @SergeyBiryukov2 years ago

  • Component changed from General to Appearance
  • Keywords reporter-feedback removed

Related: #23509

comment:2 @johnbillion2 years ago

Suggesting close as wontfix, and in favour of introducing a new conditional in #23509. If we start returning true for is_admin() on the front end then it'll mess with plugins that control access to the admin area and we'll get all sorts of code being executed when it shouldn't be.

comment:3 @SergeyBiryukov2 years ago

  • Keywords dev-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed
  • Version changed from 3.6 to 3.4

comment:4 @nacin2 years ago

  • Resolution changed from wontfix to invalid

This is also by design, to make sure themes checking is_admin() were either loading or not loading the proper stuff in the controls panel (considered the admin here) and in the preview frame (considered the frontend). This was designed to work with all themes without modification, which was quite a bit of a feat in itself.

comment:5 @badfun2 months ago

  • Keywords needs-codex added

Was just about to report the same 'bug'. If this was by design, then I suppose the problem is really communicating that the customizer preview is really front-end, and not in the admin, even though it is, well, in the admin.

is_customize_preview() is great of course. thanks!

comment:6 @DrewAPicture2 months ago

  • Keywords needs-docs added; needs-codex removed

I would suggest supplementing the inline docs for is_admin() to mention this case. The Customizer is now consistently being described as a "bridge" between the back- and front-ends, so I think that's something worth mentioning by default for is_admin() in its article in the code reference.

Removing the needs-codex keyword as we're really trying to shift effort to inline docs and the code reference over the Codex.

Note: See TracTickets for help on using tickets.