| @@ -10,38 +10,86 @@ | ||
| 10 | 10 | die( 'Silence is golden.' ); |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | - * Overrides the REST controller for the `wp_global_styles` post type. | |
| 14 | + * Handle a failing oEmbed proxy request to try embedding as a shortcode. | |
| 15 | 15 | * |
| 16 | - * @param array $args Array of arguments for registering a post type. | |
| 17 | - * See the register_post_type() function for accepted arguments. | |
| 16 | + * @see https://core.trac.wordpress.org/ticket/45447 | |
| 18 | 17 | * |
| 19 | - * @return array Array of arguments for registering a post type. | |
| 18 | + * @since 2.3.0 | |
| 19 | + * | |
| 20 | + * @param WP_HTTP_Response|WP_Error $response The REST Request response. | |
| 21 | + * @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server). | |
| 22 | + * @param WP_REST_Request $request Request used to generate the response. | |
| 23 | + * @return WP_HTTP_Response|object|WP_Error The REST Request response. | |
| 20 | 24 | */ |
| 21 | -function gutenberg_override_global_styles_endpoint( array $args ): array { | |
| 22 | - $args['rest_controller_class'] = 'WP_REST_Global_Styles_Controller_Gutenberg'; | |
| 23 | - $args['late_route_registration'] = true; | |
| 24 | - $args['show_in_rest'] = true; | |
| 25 | - $args['rest_base'] = 'global-styles'; | |
| 25 | +function gutenberg_filter_oembed_result( $response, $handler, $request ) { | |
| 26 | + if ( ! is_wp_error( $response ) || 'oembed_invalid_url' !== $response->get_error_code() || | |
| 27 | + '/oembed/1.0/proxy' !== $request->get_route() ) { | |
| 28 | + return $response; | |
| 29 | + } | |
| 26 | 30 | |
| 27 | - return $args; | |
| 31 | + // Try using a classic embed instead. | |
| 32 | + global $wp_embed; | |
| 33 | + $html = $wp_embed->shortcode( array(), $_GET['url'] ); | |
| 34 | + if ( ! $html ) { | |
| 35 | + return $response; | |
| 36 | + } | |
| 37 | + | |
| 38 | + global $wp_scripts; | |
| 39 | + | |
| 40 | + // Check if any scripts were enqueued by the shortcode, and include them in | |
| 41 | + // the response. | |
| 42 | + $enqueued_scripts = array(); | |
| 43 | + foreach ( $wp_scripts->queue as $script ) { | |
| 44 | + $enqueued_scripts[] = $wp_scripts->registered[ $script ]->src; | |
| 45 | + } | |
| 46 | + | |
| 47 | + return array( | |
| 48 | + 'provider_name' => __( 'Embed Handler', 'gutenberg' ), | |
| 49 | + 'html' => $html, | |
| 50 | + 'scripts' => $enqueued_scripts, | |
| 51 | + ); | |
| 28 | 52 | } |
| 29 | -add_filter( 'register_wp_global_styles_post_type_args', 'gutenberg_override_global_styles_endpoint' ); | |
| 53 | +add_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result', 10, 3 ); | |
| 30 | 54 | |
| 55 | + | |
| 56 | + | |
| 31 | 57 | /** |
| 32 | - * Registers the Edit Site Export REST API routes. | |
| 58 | + * Start: Include for phase 2 | |
| 33 | 59 | */ |
| 34 | -function gutenberg_register_edit_site_export_controller_endpoints() { | |
| 35 | - $edit_site_export_controller = new WP_REST_Edit_Site_Export_Controller_Gutenberg(); | |
| 36 | - $edit_site_export_controller->register_routes(); | |
| 60 | +/** | |
| 61 | + * Registers the REST API routes needed by the legacy widget block. | |
| 62 | + * | |
| 63 | + * @since 5.0.0 | |
| 64 | + */ | |
| 65 | +function gutenberg_register_rest_widget_updater_routes() { | |
| 66 | + $widget_forms = new WP_REST_Widget_Forms(); | |
| 67 | + $widget_forms->register_routes(); | |
| 37 | 68 | } |
| 38 | -add_action( 'rest_api_init', 'gutenberg_register_edit_site_export_controller_endpoints' ); | |
| 69 | +add_action( 'rest_api_init', 'gutenberg_register_rest_widget_updater_routes' ); | |
| 39 | 70 | |
| 40 | 71 | /** |
| 41 | - * Registers the Icons Registry REST API routes. | |
| 72 | + * Registers the widget area REST API routes. | |
| 73 | + * | |
| 74 | + * @since 5.7.0 | |
| 42 | 75 | */ |
| 43 | -function gutenberg_register_icon_controller_endpoints() { | |
| 44 | - $icons_controller = new WP_REST_Icons_Controller_Gutenberg(); | |
| 45 | - $icons_controller->register_routes(); | |
| 76 | +function gutenberg_register_rest_widget_areas() { | |
| 77 | + $widget_areas_controller = new WP_REST_Widget_Areas_Controller(); | |
| 78 | + $widget_areas_controller->register_routes(); | |
| 46 | 79 | } |
| 47 | -add_action( 'rest_api_init', 'gutenberg_register_icon_controller_endpoints' ); | |
| 80 | +add_action( 'rest_api_init', 'gutenberg_register_rest_widget_areas' ); | |
| 81 | + | |
| 82 | +/** | |
| 83 | + * Registers the block directory. | |
| 84 | + * | |
| 85 | + * @since 6.5.0 | |
| 86 | + */ | |
| 87 | +function gutenberg_register_rest_block_directory() { | |
| 88 | + if ( ! gutenberg_is_experiment_enabled( 'gutenberg-block-directory' ) ) { | |
| 89 | + return; | |
| 90 | + } | |
| 91 | + | |
| 92 | + $block_directory_controller = new WP_REST_Block_Directory_Controller(); | |
| 93 | + $block_directory_controller->register_routes(); | |
| 94 | +} | |
| 95 | +add_filter( 'rest_api_init', 'gutenberg_register_rest_block_directory' ); | |