Make WordPress Core


Ignore:
Timestamp:
04/01/2026 04:41:40 PM (5 months ago)
Author:
jorgefilipecosta
Message:

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.

Location:
branches/7.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/7.0

  • branches/7.0/src/wp-includes/connectors.php

    r62194 r62195  
    5959 *         Optional. Plugin data for install/activate UI.
    6060 *
    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').
    6263 *     }
    6364 * }
     
    7576 *     },
    7677 *     plugin?: array{
    77  *         slug: non-empty-string
     78 *         file: non-empty-string
    7879 *     }
    7980 * }
     
    119120 *             Optional. Plugin data for install/activate UI.
    120121 *
    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').
    122124 *         }
    123125 *     }
     
    136138 *     },
    137139 *     plugin?: array{
    138  *         slug: non-empty-string
     140 *         file: non-empty-string
    139141 *     }
    140142 * }>
     
    257259                        'type'           => 'ai_provider',
    258260                        'plugin'         => array(
    259                                 'slug' => 'ai-provider-for-anthropic',
     261                                'file' => 'ai-provider-for-anthropic/plugin.php',
    260262                        ),
    261263                        'authentication' => array(
     
    269271                        'type'           => 'ai_provider',
    270272                        'plugin'         => array(
    271                                 'slug' => 'ai-provider-for-google',
     273                                'file' => 'ai-provider-for-google/plugin.php',
    272274                        ),
    273275                        'authentication' => array(
     
    281283                        'type'           => 'ai_provider',
    282284                        'plugin'         => array(
    283                                 'slug' => 'ai-provider-for-openai',
     285                                'file' => 'ai-provider-for-openai/plugin.php',
    284286                        ),
    285287                        'authentication' => array(
     
    637639        $registry = AiClient::defaultRegistry();
    638640
    639         // Build a slug-to-file map for plugin installation status.
    640         if ( ! function_exists( 'get_plugins' ) ) {
     641        if ( ! function_exists( 'is_plugin_active' ) ) {
    641642                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;
    647643        }
    648644
     
    677673                );
    678674
    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 );
    685679
    686680                        $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,
    691683                                'isActivated' => $is_activated,
    692684                        );
Note: See TracChangeset for help on using the changeset viewer.