Skip to content
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 @@ -89,6 +89,29 @@ public function prepare_item_for_response( $post, $request ) { // phpcs:ignore V
return $response;
}

/**
* Get the link relations available for the post and current user.
*
* @since 5.9.0
* @since 6.2.0 Added 'edit-css' action.
*
* @return array List of link relations.
*/
protected function get_available_actions() {
$rels = array();

$post_type = get_post_type_object( $this->post_type );
if ( current_user_can( $post_type->cap->publish_posts ) ) {
$rels[] = 'https://api.w.org/action-publish';
}

if ( current_user_can( 'edit_css' ) ) {
$rels[] = 'https://api.w.org/action-edit-css';
}
Comment on lines +108 to +110
Copy link
Member Author

@Mamaduka Mamaduka Dec 29, 2022

Choose a reason for hiding this comment

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

I couldn't find documentation on how these URLs are generated/created. So I need to double-check if https://api.w.org/action-edit-css is the correct format.

cc @TimothyBJacobs, @spacedmonkey


return $rels;
}

/**
* Updates a single global style config.
*
Expand Down
3 changes: 0 additions & 3 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ function gutenberg_enable_experiments() {
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-off-canvas-navigation-editor', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableOffCanvasNavigationEditor = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-global-styles-custom-css', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableGlobalStylesCustomCSS = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_enable_experiments' );
16 changes: 0 additions & 16 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,6 @@ function gutenberg_initialize_experiments_settings() {
)
);

add_settings_field(
'gutenberg-global-styles-custom-css',
__( 'Global styles custom css ', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => sprintf(
/* translators: %s: WordPress documentation for roles and capabilities. */
__( 'Test the Global Styles custom CSS field in the site editor. This requires a user to have <a href="%s">unfiltered html capabilities</a>.', 'gutenberg' ),
'https://wordpress.org/support/article/roles-and-capabilities/#unfiltered_html'
),
'id' => 'gutenberg-global-styles-custom-css',
)
);

register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
24 changes: 16 additions & 8 deletions packages/edit-site/src/components/global-styles/screen-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ import ContextMenu from './context-menu';
import StylesPreview from './preview';

function ScreenRoot() {
const { variations } = useSelect( ( select ) => {
const { variations, canEditCSS } = useSelect( ( select ) => {
const {
getEntityRecord,
__experimentalGetCurrentGlobalStylesId,
__experimentalGetCurrentThemeGlobalStylesVariations,
} = select( coreStore );

const globalStylesId = __experimentalGetCurrentGlobalStylesId();
const globalStyles = globalStylesId
? getEntityRecord( 'root', 'globalStyles', globalStylesId )
: undefined;

return {
variations:
select(
coreStore
).__experimentalGetCurrentThemeGlobalStylesVariations(),
variations: __experimentalGetCurrentThemeGlobalStylesVariations(),
canEditCSS:
!! globalStyles?._links?.[ 'wp:action-edit-css' ] ?? false,
};
}, [] );

const __experimentalGlobalStylesCustomCSS =
window?.__experimentalEnableGlobalStylesCustomCSS;
return (
<Card size="small">
<CardBody>
Expand Down Expand Up @@ -102,7 +110,7 @@ function ScreenRoot() {
</ItemGroup>
</CardBody>

{ __experimentalGlobalStylesCustomCSS && (
{ canEditCSS && (
<>
<CardDivider />
<CardBody>
Expand Down