-
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.
- Loading branch information
Showing
5 changed files
with
422 additions
and
43 deletions.
There are no files selected for viewing
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,170 @@ | ||
<?php | ||
/** | ||
* Load API functions, register scripts and actions, etc. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
die( 'Silence is golden.' ); | ||
} | ||
|
||
define( 'IS_GUTENBERG_PLUGIN', true ); | ||
|
||
require_once __DIR__ . '/init.php'; | ||
require_once __DIR__ . '/upgrade.php'; | ||
|
||
/** | ||
* Checks whether the Gutenberg experiment is enabled. | ||
* | ||
* @since 6.7.0 | ||
* | ||
* @param string $name The name of the experiment. | ||
* | ||
* @return bool True when the experiment is enabled. | ||
*/ | ||
function gutenberg_is_experiment_enabled( $name ) { | ||
$experiments = get_option( 'gutenberg-experiments' ); | ||
return ! empty( $experiments[ $name ] ); | ||
} | ||
|
||
// These files only need to be loaded if within a rest server instance | ||
// which this class will exist if that is the case. | ||
if ( class_exists( 'WP_REST_Controller' ) ) { | ||
// WordPress 5.9 compat. | ||
require_once __DIR__ . '/compat/wordpress-5.9/class-wp-rest-global-styles-controller.php'; | ||
require_once __DIR__ . '/compat/wordpress-5.9/rest-active-global-styles.php'; | ||
if ( ! class_exists( 'WP_REST_Menus_Controller' ) ) { | ||
require_once __DIR__ . '/compat/wordpress-5.9/class-wp-rest-menus-controller.php'; | ||
} | ||
if ( ! class_exists( 'WP_REST_Menu_Items_Controller' ) ) { | ||
require_once __DIR__ . '/compat/wordpress-5.9/class-wp-rest-menu-items-controller.php'; | ||
} | ||
if ( ! class_exists( 'WP_REST_Menu_Locations_Controller' ) ) { | ||
require_once __DIR__ . '/compat/wordpress-5.9/class-wp-rest-menu-locations-controller.php'; | ||
} | ||
if ( ! class_exists( 'WP_REST_Block_Editor_Settings_Controller' ) ) { | ||
require_once __DIR__ . '/experimental/class-wp-rest-block-editor-settings-controller.php'; | ||
} | ||
if ( ! class_exists( 'WP_REST_URL_Details_Controller' ) ) { | ||
require_once __DIR__ . '/compat/wordpress-5.9/class-wp-rest-url-details-controller.php'; | ||
} | ||
require_once __DIR__ . '/compat/wordpress-5.9/rest-api.php'; | ||
|
||
// WordPress 6.0 compat. | ||
require_once __DIR__ . '/compat/wordpress-6.0/class-gutenberg-rest-global-styles-controller.php'; | ||
require_once __DIR__ . '/compat/wordpress-6.0/class-gutenberg-rest-pattern-directory-controller.php'; | ||
require_once __DIR__ . '/compat/wordpress-6.0/class-gutenberg-rest-edit-site-export-controller.php'; | ||
if ( ! class_exists( 'WP_REST_Block_Pattern_Categories_Controller' ) ) { | ||
require_once __DIR__ . '/compat/wordpress-6.0/class-wp-rest-block-pattern-categories-controller.php'; | ||
} | ||
require_once __DIR__ . '/compat/wordpress-6.0/rest-api.php'; | ||
|
||
// WordPress 6.1 compat. | ||
require_once __DIR__ . '/compat/wordpress-6.1/class-gutenberg-rest-block-patterns-controller.php'; | ||
require_once __DIR__ . '/compat/wordpress-6.1/class-gutenberg-rest-templates-controller.php'; | ||
require_once __DIR__ . '/compat/wordpress-6.1/class-wp-rest-custom-css-controller.php'; | ||
require_once __DIR__ . '/compat/wordpress-6.1/rest-api.php'; | ||
|
||
// Experimental. | ||
if ( ! class_exists( 'WP_Rest_Customizer_Nonces' ) ) { | ||
require_once __DIR__ . '/experimental/class-wp-rest-customizer-nonces.php'; | ||
} | ||
require_once __DIR__ . '/experimental/rest-api.php'; | ||
} | ||
|
||
require __DIR__ . '/experimental/editor-settings.php'; | ||
|
||
// WordPress 5.9 compat. | ||
require __DIR__ . '/compat/wordpress-5.9/polyfills.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/block-gallery.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/widget-render-api-endpoint/index.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/blocks.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/block-editor-settings.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/block-patterns.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/block-template-utils.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/default-editor-styles.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/register-global-styles-cpt.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/script-loader.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/json-file-decode.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/translate-settings-using-i18n-schema.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/global-styles-css-custom-properties.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/class-gutenberg-block-template.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/templates.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/template-parts.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/theme-templates.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/class-wp-theme-json-schema-gutenberg.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/class-wp-theme-json-5-9.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/class-wp-theme-json-resolver-5-9.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/theme.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/admin-menu.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/edit-site-page.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/block-template.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/default-theme-supports.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/move-theme-editor-menu-item.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/navigation.php'; | ||
require __DIR__ . '/compat/wordpress-5.9/kses.php'; | ||
|
||
// WordPress 6.0 compat. | ||
require __DIR__ . '/compat/wordpress-6.0/block-editor-settings.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/get-global-styles-and-settings.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/render-svg-filters.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/post-lock.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/blocks.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/block-template-utils.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/functions.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-6-0.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/block-patterns.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/block-template.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/edit-form-blocks.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/block-patterns-update.php'; | ||
require __DIR__ . '/compat/wordpress-6.0/client-assets.php'; | ||
|
||
// WordPress 6.1 compat. | ||
require __DIR__ . '/compat/wordpress-6.1/blocks.php'; | ||
require __DIR__ . '/compat/wordpress-6.1/persisted-preferences.php'; | ||
require __DIR__ . '/compat/wordpress-6.1/get-global-styles-and-settings.php'; | ||
require __DIR__ . '/compat/wordpress-6.1/class-wp-theme-json-6-1.php'; | ||
require __DIR__ . '/compat/wordpress-6.1/class-wp-theme-json-resolver-6-1.php'; | ||
require __DIR__ . '/compat/wordpress-6.1/block-template-utils.php'; | ||
require __DIR__ . '/compat/wordpress-6.1/wp-theme-get-post-templates.php'; | ||
require __DIR__ . '/compat/wordpress-6.1/script-loader.php'; | ||
require __DIR__ . '/compat/wordpress-6.1/date-settings.php'; | ||
require __DIR__ . '/compat/wordpress-6.1/block-patterns.php'; | ||
|
||
// Experimental features. | ||
remove_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); // Turns off WP 6.0's stopgap handler for Webfonts API. | ||
require __DIR__ . '/experimental/block-editor-settings-mobile.php'; | ||
require __DIR__ . '/experimental/register-webfonts-from-theme-json.php'; | ||
require __DIR__ . '/experimental/class-wp-theme-json-gutenberg.php'; | ||
require __DIR__ . '/experimental/class-wp-theme-json-resolver-gutenberg.php'; | ||
require __DIR__ . '/experimental/class-wp-webfonts.php'; | ||
require __DIR__ . '/experimental/class-wp-webfonts-provider.php'; | ||
require __DIR__ . '/experimental/class-wp-webfonts-provider-local.php'; | ||
require __DIR__ . '/experimental/webfonts.php'; | ||
require __DIR__ . '/experimental/blocks.php'; | ||
require __DIR__ . '/experimental/navigation-theme-opt-in.php'; | ||
require __DIR__ . '/experimental/navigation-page.php'; | ||
|
||
// Plugin specific code. | ||
require __DIR__ . '/blocks.php'; | ||
require __DIR__ . '/client-assets.php'; | ||
require __DIR__ . '/demo.php'; | ||
require __DIR__ . '/experiments-page.php'; | ||
|
||
// Copied package PHP files. | ||
if ( file_exists( __DIR__ . '/../build/style-engine/class-wp-style-engine-gutenberg.php' ) ) { | ||
require_once __DIR__ . '/../build/style-engine/class-wp-style-engine-gutenberg.php'; | ||
} | ||
|
||
// Block supports overrides. | ||
require __DIR__ . '/block-supports/utils.php'; | ||
require __DIR__ . '/block-supports/elements.php'; | ||
require __DIR__ . '/block-supports/colors.php'; | ||
require __DIR__ . '/block-supports/typography.php'; | ||
require __DIR__ . '/block-supports/border.php'; | ||
require __DIR__ . '/block-supports/layout.php'; | ||
require __DIR__ . '/block-supports/spacing.php'; | ||
require __DIR__ . '/block-supports/dimensions.php'; | ||
require __DIR__ . '/block-supports/duotone.php'; |
129 changes: 129 additions & 0 deletions
129
lib/compat/wordpress-6.1/class-wp-rest-custom-css-controller.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
/** | ||
* REST API: WP_REST_Custom_CSS_Controller class | ||
* | ||
* @package WordPress | ||
* @subpackage REST_API | ||
*/ | ||
|
||
/** | ||
* Controller which provides REST endpoint for retrieving the Custom CSS. | ||
* | ||
* @see WP_REST_Controller | ||
*/ | ||
class WP_REST_Custom_CSS_Controller extends WP_REST_Controller { | ||
|
||
/** | ||
* Constructs the controller. | ||
*/ | ||
public function __construct() { | ||
$this->namespace = 'wp/v2'; | ||
/* | ||
* The rest base is different from the name of the post type, | ||
* since it uses wp_get_custom_css(). | ||
*/ | ||
$this->rest_base = 'customcss'; | ||
} | ||
|
||
/** | ||
* Registers the routes for the objects of the controller. | ||
* | ||
* @see register_rest_route() | ||
* | ||
* @since 6.1.0 | ||
*/ | ||
public function register_routes() { | ||
register_rest_route( | ||
$this->namespace, | ||
'/' . $this->rest_base, | ||
array( | ||
array( | ||
'methods' => WP_REST_Server::READABLE, | ||
'callback' => array( $this, 'get_items' ), | ||
'permission_callback' => array( $this, 'items_permissions_check' ), | ||
), | ||
array( | ||
'methods' => WP_REST_Server::EDITABLE, | ||
'callback' => array( $this, 'update_item' ), | ||
'permission_callback' => array( $this, 'items_permissions_check' ), | ||
), | ||
'schema' => array( $this, 'get_public_item_schema' ), | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Retrieves the custom CSS | ||
* | ||
* @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. | ||
*/ | ||
public function get_items( $request ) { | ||
$data = wp_get_custom_css(); | ||
|
||
return rest_ensure_response( $data ); | ||
} | ||
|
||
/** | ||
* Update custom CSS | ||
* @see https://developer.wordpress.org/reference/functions/wp_update_custom_css_post | ||
* @param WP_REST_Request $request Full details about the request. | ||
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. | ||
*/ | ||
public function update_item( $request ) { | ||
$data = wp_update_custom_css_post( $request ); | ||
|
||
return rest_ensure_response( $data ); | ||
} | ||
|
||
/** | ||
* Checks whether a given request has permission to read the custom CSS | ||
* | ||
* @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. | ||
*/ | ||
public function items_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | ||
if ( ! current_user_can( 'edit_css' ) ) { | ||
return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to view custom CSS.', 'gutenberg' ), array( 'status' => rest_authorization_required_code() ) ); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Custom CSS schema | ||
* | ||
* @return array Item schema data. | ||
*/ | ||
public function get_item_schema() { | ||
$schema = array( | ||
'$schema' => 'http://json-schema.org/draft-04/schema#', | ||
'title' => 'custom_css', | ||
'type' => 'object', | ||
'properties' => array( | ||
'id' => array( | ||
'description' => __( 'ID of the custom CSS.', 'gutenberg' ), | ||
'type' => 'string', | ||
'context' => array( 'view', 'edit' ), | ||
'readonly' => true, | ||
), | ||
'theme' => array( | ||
'description' => __( 'The theme slug.', 'gutenberg' ), | ||
'type' => 'string', | ||
'context' => array( 'view', 'edit' ), | ||
'readonly' => true, | ||
), | ||
'content' => array( | ||
'description' => __( 'The custom CSS provided by the user.', 'gutenberg' ), | ||
'type' => 'string', | ||
'context' => array( 'view', 'edit' ), | ||
'readonly' => true, | ||
), | ||
), | ||
); | ||
|
||
return $this->add_additional_fields_schema( $schema ); | ||
} | ||
} |
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
Oops, something went wrong.