Fix: Only auto register settings if the plugin the connector references is installed and active.#11564
Conversation
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
1ca586c to
03be585
Compare
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| continue; | ||
| } | ||
| } else { | ||
| if ( ! isset( $connector_data['plugin']['is_active'] ) || ! is_callable( $connector_data['plugin']['is_active'] ) ) { |
There was a problem hiding this comment.
As most non-AI connectors will be registered by the plugin itself, this is probably best treated as an optional argument with the default __return_true.
As is, an active plugin registering a connector will need to do something along the lines of the following even though the registration of the connector indicates the plugin is active:
<?php
/**
* Plugin name: My connector
*/
function my_plugin_register_connector( $registry ) {
$args = [...];
$args['plugin']['is_active'] = function() { return function_exists( 'my_plugin_register_connector' ); };
// etc
}
add_action( 'wp_connectors_init', 'my_plugin_register_connector' );There was a problem hiding this comment.
Good point @peterwilsoncc will make the required updates
8093a56 to
5668fdc
Compare
5668fdc to
5bb886d
Compare
Collapse the AI/non-AI branches in _wp_register_default_connector_settings() into a single is_active callback check. AI providers already get an is_active callback wired up at registration that delegates to the AI Client registry, so one path covers both cases. Add tests for is_active returning true (setting registered) and false (setting skipped).
The connector registry now defaults plugin.is_active to __return_true when omitted, so the "is_active missing" scenario can't reach _wp_register_default_connector_settings(). The remaining returns_true / returns_false tests cover the gate's actual branches.
gziolo
left a comment
There was a problem hiding this comment.
That's much nicer and more flexible 👍🏻
Summary
Ticket: https://core.trac.wordpress.org/ticket/65099
Testing