Skip to content

Improve child theme boilerplate to prevent PHP 8.2 fatal errors with NEVE_VERSION #4543

Description

@pirate-bot

Impact: 75 · Confidence: 95 · Complexity: 10

Description

Problem:
Users creating child themes often use the NEVE_VERSION constant when enqueuing their style.css, based on typical snippets or standard boilerplates. However, since a child theme's functions.php loads before the parent theme's functions.php, evaluating NEVE_VERSION too early (or during specific block editor AJAX/REST calls where the parent theme may not fully load the same way) results in an undefined constant. On PHP 8.2+, this triggers a fatal error rather than a warning, silently returning a blank screen in the page editor.

Desired Behavior:
The commonly distributed Neve child theme boilerplate (and any related documentation snippets) should use a defensive pattern when referencing the Neve version to guarantee it doesn't cause fatal errors on modern PHP versions.

Acceptance Criteria:

  • Update the boilerplate in the neve-child repository and documentation snippets.
  • Check if the constant is defined using defined( 'NEVE_VERSION' ) before assigning it.
  • Provide a safe fallback (e.g., wp_get_theme()->get( 'Version' )) if the constant is not defined to avoid fatal errors.

Customer Context

A premium customer running PHP 8.2 experienced a blank page editor for a week. Through troubleshooting, they discovered the child theme functions.php was calling NEVE_VERSION before it was defined, throwing a silent fatal error via AJAX. The customer recommended a robust fallback snippet so other users don't encounter the same painful issue.

Root Cause Analysis

The root cause of the customer's blank editor is a PHP 8.2 strictness change compounded by WordPress load order. The customer's child theme referenced the parent theme's NEVE_VERSION constant when enqueuing assets. Because child themes load before parent themes, and the block editor utilizes specific asynchronous requests, the constant was evaluated before the parent theme had defined it. On PHP 8.2, undefined constants throw fatal errors instead of warnings, which halted execution and silently returned a blank editor interface.

Alternative Suggestions

Update the official Neve child theme boilerplate (e.g. the downloadable zip in the installation docs) and any relevant code snippets to conditionally check defined('NEVE_VERSION'). If it evaluates to false, it should safely fall back to wp_get_theme()->get('Version'). This changes the default starter code so users are completely insulated from version constant fatals, effectively bypassing the problem without needing parent theme architectural changes.

Reasoning

The customer spent a week trying to debug a blank block editor and found that referencing an undefined NEVE_VERSION constant in their child theme triggers a fatal error on PHP 8.2+. Since child theme functions run before parent theme functions, certain AJAX/REST requests can evaluate this constant before Neve has defined it. The customer's proposed solution is a resilient code snippet. We should implement this minor but critical improvement in our child theme boilerplate (which users download from our docs) to provide better defaults and prevent silent crashes for users on modern PHP versions. This is an improvement to existing behavior, not a net-new feature.


Source: HelpScout #3389074640
Generated by feature-request-triage workflow (ID: feature-request-triage_6a593961b4f406.73180497)

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions