Changeset 62192
- Timestamp:
- 04/01/2026 02:56:47 PM (10 hours ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
src/wp-includes/class-wp-connector-registry.php (modified) (3 diffs)
-
src/wp-includes/connectors.php (modified) (9 diffs)
-
tests/phpunit/tests/connectors/wpConnectorRegistry.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-connector-registry.php
r62180 r62192 41 41 * }, 42 42 * plugin?: array{ 43 * slug: non-empty-string43 * file: non-empty-string 44 44 * } 45 45 * } … … 110 110 * Optional. Plugin data for install/activate UI. 111 111 * 112 * @type string $slug The WordPress.org plugin slug. 112 * @type string $file The plugin's main file path relative to the plugins 113 * directory (e.g. 'akismet/akismet.php' or 'hello.php'). 113 114 * } 114 115 * } … … 243 244 } 244 245 245 if ( ! empty( $args['plugin'] ) && is_array( $args['plugin'] ) ) {246 $connector['plugin'] = $args['plugin'];246 if ( ! empty( $args['plugin'] ) && is_array( $args['plugin'] ) && ! empty( $args['plugin']['file'] ) ) { 247 $connector['plugin'] = array( 'file' => $args['plugin']['file'] ); 247 248 } 248 249 -
trunk/src/wp-includes/connectors.php
r62180 r62192 59 59 * Optional. Plugin data for install/activate UI. 60 60 * 61 * @type string $slug The WordPress.org plugin slug. 61 * @type string $file The plugin's main file path relative to the plugins 62 * directory (e.g. 'akismet/akismet.php' or 'hello.php'). 62 63 * } 63 64 * } … … 75 76 * }, 76 77 * plugin?: array{ 77 * slug: non-empty-string78 * file: non-empty-string 78 79 * } 79 80 * } … … 119 120 * Optional. Plugin data for install/activate UI. 120 121 * 121 * @type string $slug The WordPress.org plugin slug. 122 * @type string $file The plugin's main file path relative to the plugins 123 * directory (e.g. 'akismet/akismet.php' or 'hello.php'). 122 124 * } 123 125 * } … … 136 138 * }, 137 139 * plugin?: array{ 138 * slug: non-empty-string140 * file: non-empty-string 139 141 * } 140 142 * }> … … 257 259 'type' => 'ai_provider', 258 260 'plugin' => array( 259 ' slug' => 'ai-provider-for-anthropic',261 'file' => 'ai-provider-for-anthropic/plugin.php', 260 262 ), 261 263 'authentication' => array( … … 269 271 'type' => 'ai_provider', 270 272 'plugin' => array( 271 ' slug' => 'ai-provider-for-google',273 'file' => 'ai-provider-for-google/plugin.php', 272 274 ), 273 275 'authentication' => array( … … 281 283 'type' => 'ai_provider', 282 284 'plugin' => array( 283 ' slug' => 'ai-provider-for-openai',285 'file' => 'ai-provider-for-openai/plugin.php', 284 286 ), 285 287 'authentication' => array( … … 637 639 $registry = AiClient::defaultRegistry(); 638 640 639 // Build a slug-to-file map for plugin installation status. 640 if ( ! function_exists( 'get_plugins' ) ) { 641 if ( ! function_exists( 'is_plugin_active' ) ) { 641 642 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 642 }643 $plugin_files_by_slug = array();644 foreach ( array_keys( get_plugins() ) as $plugin_file ) {645 $slug = str_contains( $plugin_file, '/' ) ? dirname( $plugin_file ) : str_replace( '.php', '', $plugin_file );646 $plugin_files_by_slug[ $slug ] = $plugin_file;647 643 } 648 644 … … 677 673 ); 678 674 679 if ( ! empty( $connector_data['plugin']['slug'] ) ) { 680 $plugin_slug = $connector_data['plugin']['slug']; 681 $plugin_file = $plugin_files_by_slug[ $plugin_slug ] ?? null; 682 683 $is_installed = null !== $plugin_file; 684 $is_activated = $is_installed && is_plugin_active( $plugin_file ); 675 if ( ! empty( $connector_data['plugin']['file'] ) ) { 676 $file = $connector_data['plugin']['file']; 677 $is_installed = file_exists( wp_normalize_path( WP_PLUGIN_DIR . '/' . $file ) ); 678 $is_activated = $is_installed && is_plugin_active( $file ); 685 679 686 680 $connector_out['plugin'] = array( 687 'slug' => $plugin_slug, 688 'pluginFile' => $is_installed 689 ? ( str_ends_with( $plugin_file, '.php' ) ? substr( $plugin_file, 0, -4 ) : $plugin_file ) 690 : null, 681 'file' => $file, 682 'isInstalled' => $is_installed, 691 683 'isActivated' => $is_activated, 692 684 ); -
trunk/tests/phpunit/tests/connectors/wpConnectorRegistry.php
r62180 r62192 295 295 public function test_register_includes_plugin_data() { 296 296 $args = self::$default_args; 297 $args['plugin'] = array( ' slug' => 'my-plugin' );297 $args['plugin'] = array( 'file' => 'my-plugin/my-plugin.php' ); 298 298 299 299 $result = $this->registry->register( 'with-plugin', $args ); 300 300 301 301 $this->assertArrayHasKey( 'plugin', $result ); 302 $this->assertSame( array( ' slug' => 'my-plugin' ), $result['plugin'] );302 $this->assertSame( array( 'file' => 'my-plugin/my-plugin.php' ), $result['plugin'] ); 303 303 } 304 304
Note: See TracChangeset
for help on using the changeset viewer.