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

Do not register global styles CPT in WordPress 5.9 #37282

Merged
merged 2 commits into from
Dec 10, 2021
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
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() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code of this function is the same, just indented.

$args = array(
'label' => __( 'Global Styles', 'gutenberg' ),
'description' => 'Global styles to include in themes.',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a second commit, I actually updated this text to be in line with core's naming.

'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