Can't preview starter content "Home" menu item in subdirectory installation
|Reported by:||dlh||Owned by:||westonruter|
|Component:||Customize||Keywords:||has-patch commit fixed-major|
To replicate, install trunk into a subdirectory, preview Twenty Seventeen with its starter content, and attempt to navigate to the "Home" menu item. Instead of the preview, you get a "Cheatin'" error.
As far as I can tell, the cause of this behavior starts with get_option() stripping trailing slashes from home_url().
get_theme_starter_content() calls home_url() as part of building its 'nav_menus' array as of . When the home URL is a subdirectory, the resulting URL is always example.com/wp instead of example.com/wp/.
Later, inside the Customize preview, the resulting URL of the "Home" menu item looks like:
Clicking the link leads to the error page because (and here I'm not quite certain) the user's authentication cookie isn't sent to the server with a request for example.com/wp. So, no user is logged in when the Customizer checks authentication -- first in WP_Customize_Widgets::__construct(), then in WP_Customize_Manager::customize_preview_init().
The problem doesn't occur when WordPress is in the root because appending the changeset ID in JS (via element.search in prepareLinkPreview()) automatically appends the trailing slash, at least in Chrome and Firefox. Before that, I think  handled it.
Assuming the above is correct, a relatively low-impact way to address the issue is to trailing-slash home_url() in get_theme_starter_content(), which the attached patch would do.
However, any link to example.com/wp in the preview is affected, even before 4.7. The starter content only makes the issue more noticeable. So a more general fix in JS might also be worthwhile.
Change History (10)
- Keywords has-patch added
- Milestone changed from Awaiting Review to 4.7.4
6 weeks ago
- Keywords commit added
- Owner set to westonruter
- Status changed from new to accepted
6 weeks ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
- Version changed from 4.7.1 to 4.7