Skip to content

feat: let core's copy of a presence function or class win when it already exists - #805

Merged
josephfusco merged 5 commits into
WordPress:mainfrom
huzaifaalmesbah:feat/733-function-exists-guards
Oct 12, 2026
Merged

josephfusco merged 5 commits into
WordPress:mainfrom
huzaifaalmesbah:feat/733-function-exists-guards

Conversation

@huzaifaalmesbah

Copy link
Copy Markdown
Member

Almost all of this diff is re-indentation, so it reads best with whitespace hidden (?w=1), and the scope (all 57 functions in presence.php including private helpers, plus the two REST controllers and the CLI command) is the one I proposed on #733 before hearing back, so it may need narrowing.

Related: #733

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Writing the script that wrapped each declaration and drafting the guard test; reviewed and run locally by me.

@github-actions github-actions Bot added the Public API Adds a hook, route, constant, or global that third parties can depend on label Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🛝 WordPress Playgrounds

Built from d34395c

Post locks RTC Synced patterns Settings
Single site Launch post locks, single site Launch RTC, single site Launch synced patterns, single site Launch settings, single site
Multisite Launch post locks, multisite Launch RTC, multisite Launch synced patterns, multisite Launch network settings, multisite

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.74843% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.12%. Comparing base (e89901e) to head (d34395c).

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #805      +/-   ##
============================================
+ Coverage     97.09%   97.12%   +0.02%     
  Complexity      271      271              
============================================
  Files            30       30              
  Lines          4370     4375       +5     
============================================
+ Hits           4243     4249       +6     
+ Misses          127      126       -1     
Flag Coverage Δ
multisite 97.12% <99.74%> (+0.02%) ⬆️
phpunit 77.14% <71.44%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot removed the Public API Adds a hook, route, constant, or global that third parties can depend on label Oct 9, 2026
github-actions Bot added a commit that referenced this pull request Oct 9, 2026
@huzaifaalmesbah

Copy link
Copy Markdown
Member Author

Dropped the defined() guards on WP_PRESENCE_MAX_KEY_LENGTH and WP_PRESENCE_RESERVED_PREFIX that I proposed on #733: a guard lets a site set them in wp-config.php, and a key length above the column's 191 would bring back the silent truncation it prevents, while core redefining one is only a warning.

github-actions Bot added a commit that referenced this pull request Oct 9, 2026
github-actions Bot added a commit that referenced this pull request Oct 9, 2026
@josephfusco josephfusco added [Type] Enhancement A suggestion for improvement of an existing feature [Area] Infrastructure Issues for the repository infrastructure Public API Adds a hook, route, constant, or global that third parties can depend on php Pull requests that update php code labels Oct 9, 2026
@huzaifaalmesbah
huzaifaalmesbah force-pushed the feat/733-function-exists-guards branch from b6b6f61 to 025b266 Compare October 9, 2026 14:17
@github-actions github-actions Bot removed the Public API Adds a hook, route, constant, or global that third parties can depend on label Oct 9, 2026
github-actions Bot added a commit that referenced this pull request Oct 9, 2026
@huzaifaalmesbah
huzaifaalmesbah marked this pull request as ready for review October 9, 2026 14:28
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props huzaifaalmesbah, rejaulalomkhan, joefusco.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@rejaulalomkhan

Copy link
Copy Markdown
Contributor

Wrapping public functions and classes in \ unction_exists()\ / \class_exists()\ is the clean canonical Gutenberg/feature-plugin approach for incremental Core adoption.

Regarding Codecov's note (\Patch coverage is 99.74555% with 2 lines in your changes missing coverage): the uncovered lines are the fallback branches where a function/class already exists before inclusion. Adding a test in \ est-core-guards.php\ that declares a mock presence function/class before running the guard check will exercise those fallback branches and restore 100% patch coverage.

@github-actions github-actions Bot added the Needs Reply Someone outside the maintainers has waited over 48 hours for an answer label Oct 12, 2026
@josephfusco

Copy link
Copy Markdown
Collaborator

#733 now has answers to Deepak's scope questions, which change this PR in two places:

Guarding every function in presence.php, private helpers included, and the REST controllers stays as it is.

@josephfusco josephfusco added Public API Adds a hook, route, constant, or global that third parties can depend on and removed Needs Reply Someone outside the maintainers has waited over 48 hours for an answer labels Oct 12, 2026
# Conflicts:
#	plugins/presence-api/includes/presence.php
#	plugins/presence-api/includes/rest-api/endpoints/class-wp-rest-presence-controller.php
@josephfusco

Copy link
Copy Markdown
Collaborator

Merged main to clear the conflicts with #815. I rebuilt both files from main's copy with the same wrapping rather than resolving each hunk, so wp_presence_session_hash() is guarded too.

@github-actions github-actions Bot removed the Public API Adds a hook, route, constant, or global that third parties can depend on label Oct 12, 2026
github-actions Bot added a commit that referenced this pull request Oct 12, 2026
@josephfusco
josephfusco merged commit 7c91227 into WordPress:main Oct 12, 2026
25 checks passed
@github-actions github-actions Bot added this to the 0.18.0 milestone Oct 12, 2026
@josephfusco josephfusco mentioned this pull request Oct 12, 2026
24 of 36 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Infrastructure Issues for the repository infrastructure php Pull requests that update php code [Type] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants