Skip to content

Meta: Add support for site meta in get_object_subtype() - #12612

Closed
SainathPoojary wants to merge 8 commits into
WordPress:trunkfrom
SainathPoojary:fix/44387
Closed

SainathPoojary wants to merge 8 commits into
WordPress:trunkfrom
SainathPoojary:fix/44387

Conversation

@SainathPoojary

@SainathPoojary SainathPoojary commented Jul 20, 2026

Copy link
Copy Markdown

This PR adds subtype support for site meta to register_meta() by updating get_object_subtype().
Since site meta was introduced, it has lacked subtype awareness. This change adds a blog case to get_object_subtype(), which validates that multisite is active and the given site ID actually exists before returning the subtype. It also includes an explicit guard for $object_id <= 0 to prevent get_site() from incorrectly resolving to the current site.
Includes unit tests for validation and integration with get_registered_metadata().

Trac ticket: #44387

Use of AI Tools

AI assistance: Yes
Tool(s): GitHub Copilot
Model(s): Gemini, Claude
Used for: Checking for potential edge cases, drafting the PR description, and assisting with local code review. The final implementation and testing were written and executed manually by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI review requested due to automatic review settings July 21, 2026 11:53

Copilot AI 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.

Pull request overview

This PR extends the metadata API’s get_object_subtype() to recognize multisite “site meta” objects (meta type 'blog'), enabling subtype-aware behavior for site meta and adding PHPUnit coverage for the new behavior.

Changes:

  • Add a 'blog' branch to get_object_subtype() that returns 'blog' for valid sites on multisite installs.
  • Update meta registration tests to create/delete a site in multisite and add new multisite-only assertions for blog/site subtype handling.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/wp-includes/meta.php Adds 'blog' handling to get_object_subtype() by checking multisite and validating the site via get_site().
tests/phpunit/tests/meta/registerMeta.php Adds multisite setup/teardown for a created site and new tests targeting subtype behavior for 'blog' meta.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/phpunit/tests/meta/registerMeta.php Outdated
Comment thread tests/phpunit/tests/meta/registerMeta.php
Copilot AI review requested due to automatic review settings July 21, 2026 15:19

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/wp-includes/meta.php
Comment thread tests/phpunit/tests/meta/registerMeta.php
Copilot AI review requested due to automatic review settings July 21, 2026 15:35

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/wp-includes/meta.php
Copilot AI review requested due to automatic review settings July 22, 2026 12:49
@SainathPoojary
SainathPoojary marked this pull request as ready for review July 22, 2026 12:49
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

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 sainathpoojary, spacedmonkey.

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

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@spacedmonkey spacedmonkey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR needs rebasing. It also need site meta functions adding like this.

/**
 * Registers a meta key for sites.
 *
 * @since 7.2.0
 *
 * @param string $meta_key The meta key to register.
 * @param array  $args     Data used to describe the meta key when registered. See
 *                         {@see register_meta()} for a list of supported arguments.
 * @return bool True if the meta key was successfully registered, false if not.
 */
function register_site_meta( $meta_key, array $args ) {
	return register_meta( 'blog', $meta_key, $args );
}

/**
 * Unregisters a meta key for sites.
 *
 * @since 7.2.0
 *
 * @param string $meta_key The meta key to unregister.
 * @return bool True on success, false if the meta key was not previously registered.
 */
function unregister_site_meta( $meta_key ) {
	return unregister_meta_key( 'blog', $meta_key );
}

Comment thread tests/phpunit/tests/meta/registerMeta.php

@spacedmonkey spacedmonkey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to me.

@spacedmonkey

Copy link
Copy Markdown
Member

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.

3 participants

Sponsor
SponsoredKunjungi sekarang
Promo