Skip to content

Commit

Permalink
Do not register global styles CPT in WordPress 5.9 (#37282)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal authored Dec 10, 2021
1 parent 620b395 commit 96f899f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 51 deletions.
68 changes: 39 additions & 29 deletions lib/compat/wordpress-5.9/register-global-styles-cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,44 @@
* @package gutenberg
*/

/**
* Registers a Custom Post Type to store the user's origin config.
*
* This has been ported to src/wp-includes/post.php
/*
* If wp_get_global_settings is defined, it means the plugin
* is running on WordPress 5.9, so don't need to register the CPT
* as it was already done by WordPress core.
*/
function register_global_styles_custom_post_type() {
$args = array(
'label' => __( 'Global Styles', 'gutenberg' ),
'description' => 'CPT to store user design tokens',
'public' => false,
'show_ui' => false,
'show_in_rest' => false,
'rewrite' => false,
'capabilities' => array(
'read' => 'edit_theme_options',
'create_posts' => 'edit_theme_options',
'edit_posts' => 'edit_theme_options',
'edit_published_posts' => 'edit_theme_options',
'delete_published_posts' => 'edit_theme_options',
'edit_others_posts' => 'edit_theme_options',
'delete_others_posts' => 'edit_theme_options',
),
'map_meta_cap' => true,
'supports' => array(
'title',
'editor',
'revisions',
),
);
register_post_type( 'wp_global_styles', $args );
if ( ! function_exists( 'wp_get_global_settings' ) ) {

/**
* Registers a Custom Post Type to store the user's origin config.
*
* This has been ported to src/wp-includes/post.php
*/
function register_global_styles_custom_post_type() {
$args = array(
'label' => __( 'Global Styles', 'gutenberg' ),
'description' => 'Global styles to include in themes.',
'public' => false,
'show_ui' => false,
'show_in_rest' => false,
'rewrite' => false,
'capabilities' => array(
'read' => 'edit_theme_options',
'create_posts' => 'edit_theme_options',
'edit_posts' => 'edit_theme_options',
'edit_published_posts' => 'edit_theme_options',
'delete_published_posts' => 'edit_theme_options',
'edit_others_posts' => 'edit_theme_options',
'delete_others_posts' => 'edit_theme_options',
),
'map_meta_cap' => true,
'supports' => array(
'title',
'editor',
'revisions',
),
);
register_post_type( 'wp_global_styles', $args );
}

add_action( 'init', 'register_global_styles_custom_post_type' );
}
21 changes: 0 additions & 21 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,6 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&
return $settings;
}

/**
* Whether or not the Site Editor is available.
*
* @return boolean
*/
function gutenberg_experimental_is_site_editor_available() {
return wp_is_block_theme();
}

/**
* Register CPT to store/access user data.
*
* @return void
*/
function gutenberg_experimental_global_styles_register_user_cpt() {
if ( gutenberg_experimental_is_site_editor_available() ) {
register_global_styles_custom_post_type();
}
}

/**
* Sanitizes global styles user content removing unsafe rules.
*
Expand Down Expand Up @@ -293,7 +273,6 @@ function gutenberg_load_css_custom_properties() {
add_filter( 'block_editor_settings', 'gutenberg_experimental_global_styles_settings', PHP_INT_MAX );
}

add_action( 'init', 'gutenberg_experimental_global_styles_register_user_cpt' );
add_action( 'wp_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets' );

// kses actions&filters.
Expand Down
2 changes: 1 addition & 1 deletion lib/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function gutenberg_menu() {
* @since 9.4.0
*/
function gutenberg_site_editor_menu() {
if ( gutenberg_experimental_is_site_editor_available() ) {
if ( wp_is_block_theme() ) {
add_theme_page(
__( 'Editor (beta)', 'gutenberg' ),
sprintf(
Expand Down

0 comments on commit 96f899f

Please sign in to comment.