intermittent home-page 404
-
I’ve been chasing an intermittent home-page 404 on a dev site and it traces back to LearnPress, so I wanted to flag it with what I found.
Every so often the site’s home page (
/) returns a 404. Flushing permalinks clears it straight away, but it comes back on its own after a while, and it only happens with LearnPress active. Deactivating LearnPress stops it completely.The cause is that LearnPress hooks
option_rewrite_rulesat priority 1 and array_merges its own ruleset into the option every time it’s read (LP_Query, from what I traced). Filtering that option is a known WordPress core gotcha (Trac #37561):flush_rules()reads it while regenerating the rules, so LearnPress’s merge feeds back into the regeneration. In that churn, core’s$root rule (the'$' => 'index.php?'that routes/to the front page) gets pushed out and never makes it into the saved set. With nothing matching/, the home page 404s. It keeps returning because every regeneration (a plugin activating, a permalink save, an update, core’s own self-heal) is another chance for the rule to drop.Digging in further, LearnPress re-injects its whole course/profile/checkout ruleset into
extra_rules_topon every request, and the per-request guard that should stop it doing that repeatedly looks like it’s commented out in the source.To reproduce: static front page, permalinks on
/%postname%/, LearnPress active. Save Permalinks (or activate any plugin) to force a regeneration, then check the storedrewrite_rulesoption and you’ll see the$rule is intermittently gone, with/404ing when it is.I think the fix is to register LearnPress’s rewrite rules the standard way, at generation time via
add_rewrite_rule()or therewrite_rules_arrayfilter, rather than filtering the stored option on read, and to re-enable the per-request guard so the ruleset isn’t merged in every request. That keeps LearnPress clear offlush_rules()and lets core’s root rule survive.The page I need help with: [log in to see the link]
You must be logged in to reply to this topic.