Skip to content

Commit b2cc1df

Browse files
REST API: Introduce plugin management and block directory endpoints.
These endpoints facilitate the Block Directory Inserter feature in Gutenberg. Users can now install, activate, deactivate, and delete plugins over the REST API. The block directoryendpoint allows searching for available blocks from the WordPress.org block directory. Props cklee, talldanwp, noisysocks, joen, soean, youknowriad, dufresnesteven, gziolo, dd32, tellyworth, ryelle, spacedmonkey, TimothyBlynJacobs. Fixes #50321. git-svn-id: https://develop.svn.wordpress.org/trunk@48242 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 48f0e74 commit b2cc1df

File tree

11 files changed

+2953
-8
lines changed

11 files changed

+2953
-8
lines changed

src/wp-admin/edit-form-blocks.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,14 @@
361361
);
362362
wp_tinymce_inline_scripts();
363363
wp_enqueue_editor();
364+
wp_enqueue_script( 'wp-block-directory' );
364365

365366
/**
366367
* Styles
367368
*/
368369
wp_enqueue_style( 'wp-edit-post' );
369370
wp_enqueue_style( 'wp-format-library' );
371+
wp_enqueue_style( 'wp-block-directory' );
370372

371373
/**
372374
* Fires after block assets have been enqueued for the editing interface.

src/wp-admin/includes/plugin-install.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,17 @@ function plugins_api( $action, $args = array() ) {
173173
$request = wp_remote_get( $url, $http_args );
174174

175175
if ( $ssl && is_wp_error( $request ) ) {
176-
trigger_error(
177-
sprintf(
178-
/* translators: %s: Support forums URL. */
179-
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
180-
__( 'https://wordpress.org/support/forums/' )
181-
) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
182-
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
183-
);
176+
if ( ! wp_is_json_request() ) {
177+
trigger_error(
178+
sprintf(
179+
/* translators: %s: Support forums URL. */
180+
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
181+
__( 'https://wordpress.org/support/forums/' )
182+
) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
183+
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
184+
);
185+
}
186+
184187
$request = wp_remote_get( $http_url, $http_args );
185188
}
186189

src/wp-includes/rest-api.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ function create_initial_rest_routes() {
285285
$controller = new WP_REST_Themes_Controller;
286286
$controller->register_routes();
287287

288+
// Plugins.
289+
$controller = new WP_REST_Plugins_Controller();
290+
$controller->register_routes();
291+
292+
// Block Directory.
293+
$controller = new WP_REST_Block_Directory_Controller();
294+
$controller->register_routes();
295+
288296
}
289297

290298
/**

0 commit comments

Comments
 (0)