Opened 10 years ago
Last modified 8 weeks ago
#37653 new defect (bug)
customizer sections with 'active_callback' set to 'is_front_page' don't show when "Front page displays" "a static page" and no page is selected
| Reported by: | Guss77 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Customize | Version: | 3.4 |
| Severity: | normal | Keywords: | has-patch reporter-feedback has-unit-tests |
| Cc: | Focuses: |
Description
When using a theme with customizer sections set up with the "active_callback" feature set to "is_front_page", when customizing the theme on a blog which has "Front page displays a static page" under "Reading setting", these sections to not show up when accessing "Appearance"->"Customize".
The problem appears to be that when running "Customize", the WP_Query object is started with an empty string. When the query is empty, then is_front_page looks at the value of get_option( 'show_on_front') and if it is set to "posts" it checks is_home - which resolves to true when the query is empty.
On the other hand, if get_option( 'show_on_front') resolves to "pages", is_front_page then checks $this->is_page( get_option( 'page_on_front' ) ) which never resolves to true when starting with an empty query.
The problem with is_page not responding correctly get_option( 'show_on_front') == "pages" is that WP_Query::__construct() will not do anything if empty($query) and will not run WP_Query::query() - which would in turn run get_posts() and then parse_query only there does get_option('show_on_front') gets resolved and is_page is set if needed.
Tested on 4.5.1, but the code paths I traced exist without change in trunk. I'm running my tests on a mutli-site set up, so that might also contribute to the issue, but not in anyway I managed to detect.
Attachments (3)
Change History (18)
#1
@
10 years ago
- Keywords has-patch reporter-feedback added
- Milestone Awaiting Review → 4.7
- Version 4.5.1 → 3.4
@Guss77 thanks for the report. I could specifically reproduce the issue when I first switch from “Your latest posts” to “A static page” while the “Front page” and “Posts page” are both empty (see static-front-page-without-selections.png). This scenario isn't possible when setting these options on the Reading admin page. This intermediate state is possible, however, in the Customizer. The easiest fix is to replace 'is_front_page' as the active_callback with function() { return is_front_page() || is_home(); }.
37653.2.diff seems to be a better fix for this special condition for is_front_page().
Can you confirm this is the scenario you're experiencing?
#2
@
10 years ago
Unfortunately the fix you suggested in is_front_page() does not work for me - I assume because on my setup the "Front page" setting is not empty.
Also, implementing a workaround in the theme code is not useful because I want to be able to update the theme, so the change has also to be done upstream - in any of the dozens themes or so I have installed (using is_front_page for active_callback is very popular and documented in several theme creation tutorials).
Can you please explain why do you think my analysis in the bug report is not correct? Specifically this part:
$this->is_page( get_option( 'page_on_front' ) )never resolves to true when starting with an empty query (regardless of any option setting).
#3
@
10 years ago
I was able to reproduce the error in the scenario I described. I didn't really understand your scenario of starting with an empty query. How would you start with an empty query? The query here should be the main query which would be non-empty.
#4
@
10 years ago
When I say "empty query" - I mean the string that is passed to new WP_Query() when customizer loads the page: it passes an empty string.
#5
@
10 years ago
- Keywords needs-unit-tests added
Some unit tests might be able to help demonstrate this and get this fixed.
This ticket was mentioned in Slack in #core by desrosj. View the logs.
10 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
10 years ago
This ticket was mentioned in Slack in #core by stevenkword. View the logs.
10 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
10 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
10 years ago
#12
@
10 years ago
- Summary customizer sections with 'active_callback' set to 'is_front_page' don't show when "Front page displays" "a static page" → customizer sections with 'active_callback' set to 'is_front_page' don't show when "Front page displays" "a static page" and no page is selected
Clarifying the summary of the bug here to avoid potential panics. This is an edge case for sure, but something that would be nice to fix in 4.7.
#13
@
10 years ago
- Component Themes → Customize
Moving into customize to make sure it gets attention - since this isn't a new issue, does it still need to be tackled in 4.7? I understand it would be nice, of course, but we are into beta now and need to be more selective about where attention is going.
This ticket was mentioned in PR #13538 on WordPress/wordpress-develop by skikken.
8 weeks ago
#15
- Keywords has-unit-tests added; needs-unit-tests removed
A section or control whose active_callback is is_front_page never shows in the Customizer, because is_front_page() is false at the point the callback is evaluated.
The Customizer renders in wp-admin, and nothing there parses a front-end main query. $wp->main() only runs on the front end, from wp-blog-header.php, so $wp_query is still the bare new WP_Query() created in wp-settings.php. Because WP_Query::__construct() skips query() when the query string is empty, parse_query() never runs and none of the is_* flags are populated. They stay at their declared defaults of false, so every branch of is_front_page() falls through to false.
The same situation is already handled for a parsed query with an empty query string. parse_query() promotes is_page and demotes is_home when show_on_front is page, on the grounds that an empty query with a static front page is the front page. That logic is unreachable here only because it lives in the function that does not run for an unparsed query.
This tracks whether parse_query() has run and consults that in is_front_page(), so an unparsed query reporting a static front page is treated as the front page. It does not require a page to be selected, which is what 37653.2.diff gated on, and therefore also covers the intermediate state the Customizer can reach with no page chosen. That state is why the reporter said that patch did not work for him.
Scope notes:
WP_Query::__construct()is unchanged. Making it always callquery()was the reporter's own suggestion inquery.patch, which he described as a hack; it would change behaviour for every barenew WP_Query()in core, about 20 call sites insrc/alone, and an unparsed query is a state core relies on.is_page()is unchanged. An unparsed query has no queried object, so there is nothing to match a page ID against, and a test pins that.is_front_page()returns the same value as before for every parsed query. The tests assert the negative cases as well as the positive ones, including that a parsed query for a different page is still not the front page.
## Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Model(s): Sonnet
Used for: test cases, code review
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hack that workaround the problem for me. I don't think its a coorect solution - the right thing is probably to run WP_Query::query() always, regardless of the query string content