diff --git a/environments/mocks/mu-plugins/wporg-plugin-author-import.php b/environments/mocks/mu-plugins/wporg-plugin-author-import.php new file mode 100644 index 0000000000..21c50f3a64 --- /dev/null +++ b/environments/mocks/mu-plugins/wporg-plugin-author-import.php @@ -0,0 +1,117 @@ + $slug, + '_embed' => 1, + 'per_page' => 1, + ), + 'https://wordpress.org/plugins/wp-json/wp/v2/plugin' + ); + + $response = wp_remote_get( $url, array( 'timeout' => 30 ) ); + if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { + return null; + } + + $results = json_decode( wp_remote_retrieve_body( $response ), true ); + if ( empty( $results[0]['_embedded']['author'][0]['slug'] ) ) { + return null; + } + + return $results[0]['_embedded']['author'][0]; +} + +/** + * Find or create a local user matching the given wp.org author payload. + * + * @param array $author Author array from the REST API (must include slug). + * @return int User ID, or 0 on failure. + */ +function ensure_local_user( array $author ) { + $slug = $author['slug']; + + $existing = get_user_by( 'slug', $slug ); + if ( $existing ) { + return (int) $existing->ID; + } + + $user_id = wp_insert_user( array( + 'user_login' => $slug, + 'user_nicename' => $slug, + 'user_email' => $slug . '@example.invalid', + 'display_name' => $author['name'] ?? $slug, + 'user_url' => $author['url'] ?? '', + 'user_pass' => wp_generate_password(), + 'role' => 'subscriber', + ) ); + + if ( is_wp_error( $user_id ) ) { + fwrite( STDERR, "[wporg-plugin-author-import] wp_insert_user failed for {$slug}: " . $user_id->get_error_message() . "\n" ); + return 0; + } + + return (int) $user_id; +} diff --git a/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php b/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php index d1e30f3c4b..9adf692411 100644 --- a/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php +++ b/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php @@ -785,14 +785,16 @@ public function register_admin_metaboxes( $post_type, $post ) { array( __NAMESPACE__ . '\Metabox\Author_Notice', 'display' ), 'plugin', 'normal', 'high' ); - } - add_meta_box( - 'plugin-elasticsearch', - __( 'ElasticSearch Index', 'wporg-plugins' ), - array( __NAMESPACE__ . '\Metabox\Elasticsearch', 'display' ), - 'plugin', 'normal', 'low' - ); + if ( class_exists( '\Automattic\Jetpack\Search\Classic_Search' ) ) { + add_meta_box( + 'plugin-elasticsearch', + __( 'ElasticSearch Index', 'wporg-plugins' ), + array( __NAMESPACE__ . '\Metabox\Elasticsearch', 'display' ), + 'plugin', 'normal', 'low' + ); + } + } // Remove unnecessary metaboxes. remove_meta_box( 'commentsdiv', 'plugin', 'normal' );