Skip to content

Fix PHP 7.4-8.5 / WP 6.0-7.0 compatibility and harden packaging - #15

Open
RahatSheikhLeon wants to merge 2 commits into
latestfrom
dev
Open

Fix PHP 7.4-8.5 / WP 6.0-7.0 compatibility and harden packaging#15
RahatSheikhLeon wants to merge 2 commits into
latestfrom
dev

Conversation

@RahatSheikhLeon

Copy link
Copy Markdown

Replaces #14, which GitHub auto-closed when its head branch toggle-content-dev was renamed to dev. Same commit (ffb78be), no content change.

Summary

Compatibility pass over the whole declared range — PHP 7.4 → 8.5 and WordPress 6.0 → 7.0 — with no feature or behavior change. Latest stable verified live on 2026-08-10 (PHP 8.5.9, WP 7.0.3).

Detected original baseline was PHP 5.6-era / WP 5.6-declared (really 5.9+ in practice). The policy minimum won on both axes, so the declared floor is now PHP 7.4 / WP 6.0.

Two fatals fixed

  • lib/style-handler submodule required unconditionally. The submodule was uninitialised and empty in a fresh checkout, so require_once fataled the plugin on load. Now guarded with file_exists().
  • throw new Error from an init callback when build output is missing — an uncaught Error on init is a site-wide white screen. Now a capability-gated admin notice.

PHP 8.x fixes

  • include_once for dist/modules.asset.php returns bool on a second include, making the array offsets below it fatal. Switched to require.
  • Added isset() / is_array() guards around asset dependency and version reads.
  • Font loader: guarded illegal array keys, non-string values, missing blockName, and non-array attrs.

Hygiene

  • Sanitized $_SERVER['QUERY_STRING'] (wp_unslash + sanitize_text_field).
  • add_filter('init', …)add_action('init', …).
  • Added the missing ABSPATH guard.
  • Added Requires PHP, Requires at least, Tested up toabsent entirely before — and corrected stale readme.txt values (Tested up to was 6.5, five majors behind).

Packaging

.distignore rewritten. Beyond excluding config/ and babel configs, this fixes two pattern bugs verified against a real wp dist-archive build:

  • Leading-slash entries never match. /controls/ expanded to *//controls/* (literal double slash), so 4 files leaked.
  • The .git rule could not catch a submodule's .git file. Root .git is a directory, so the rule became */.git/*; lib/style-handler/.git shipped, containing a local absolute path.
  • dist/*.*.map missed nested maps — dist/frontend/index.js.map shipped.

Package now goes from 29 → 21 files, with all runtime files verified present.

Version

Bumped to 1.5.0, synced across plugin header, TOGGLE_CONTENT_VERSION, readme.txt Stable tag, and package.json.

Test plan

  • php -l clean on all 10 PHP files under PHP 8.5.8
  • Clean rebuild (npm run build) reproduces byte-identical output
  • wp dist-archive package verified: no node_modules, no .git, top-level folder toggle-content/, 13 dist/ files present
  • Manual smoke test in the block editor across WP 6.0 and 7.0
  • Verify frontend toggle behavior is unchanged

Not auto-fixed — needs a decision

Documented in compatibility-report.md §7:

  1. is_registered('essential-blocks/countdown') guard at toggle-content.php:116 checks the wrong block name, so the block silently fails to register when Essential Blocks is active.
  2. Four hard PHP 8.0+ breaks in lib/style-handler (undefined constant, in_array() on false, array_key_exists() on non-array, count() on non-countable). Separate shared repo, needs its own PR.
  3. eb_wp_version float cast — the controls submodule compares it numerically (>= 5.8), so "fixing" it to a string would break every EB sibling plugin.
  4. DOMNodeInserted in the animation loader, removed from Chromium 127+.

Note on the base branch

Targeting latest, not mastermaster is missing commit d04c239. The two have diverged and should be reconciled separately.

🤖 Generated with Claude Code

RahatSheikhLeon and others added 2 commits August 10, 2026 14:39
Audit and repair the plugin so it runs across the full declared range, with
no feature or behavior change. Declared floor raised to PHP 7.4 / WP 6.0.

Fatal-path fixes:
- Guard the style-handler submodule require with file_exists(); an
  uninitialised submodule previously fataled the plugin on load
- Replace the init-time `throw new Error` on missing build output with a
  capability-gated admin notice, so a missing build no longer white-screens
  the whole site

PHP 8.x fixes:
- Use `require` instead of `include_once` for dist/modules.asset.php; a
  second *_once include returns bool, making the array offsets fatal
- Add isset()/is_array() guards around asset dependency and version reads
- Guard illegal array keys and non-string values in the font loader
- Guard missing blockName and non-array attrs in render_block handling

Hygiene:
- Sanitize $_SERVER['QUERY_STRING'] via wp_unslash + sanitize_text_field
- add_filter('init', ...) -> add_action('init', ...) for meta registration
- Add the missing ABSPATH guard to the main plugin file
- Add Requires PHP, Requires at least and Tested up to headers, which were
  absent entirely, and correct the stale readme.txt values

Packaging:
- Rewrite .distignore: exclude config/ and babel config files, catch all
  sourcemaps, and fix two pattern bugs that leaked files into the zip -
  leading-slash entries never match, and the .git rule could not catch a
  submodule's .git file. Verified against a real wp dist-archive build.

Version bumped to 1.5.0 across the plugin header, TOGGLE_CONTENT_VERSION,
readme.txt Stable tag and package.json.

Full audit, including issues flagged but deliberately not auto-fixed, is in
compatibility-report.md.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Converts readme.txt to GitHub-flavored markdown, matching the output shape
of the wp_readme_to_markdown grunt task the Gruntfile declares.

Generated by hand rather than via `grunt readme`: the Gruntfile loads
grunt-wp-i18n and grunt-wp-readme-to-markdown, but neither is declared in
package.json devDependencies, so the task cannot run without adding
undeclared dependencies.

README.md is already excluded by .distignore, so it does not ship in the
plugin zip.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant