Skip to content

Commit

Permalink
Plugin: Guard code from redeclaration errors after WP core merge (#39888
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gziolo authored Mar 31, 2022
1 parent 30f900e commit 27b4e83
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 134 deletions.
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
4 changes: 4 additions & 0 deletions lib/compat/wordpress-6.0/class-wp-webfonts-provider-local.php
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
Loading

0 comments on commit 27b4e83

Please sign in to comment.