Skip to content

Plugin Directory: Hide ElasticSearch metabox where unusable + populate post_author for CLI inserts#9

Open
dd32 wants to merge 3 commits into
trunkfrom
add/claude/local-plugin-author-import
Open

Plugin Directory: Hide ElasticSearch metabox where unusable + populate post_author for CLI inserts#9
dd32 wants to merge 3 commits into
trunkfrom
add/claude/local-plugin-author-import

Conversation

@dd32
Copy link
Copy Markdown
Owner

@dd32 dd32 commented May 14, 2026

Two small fixes around the wp-admin plugin edit screen, motivated by PHP warnings showing up when running locally:

Hide the ElasticSearch metabox when it cannot be useful

  • For plugins in draft or pending status there is nothing indexed yet, so the metabox just shows "Not indexed" with a Reindex button that will not help.
  • On non-production/staging environments without Jetpack Search available locally, the AJAX call cannot reach the index at all.

The metabox now registers only when neither of those conditions apply.

Local env mu-plugin: populate post_author for CLI inserts

The production import-plugin.php --create path calls Plugin_Directory::create_plugin_post() with only post_name, so wp_insert_post() defaults post_author to get_current_user_id() — which is 0 in CLI. Locally-imported plugin posts end up with no resolvable author, which then produces a wall of PHP warnings in the Review Tools metabox ($author->user_email, ->user_registered, etc on false).

The new environments/mocks/mu-plugins/wporg-plugin-author-import.php hooks wp_insert_post_data (CLI-only, new inserts, missing post_author) and resolves the author from https://wordpress.org/plugins/wp-json/wp/v2/plugin?slug=...&_embed=1, creating a matching local user if needed.

Test plan

  • In wp-admin on a draft plugin, the ElasticSearch metabox is hidden.
  • On a local env without Jetpack Search available, the ElasticSearch metabox is hidden for any plugin.
  • In a production-mode local env (or one with Jetpack Search active), the metabox still appears for published plugins.
  • Running wp eval-file wp-content/plugin-directory/bin/import-plugin.php --plugin=<slug> --create against a fresh local DB results in the plugin post being created with post_author set to the matching wp.org user (auto-created locally).
  • The Review Tools metabox for that plugin opens without PHP warnings.

🤖 Generated with Claude Code

dd32 and others added 2 commits May 14, 2026 16:19
…eful.

Skip rendering for draft/pending plugins (nothing is indexed yet) and on local
environments without Jetpack Search available (the AJAX call would just report
that Jetpack Search is unavailable).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… inserts.

The production import-plugin.php --create path calls create_plugin_post() with
only post_name, so wp_insert_post() defaults post_author to get_current_user_id(),
which is 0 in CLI. This leaves the plugin post with no resolvable author, which
in turn produces a string of PHP warnings in the wp-admin Review Tools metabox.

Add a local mu-plugin that hooks wp_insert_post_data: when a new plugin post is
being inserted in CLI without a post_author, fetch the embedded author from the
wp.org REST API and create the matching local user.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
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 dd32.

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

Move it into the existing post-approval block (alongside committers, support
reps, etc.) so it only renders for plugins that have moved past new/pending,
and keep the class_exists guard so it stays hidden when Jetpack Search is not
loaded locally.

Co-Authored-By: Claude Opus 4.7 (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