Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin: Guard code from redeclaration errors after WP core merge #39888

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@
/**
* REST API: WP_REST_Block_Pattern_Catergories_Controller class
*
* @subpackage REST_API
* @package WordPress
* @subpackage REST_API
* @since 6.0.0
*/

if ( class_exists( 'WP_REST_Block_Pattern_Categories_Controller' ) ) {
return;
}

/**
* Core class used to access block pattern categories via the REST API.
*
* @see WP_REST_Controller
*
* @since 6.0.0
*/
class WP_REST_Block_Pattern_Categories_Controller extends WP_REST_Controller {

/**
* Constructor.
*
* @since 6.0.0
*/
public function __construct() {
$this->namespace = '__experimental';
Expand All @@ -25,6 +34,8 @@ public function __construct() {
* Registers the routes for the objects of the controller.
*
* @see register_rest_route()
*
* @since 6.0.0
*/
public function register_routes() {
register_rest_route(
Expand All @@ -44,6 +55,8 @@ public function register_routes() {
/**
* Checks whether a given request has permission to read block patterns.
*
* @since 6.0.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|bool True if the request has read access, WP_Error object otherwise.
Expand All @@ -69,6 +82,8 @@ public function get_items_permissions_check( $request ) { // phpcs:ignore Variab
/**
* Retrieves all block pattern categories.
*
* @since 6.0.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
Expand All @@ -86,6 +101,8 @@ public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAna
/**
* Prepare a raw block pattern category before it gets output in a REST API response.
*
* @since 6.0.0
*
* @param object $item Raw category as registered, before any changes.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response
Expand All @@ -109,6 +126,8 @@ public function prepare_item_for_response( $item, $request ) {
/**
* Retrieves the block pattern category schema, conforming to JSON Schema.
*
* @since 6.0.0
*
* @return array Item schema data.
*/
public function get_item_schema() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
/**
* REST API: WP_REST_Block_Patterns_Controller class
*
* @subpackage REST_API
* @package WordPress
* @subpackage REST_API
* @since 6.0.0
*/

if ( class_exists( 'WP_REST_Block_Patterns_Controller' ) ) {
return;
}

/**
* Core class used to access block patterns via the REST API.
*
* @see WP_REST_Controller
*
* @since 6.0.0
*/
class WP_REST_Block_Patterns_Controller extends WP_REST_Controller {

Expand All @@ -25,6 +32,8 @@ public function __construct() {
* Registers the routes for the objects of the controller.
*
* @see register_rest_route()
*
* @since 6.0.0
*/
public function register_routes() {
register_rest_route(
Expand All @@ -44,6 +53,8 @@ public function register_routes() {
/**
* Checks whether a given request has permission to read block patterns.
*
* @since 6.0.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|bool True if the request has read access, WP_Error object otherwise.
Expand All @@ -69,6 +80,8 @@ public function get_items_permissions_check( $request ) { // phpcs:ignore Variab
/**
* Retrieves all block patterns.
*
* @since 6.0.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
Expand All @@ -91,6 +104,8 @@ public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAna
/**
* Prepare a raw block pattern before it gets output in a REST API response.
*
* @since 6.0.0
*
* @param object $item Raw pattern as registered, before any changes.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response
Expand Down Expand Up @@ -123,6 +138,8 @@ public function prepare_item_for_response( $item, $request ) {
/**
* Retrieves the block pattern schema, conforming to JSON Schema.
*
* @since 6.0.0
*
* @return array Item schema data.
*/
public function get_item_schema() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @since 6.0.0
*/

if ( class_exists( 'WP_Webfonts_Provider_Local' ) ) {
return;
}

/**
* A core bundled provider for generating `@font-face` styles
* from locally-hosted font files.
Expand Down
4 changes: 4 additions & 0 deletions lib/compat/wordpress-6.0/class-wp-webfonts-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @since 6.0.0
*/

if ( class_exists( 'WP_Webfonts_Provider' ) ) {
return;
}

/**
* Abstract class for Webfonts API providers.
*
Expand Down
34 changes: 33 additions & 1 deletion lib/compat/wordpress-6.0/class-wp-webfonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@
/**
* Webfonts API class.
*
* @package Gutenberg
* @package WordPress
* @subpackage WebFonts
* @since 6.0.0
*/

if ( class_exists( 'WP_Webfonts' ) ) {
return;
}

/**
* Class WP_Webfonts
*
* @since 6.0.0
*/
class WP_Webfonts {

/**
* An array of registered webfonts.
*
* @since 6.0.0
*
* @access private
* @var array
*/
Expand All @@ -21,6 +31,8 @@ class WP_Webfonts {
/**
* An array of registered providers.
*
* @since 6.0.0
*
* @access private
* @var array
*/
Expand All @@ -29,12 +41,16 @@ class WP_Webfonts {
/**
* Stylesheet handle.
*
* @since 6.0.0
*
* @var string
*/
private $stylesheet_handle = '';

/**
* Init.
*
* @since 6.0.0
*/
public function init() {

Expand All @@ -58,6 +74,8 @@ public function init() {
/**
* Get the list of fonts.
*
* @since 6.0.0
*
* @return array
*/
public function get_fonts() {
Expand All @@ -67,6 +85,8 @@ public function get_fonts() {
/**
* Get the list of providers.
*
* @since 6.0.0
*
* @return array
*/
public function get_providers() {
Expand All @@ -76,6 +96,8 @@ public function get_providers() {
/**
* Register a webfont.
*
* @since 6.0.0
*
* @param array $font The font arguments.
*/
public function register_font( $font ) {
Expand All @@ -89,6 +111,8 @@ public function register_font( $font ) {
/**
* Get the font ID.
*
* @since 6.0.0
*
* @param array $font The font arguments.
* @return string
*/
Expand All @@ -99,6 +123,8 @@ public function get_font_id( $font ) {
/**
* Validate a font.
*
* @since 6.0.0
*
* @param array $font The font arguments.
*
* @return array|false The validated font arguments, or false if the font is invalid.
Expand Down Expand Up @@ -183,6 +209,8 @@ public function validate_font( $font ) {
/**
* Register a provider.
*
* @since 6.0.0
*
* @param string $provider The provider name.
* @param string $class The provider class name.
*
Expand All @@ -198,6 +226,8 @@ public function register_provider( $provider, $class ) {

/**
* Generate and enqueue webfonts styles.
*
* @since 6.0.0
*/
public function generate_and_enqueue_styles() {
// Generate the styles.
Expand All @@ -218,6 +248,8 @@ public function generate_and_enqueue_styles() {

/**
* Generate and enqueue editor styles.
*
* @since 6.0.0
*/
public function generate_and_enqueue_editor_styles() {
// Generate the styles.
Expand Down
17 changes: 13 additions & 4 deletions lib/compat/wordpress-6.0/webfonts.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
/**
* Webfonts API: Webfonts functions
*
* @since 6.0.0
* Webfonts API functions.
*
* @package WordPress
* @subpackage Webfonts
* @subpackage WebFonts
* @since 6.0.0
*/

if ( ! function_exists( 'wp_webfonts' ) ) {
/**
* Instantiates the webfonts controller, if not already set, and returns it.
*
Expand All @@ -25,7 +25,9 @@ function wp_webfonts() {

return $wp_webfonts;
}
}

if ( ! function_exists( 'wp_register_webfonts' ) ) {
/**
* Registers a collection of webfonts.
*
Expand Down Expand Up @@ -69,7 +71,9 @@ function wp_register_webfonts( array $webfonts = array() ) {
wp_register_webfont( $webfont );
}
}
}

if ( ! function_exists( 'wp_register_webfont' ) ) {
/**
* Registers a single webfont.
*
Expand All @@ -96,7 +100,9 @@ function wp_register_webfonts( array $webfonts = array() ) {
function wp_register_webfont( array $webfont ) {
wp_webfonts()->register_font( $webfont );
}
}

if ( ! function_exists( 'wp_register_webfont_provider' ) ) {
/**
* Registers a custom font service provider.
*
Expand Down Expand Up @@ -125,7 +131,9 @@ function wp_register_webfont( array $webfont ) {
function wp_register_webfont_provider( $name, $classname ) {
return wp_webfonts()->register_provider( $name, $classname );
}
}

if ( ! function_exists( 'wp_get_webfont_providers' ) ) {
/**
* Gets all registered providers.
*
Expand All @@ -146,6 +154,7 @@ function wp_register_webfont_provider( $name, $classname ) {
function wp_get_webfont_providers() {
return wp_webfonts()->get_providers();
}
}

/**
* Add webfonts mime types.
Expand Down