-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin: Correctly classify functionality in the
lib
folder (#39972)
* Plugin: Correctly classify functionality in the `lib` folder * Move code that should be backported to WordPress core as part of 6.0 * Update CODEOWNERS file * Move global styles from 6.0 to 5.9 as kses.php * Move more files to the compat layer * Make the style engine class experimental * Move all the remaining code in lib
- Loading branch information
Showing
19 changed files
with
231 additions
and
238 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 1 addition & 24 deletions
25
lib/compat.php → lib/compat/wordpress-5.9/block-gallery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
/** | ||
* Bootstraps Global Styles. | ||
* Filters to adjust the KSES behavior. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
/** | ||
* Extends the REST API endpoints. | ||
* | ||
* @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. | ||
* | ||
* @param WP_REST_Response $response Response data served by the WordPress REST index endpoint. | ||
* @return WP_REST_Response | ||
*/ | ||
function gutenberg_register_site_logo_to_rest_index( $response ) { | ||
$site_logo_id = get_theme_mod( 'custom_logo' ); | ||
$response->data['site_logo'] = $site_logo_id; | ||
if ( $site_logo_id ) { | ||
$response->add_link( | ||
'https://api.w.org/featuredmedia', | ||
rest_url( 'wp/v2/media/' . $site_logo_id ), | ||
array( | ||
'embeddable' => true, | ||
) | ||
); | ||
} | ||
return $response; | ||
} | ||
|
||
add_filter( 'rest_index', 'gutenberg_register_site_logo_to_rest_index' ); | ||
|
||
/** | ||
* Filters WP_User_Query arguments when querying users via the REST API. | ||
* | ||
* Allow using the has_published_post argument. | ||
* | ||
* @param array $prepared_args Array of arguments for WP_User_Query. | ||
* @param WP_REST_Request $request The REST API request. | ||
* | ||
* @return array Returns modified $prepared_args. | ||
*/ | ||
function gutenberg_rest_user_query_has_published_posts( $prepared_args, $request ) { | ||
if ( ! empty( $request['has_published_posts'] ) ) { | ||
$prepared_args['has_published_posts'] = ( true === $request['has_published_posts'] ) | ||
? get_post_types( array( 'show_in_rest' => true ), 'names' ) | ||
: (array) $request['has_published_posts']; | ||
} | ||
return $prepared_args; | ||
} | ||
add_filter( 'rest_user_query', 'gutenberg_rest_user_query_has_published_posts', 10, 2 ); | ||
|
||
/** | ||
* Filters REST API collection parameters for the users controller. | ||
* | ||
* @param array $query_params JSON Schema-formatted collection parameters. | ||
* | ||
* @return array Returns the $query_params with "has_published_posts". | ||
*/ | ||
function gutenberg_rest_user_collection_params_has_published_posts( $query_params ) { | ||
$query_params['has_published_posts'] = array( | ||
'description' => __( 'Limit result set to users who have published posts.', 'gutenberg' ), | ||
'type' => array( 'boolean', 'array' ), | ||
'items' => array( | ||
'type' => 'string', | ||
'enum' => get_post_types( array( 'show_in_rest' => true ), 'names' ), | ||
), | ||
); | ||
return $query_params; | ||
} | ||
add_filter( 'rest_user_collection_params', 'gutenberg_rest_user_collection_params_has_published_posts' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Updates client assets for the editor. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Registers vendor JavaScript files to be used as dependencies of the editor | ||
* and plugins. | ||
* | ||
* This function is called from a script during the plugin build process, so it | ||
* should not call any WordPress PHP functions. | ||
* | ||
* @since 13.0 | ||
* | ||
* @param WP_Scripts $scripts WP_Scripts instance. | ||
*/ | ||
function gutenberg_register_vendor_scripts( $scripts ) { | ||
$extension = SCRIPT_DEBUG ? '.js' : '.min.js'; | ||
|
||
gutenberg_override_script( | ||
$scripts, | ||
'react', | ||
gutenberg_url( 'build/vendors/react' . $extension ), | ||
// See https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react. | ||
SCRIPT_DEBUG ? array( 'wp-react-refresh-entry', 'wp-polyfill' ) : array( 'wp-polyfill' ) | ||
); | ||
gutenberg_override_script( | ||
$scripts, | ||
'react-dom', | ||
gutenberg_url( 'build/vendors/react-dom' . $extension ), | ||
array( 'react' ) | ||
); | ||
} | ||
add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.