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

Theme Support: Enable custom units by default #24873

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 6 additions & 4 deletions docs/designers-developers/developers/themes/theme-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,18 @@ add_theme_support( 'custom-line-height' );

### Support custom units

In addition to pixels, users can use other units to define sizes, paddings... The available units are: px, em, rem, vh, vw. Themes can enable support for this feature with the following code:
In addition to pixels, users can use other units to define sizes, paddings... The available units are: px, em, rem, vh, vw.

Themes can also filter the available custom units.

```php
add_theme_support( 'custom-units' );
add_theme_support( 'custom-units', 'rem', 'em' );
```

Themes can also filter the available custom units.
Custom units are available by default. However, themes can disable support for this feature with the following code:

```php
add_theme_support( 'custom-units', 'rem', 'em' );
add_theme_support( 'custom-units', false );
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should change this to remove_theme_support( 'custom-units' ); and add a add_theme_support( true ) call to Core.

Copy link
Author

Choose a reason for hiding this comment

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

Cool! That API makes sense to me. I've never worked with remove_theme_support before.. Is there an example I can follow to do that? :D

```

### Disabling the default block patterns.
Expand Down
11 changes: 9 additions & 2 deletions packages/block-editor/src/components/unit-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ export function useCustomUnits( unitsProp ) {
select( 'core/block-editor' ).getSettings().enableCustomUnits,
[]
);
const isDisabled = ! settings;
const hasConfigs = Array.isArray( settings );

let isDisabled = false;

if ( hasConfigs ) {
const [ enabledFlag ] = settings;
isDisabled = enabledFlag === false;
}

// Adjust units based on add_theme_support( 'custom-units' );
let units;
Expand All @@ -51,7 +58,7 @@ export function useCustomUnits( unitsProp ) {
* Note: If there are unit argument (e.g. 'em'), these units are enabled
* within the control.
*/
if ( Array.isArray( settings ) ) {
if ( hasConfigs ) {
units = filterUnitsWithSettings( settings, unitsProp );
} else {
units = isDisabled ? false : unitsProp;
Expand Down