Skip to content

Commit

Permalink
Move all the remaining code in lib
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 4, 2022
1 parent bfa2120 commit 9d8938f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 86 deletions.
62 changes: 60 additions & 2 deletions lib/compat/wordpress-5.9/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,71 @@
* @package gutenberg
*/

if ( ! defined( 'ABSPATH' ) ) {
die( 'Silence is golden.' );
}

/**
* Registers the REST API routes for URL Details.
*/
function gutenberg_register_url_details_routes() {
$url_details_controller = new WP_REST_URL_Details_Controller();
$url_details_controller->register_routes();
}
add_action( 'rest_api_init', 'gutenberg_register_url_details_routes' );

/**
* Registers the menu locations REST API routes.
*/
function gutenberg_register_rest_menu_location() {
$nav_menu_location = new WP_REST_Menu_Locations_Controller();
$nav_menu_location->register_routes();
}
add_action( 'rest_api_init', 'gutenberg_register_rest_menu_location' );

/**
* Hook in to the nav menu item post type and enable a post type rest endpoint.
*
* @param array $args Current registered post type args.
* @param string $post_type Name of post type.
*
* @return array
*/
function wp_api_nav_menus_post_type_args( $args, $post_type ) {
if ( 'nav_menu_item' === $post_type ) {
$args['show_in_rest'] = true;
$args['rest_base'] = 'menu-items';
$args['rest_controller_class'] = 'WP_REST_Menu_Items_Controller';
}

return $args;
}
add_filter( 'register_post_type_args', 'wp_api_nav_menus_post_type_args', 10, 2 );

/**
* Hook in to the nav_menu taxonomy and enable a taxonomy rest endpoint.
*
* @param array $args Current registered taxonomy args.
* @param string $taxonomy Name of taxonomy.
*
* @return array
*/
function wp_api_nav_menus_taxonomy_args( $args, $taxonomy ) {
if ( 'nav_menu' === $taxonomy ) {
$args['show_in_rest'] = true;
$args['rest_base'] = 'menus';
$args['rest_controller_class'] = 'WP_REST_Menus_Controller';
}

return $args;
}
add_filter( 'register_taxonomy_args', 'wp_api_nav_menus_taxonomy_args', 10, 2 );

/**
* Exposes the site logo to the Gutenberg editor through the WordPress REST
* API. This is used for fetching this information when user has no rights
* to update settings.
*
* @since 10.9
*
* @param WP_REST_Response $response Response data served by the WordPress REST index endpoint.
* @return WP_REST_Response
*/
Expand Down
27 changes: 27 additions & 0 deletions lib/compat/wordpress-6.0/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Generic helper functions.
*
* @package WordPress
* @since 6.0.0
*/

if ( ! function_exists( 'wp_recursive_ksort' ) ) {
/**
* Sorts the keys of an array alphabetically.
* The array is passed by reference so it doesn't get returned
* which mimics the behaviour of ksort.
*
* @since 6.0.0
*
* @param array $array The array to sort, passed by reference.
*/
function wp_recursive_ksort( &$array ) {
foreach ( $array as &$value ) {
if ( is_array( $value ) ) {
wp_recursive_ksort( $value );
}
}
ksort( $array );
}
}
23 changes: 0 additions & 23 deletions lib/compat/wordpress-6.0/utils.php

This file was deleted.

59 changes: 0 additions & 59 deletions lib/rest-api.php → lib/experimental/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,6 @@
die( 'Silence is golden.' );
}


/**
* Registers the REST API routes for URL Details.
*
* @since 5.0.0
*/
function gutenberg_register_url_details_routes() {
$url_details_controller = new WP_REST_URL_Details_Controller();
$url_details_controller->register_routes();
}
add_action( 'rest_api_init', 'gutenberg_register_url_details_routes' );

/**
* Registers the menu locations REST API routes.
*/
function gutenberg_register_rest_menu_location() {
$nav_menu_location = new WP_REST_Menu_Locations_Controller();
$nav_menu_location->register_routes();
}
add_action( 'rest_api_init', 'gutenberg_register_rest_menu_location' );

/**
* Registers the navigation areas REST API routes.
*/
Expand Down Expand Up @@ -58,44 +37,6 @@ function gutenberg_register_block_editor_settings() {
}
add_action( 'rest_api_init', 'gutenberg_register_block_editor_settings' );

/**
* Hook in to the nav menu item post type and enable a post type rest endpoint.
*
* @param array $args Current registered post type args.
* @param string $post_type Name of post type.
*
* @return array
*/
function wp_api_nav_menus_post_type_args( $args, $post_type ) {
if ( 'nav_menu_item' === $post_type ) {
$args['show_in_rest'] = true;
$args['rest_base'] = 'menu-items';
$args['rest_controller_class'] = 'WP_REST_Menu_Items_Controller';
}

return $args;
}
add_filter( 'register_post_type_args', 'wp_api_nav_menus_post_type_args', 10, 2 );

/**
* Hook in to the nav_menu taxonomy and enable a taxonomy rest endpoint.
*
* @param array $args Current registered taxonomy args.
* @param string $taxonomy Name of taxonomy.
*
* @return array
*/
function wp_api_nav_menus_taxonomy_args( $args, $taxonomy ) {
if ( 'nav_menu' === $taxonomy ) {
$args['show_in_rest'] = true;
$args['rest_base'] = 'menus';
$args['rest_controller_class'] = 'WP_REST_Menus_Controller';
}

return $args;
}
add_filter( 'register_taxonomy_args', 'wp_api_nav_menus_taxonomy_args', 10, 2 );

/**
* Shim for get_sample_permalink() to add support for auto-draft status.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require_once __DIR__ . '/compat/wordpress-5.9/class-wp-rest-url-details-controller.php';
}

require __DIR__ . '/rest-api.php';
require __DIR__ . '/experimental/rest-api.php';
require __DIR__ . '/compat/wordpress-5.9/rest-api.php';
}

Expand Down Expand Up @@ -100,7 +100,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.0/class-gutenberg-rest-edit-site-export-controller.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-rest-block-patterns-controller.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-rest-block-pattern-categories-controller.php';
require __DIR__ . '/compat/wordpress-6.0/utils.php';
require __DIR__ . '/compat/wordpress-6.0/functions.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php';
require __DIR__ . '/compat/wordpress-6.0/rest-api.php';
require __DIR__ . '/compat/wordpress-6.0/block-patterns.php';
Expand Down

0 comments on commit 9d8938f

Please sign in to comment.