Make WordPress Core

Opened 8 years ago

Last modified 6 years 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's profile Guss77 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Customize Keywords: has-patch reporter-feedback needs-unit-tests
Focuses: Cc:

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)

query.patch (426 bytes) - added by Guss77 8 years ago.
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
static-front-page-without-selections.png (52.4 KB) - added by westonruter 8 years ago.
37653.2.diff (839 bytes) - added by westonruter 8 years ago.

Download all attachments as: .zip

Change History (17)

@Guss77
8 years ago

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

@westonruter
8 years ago

#1 @westonruter
8 years ago

  • Keywords has-patch reporter-feedback added
  • Milestone changed from Awaiting Review to 4.7
  • Version changed from 4.5.1 to 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 @Guss77
8 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 @westonruter
8 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 @Guss77
8 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 @jorbin
8 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.


8 years ago

#7 @desrosj
8 years ago

Still waiting on some unit tests.

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


8 years ago

This ticket was mentioned in Slack in #core by stevenkword. View the logs.


8 years ago

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


8 years ago

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


8 years ago

#12 @celloexpressions
8 years ago

  • Summary changed from customizer sections with 'active_callback' set to 'is_front_page' don't show when "Front page displays" "a static page" to 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 @helen
8 years ago

  • Component changed from Themes to 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.

#14 @westonruter
8 years ago

  • Milestone changed from 4.7 to Future Release
Note: See TracTickets for help on using tickets.