Skip to content

Fix WordPress 7.1 core integration: Chromium detection, init timing, settings default - #27

Merged
adamsilverstein merged 3 commits into
mainfrom
fix/71-core-integration
Jul 16, 2026
Merged

adamsilverstein merged 3 commits into
mainfrom
fix/71-core-integration

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Jul 16, 2026 •

Copy link
Copy Markdown
Owner

Fixes #23. Part of the 7.1 readiness plan in #25.

Summary

  • Fix Chromium version function names: core 7.1 ships wp_get_chromium_major_version() and Gutenberg ships gutenberg_get_chromium_major_version(); the plugin called nonexistent *_chrome_* variants. Because detection always failed, COEP/COOP headers were emitted on Chrome 137+ in addition to core's Document-Isolation-Policy header. The plugin is now inert on DIP-capable browsers.
  • Defer initialization to plugins_loaded: the Gutenberg feature gate was checked at file include time, so activation order determined whether the plugin worked at all.
  • Browser-independent settings default: csme_enabled previously defaulted from the User-Agent of whoever saved the settings, persisting that browser's value site-wide. The option now defaults to 1; per-request DIP detection stays in csme_should_use_coep_coop(). csme_get_enabled_default() is removed.

Tests

  • Updated Test_Should_Use_Coep_Coop for the renamed functions, including a new Gutenberg-fallback case and a Chromium < 137 case.
  • Replaced Test_Get_Enabled_Default with Test_Settings, which verifies the registered default is 1 and the option gates csme_should_use_coep_coop().
  • Full suite run locally: 52 tests pass; the 3 Test_Output_Buffer failures are pre-existing on main and environment-specific (no xdebug locally, so headers_list() is empty under CLI).

Test plan

  • Chrome 137+: only core's DIP header present, no plugin COEP/COOP headers
  • Firefox: COOP: same-origin + COEP: credentialless, window.crossOriginIsolated === true
  • Safari: COOP: same-origin + COEP: require-corp, window.crossOriginIsolated === true
  • Plugin activated before and after Gutenberg, and on core 7.1 without Gutenberg

Summary by CodeRabbit

  • Bug Fixes

    • Improved plugin startup reliability by ensuring initialization occurs after WordPress plugins are loaded.
    • Updated browser compatibility detection for newer Chromium versions.
    • Client-side media processing is now enabled by default.
    • COEP/COOP behavior now correctly responds to the plugin setting and browser capabilities.
  • Tests

    • Expanded coverage for settings, browser detection, and isolation behavior.

Core ships wp_get_chromium_major_version() and Gutenberg ships
gutenberg_get_chromium_major_version(); the plugin called nonexistent
*_chrome_* variants, so DIP-capable browsers were never detected and
COEP/COOP headers were sent on Chrome 137+ alongside core's
Document-Isolation-Policy header.
The Gutenberg feature gate was checked at file include time, so when
this plugin loaded before Gutenberg the check failed and the plugin
bailed out entirely. Deferring to plugins_loaded makes activation
order irrelevant.
The default was computed from the User-Agent of whoever saved the
settings and then persisted site-wide for all browsers. DIP detection
already happens per-request in csme_should_use_coep_coop(), so the
stored option can simply default to enabled.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The plugin now initializes on plugins_loaded, uses Chromium-specific version helpers for DIP detection, defaults csme_enabled to enabled, and adds or updates tests for initialization-related isolation behavior.

Changes

Initialization and isolation behavior

Layer / File(s) Summary
Deferred plugin initialization
client-side-media-experiments.php
csme_init() runs after plugins_loaded, performing enablement checks before loading settings, isolation, and HEIC support modules.
Chromium DIP detection
includes/cross-origin-isolation.php, tests/Test_Should_Use_Coep_Coop.php
COEP/COOP detection now uses Chromium version helpers and tests core, Gutenberg fallback, and version threshold behavior.
Enabled setting defaults and filters
includes/settings.php, tests/Test_Settings.php
csme_enabled defaults to 1; UI and runtime fallbacks use that value, with tests covering enabled and disabled states.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WordPress
  participant csme_init
  participant PluginModules
  participant ChromiumHelpers
  WordPress->>csme_init: fires plugins_loaded
  csme_init->>PluginModules: loads settings and isolation code
  PluginModules->>ChromiumHelpers: retrieves Chromium major version
  ChromiumHelpers-->>PluginModules: returns version for DIP decision
Loading

Possibly related issues

Possibly related PRs

Poem

A bunny hopped past DIP’s bright gate,
While plugins waited, then loaded late.
Chromium names now guide the way,
Settings bloom enabled each day.
Tests thump softly: “COEP’s okay!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: Chromium detection, deferred initialization, and the settings default update.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/71-core-integration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/Test_Should_Use_Coep_Coop.php (1)

31-68: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Prevent test pollution from conditionally defined global functions.

Defining a function (e.g., wp_get_chromium_major_version or gutenberg_get_chromium_major_version) inside a test method defines it globally for the remainder of the PHP process.
Because test_returns_true_when_chromium_below_137() and test_returns_false_when_chromium_137_or_higher() try to define the same function with different return values, whichever test runs second will encounter function_exists() === true and silently reuse the value defined by the first test. This causes test pollution, leading to false positives or test failures depending on execution order. It also pollutes other test classes (like Test_Settings).

Consider using PHPUnit's process isolation for these tests to prevent global state leakage, or utilize a mocking library if available in your test suite.

♻️ Proposed fix using process isolation
 	/**
 	 * Returns false when Chromium version is 137+ (DIP is used).
+	 *
+	 * `@runInSeparateProcess`
+	 * `@preserveGlobalState` disabled
 	 */
 	public function test_returns_false_when_chromium_137_or_higher() {
 		if ( ! function_exists( 'wp_get_chromium_major_version' ) ) {
 			function wp_get_chromium_major_version() {
 				return 140;
 			}
 		}
 
 		$this->assertFalse( csme_should_use_coep_coop() );
 	}
 
 	/**
 	 * Returns true when Chromium version is below 137 (no DIP support).
+	 *
+	 * `@runInSeparateProcess`
+	 * `@preserveGlobalState` disabled
 	 */
 	public function test_returns_true_when_chromium_below_137() {
 		if ( ! function_exists( 'wp_get_chromium_major_version' ) ) {
 			function wp_get_chromium_major_version() {
 				return 130;
 			}
 		}
 
 		$this->assertTrue( csme_should_use_coep_coop() );
 	}
 
 	/**
 	 * Falls back to the Gutenberg plugin's version function when core's is absent.
+	 *
+	 * `@runInSeparateProcess`
+	 * `@preserveGlobalState` disabled
 	 */
 	public function test_falls_back_to_gutenberg_version_function() {
 		if ( ! function_exists( 'gutenberg_get_chromium_major_version' ) ) {
 			function gutenberg_get_chromium_major_version() {
 				return 140;
 			}
 		}
 
 		$this->assertFalse( csme_should_use_coep_coop() );
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Test_Should_Use_Coep_Coop.php` around lines 31 - 68, Prevent global
function definitions in test_returns_false_when_chromium_137_or_higher,
test_returns_true_when_chromium_below_137, and
test_falls_back_to_gutenberg_version_function from leaking between tests by
enabling PHPUnit process isolation for these test methods or the containing test
class. Preserve each test’s existing version value and assertions while ensuring
they execute in isolated PHP processes.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tests/Test_Should_Use_Coep_Coop.php`:
- Around line 31-68: Prevent global function definitions in
test_returns_false_when_chromium_137_or_higher,
test_returns_true_when_chromium_below_137, and
test_falls_back_to_gutenberg_version_function from leaking between tests by
enabling PHPUnit process isolation for these test methods or the containing test
class. Preserve each test’s existing version value and assertions while ensuring
they execute in isolated PHP processes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f704cc4-7551-4440-be76-75ca9751becf

📥 Commits

Reviewing files that changed from the base of the PR and between 9fd6128 and 7959e9b.

📒 Files selected for processing (6)
  • client-side-media-experiments.php
  • includes/cross-origin-isolation.php
  • includes/settings.php
  • tests/Test_Get_Enabled_Default.php
  • tests/Test_Settings.php
  • tests/Test_Should_Use_Coep_Coop.php
💤 Files with no reviewable changes (1)
  • tests/Test_Get_Enabled_Default.php

@adamsilverstein
adamsilverstein merged commit 721af5c into main Jul 16, 2026
8 checks passed
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.

Fix WordPress 7.1 core integration: Chromium detection, init timing, settings default

1 participant