Make WordPress Core

Opened 7 weeks ago

Closed 7 weeks ago

Last modified 12 days ago

#65002 closed defect (bug) (fixed)

Connectors: Replace plugin.slug with plugin.file and harden plugin data handling

Reported by: jorgefilipecosta's profile jorgefilipecosta Owned by: jorgefilipecosta's profile jorgefilipecosta
Milestone: 7.0 Priority: normal
Severity: normal Version: trunk
Component: General Keywords: has-patch has-unit-tests dev-reviewed
Focuses: Cc:

Description

The Connectors API currently uses plugin.slug (the WordPress.org slug) to identify plugins associated with a connector. This is insufficient because:

  • It requires a get_plugins() call to map slugs to file paths for status checks, adding unnecessary overhead.
  • The slug alone doesn't uniquely identify a plugin file.

This ticket replaces plugin.slug with plugin.file — the plugin's main file path relative to the plugins directory (e.g. akismet/akismet.php or hello.php). This simplifies the backend by allowing direct file_exists() and is_plugin_active() checks without the slug-to-file mapping step.

Changes

PHP (backend)

  1. PHPDoc: Update @type string $file documentation in wp_register_connector() and WP_Connector_Registry::register() to include a single-file plugin example ('hello.php').
  1. JS output: Stop stripping the .php extension from plugin.file in _wp_connectors_get_connector_script_module_data(). The JS output now matches the PHP registration value exactly (e.g. akismet/akismet.php instead of akismet/akismet). This avoids the confusing situation where file meant different things in PHP vs JS contexts.
  1. Registry validation: WP_Connector_Registry::register() now cherry-picks only the file key from the plugin array instead of storing whatever is passed. This ensures stored data always matches the documented shape and silently drops invalid keys.
  1. Test update: Update test_register_includes_plugin_data to use 'file' => 'my-plugin/my-plugin.php' instead of the outdated 'slug' => 'my-plugin'.

PR: https://github.com/WordPress/wordpress-develop/pull/11400

Testing

  • Run PHPUnit: phpunit --filter WP_Connector_Registry
  • Verify connectors page loads and shows correct plugin status (installed/not installed/active)
  • Verify install and activate flows still work for AI provider plugins

Change History (5)

This ticket was mentioned in PR #11400 on WordPress/wordpress-develop by @jorgefilipecosta.


7 weeks ago
#1

## Summary

  • Replace plugin.slug with plugin.file (the full plugin file path, e.g. akismet/akismet.php) in connector registrations
  • Simplify script module data: remove get_plugins() slug-to-file map, use file_exists() and is_plugin_active() directly
  • Add isInstalled to the frontend plugin data
  • Update PHPDoc for plugin type across registry and public API functions

Ticket: https://core.trac.wordpress.org/ticket/65002
## Test plan

  • [ ] Verify connectors page loads and shows correct plugin status
  • [ ] Verify install and activate flows still work for AI provider plugins

#2 @gziolo
7 weeks ago

  • Keywords dev-reviewed added

#3 @jorgefilipecosta
7 weeks ago

  • Owner set to jorgefilipecosta
  • Resolution set to fixed
  • Status changed from new to closed

In 62192:

Connectors: Replace plugin.slug with plugin.file in connector registration.

Use the plugin's main file path relative to the plugins directory
(e.g. akismet/akismet.php or hello.php) instead of the WordPress.org slug
to identify a connector's associated plugin.
This lets _wp_connectors_get_connector_script_module_data() check plugin
status with file_exists() and is_plugin_active() directly, removing the
get_plugins() slug-to-file mapping that was previously needed.

Props jorgefilipecosta, mukesh27, gziolo.
Fixes #65002.

#4 @jorgefilipecosta
7 weeks ago

In 62195:

Connectors: Replace plugin.slug with plugin.file in connector registration.

Use the plugin's main file path relative to the plugins directory
(e.g. akismet/akismet.php or hello.php) instead of the WordPress.org slug
to identify a connector's associated plugin.
This lets _wp_connectors_get_connector_script_module_data() check plugin
status with file_exists() and is_plugin_active() directly, removing the
get_plugins() slug-to-file mapping that was previously needed.

Props jorgefilipecosta, mukesh27, gziolo.
Fixes #65002.

#5 @jorbin
12 days ago

@jorgefilipecosta Please remember to follow the commit message guidelines ​https://make.wordpress.org/core/handbook/best-practices/commit-messages/ so that it's easy to track what has been merged.

Note: See TracTickets for help on using tickets.