Make WordPress Core


Ignore:
Timestamp:
05/31/2024 05:47:23 AM (6 months ago)
Author:
noisysocks
Message:

Block Themes: Add section styling via extended block style variations

Provide users with the ability to style entire sections of a page without
having to tediously reapply the same sets of styles.

This is done by extending block style variations to apply to nested blocks.

See https://github.com/WordPress/gutenberg/pull/57908.

Fixes #61312.
Props aaronrobertshaw, talldanwp, ramonopoly, isabel_brison, andrewserong.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json-resolver.php

    r58263 r58264  
    702702    }
    703703
     704    /**
     705     * Determines if a supplied style variation matches the provided scope.
     706     *
     707     * For backwards compatibility, if a variation does not define any scope
     708     * related property, e.g. `blockTypes`, it is assumed to be a theme style
     709     * variation.
     710     *
     711     * @since 6.6.0
     712     *
     713     * @param array  $variation Theme.json shaped style variation object.
     714     * @param string $scope     Scope to check e.g. theme, block etc.
     715     *
     716     * @return boolean
     717     */
     718    private static function style_variation_has_scope( $variation, $scope ) {
     719        if ( 'block' === $scope ) {
     720            return isset( $variation['blockTypes'] );
     721        }
     722
     723        if ( 'theme' === $scope ) {
     724            return ! isset( $variation['blockTypes'] );
     725        }
     726
     727        return false;
     728    }
    704729
    705730    /**
     
    708733     * @since 6.0.0
    709734     * @since 6.2.0 Returns parent theme variations if theme is a child.
     735     * @since 6.6.0 Added configurable scope parameter to allow filtering
     736     *              theme.json partial files by the scope to which they
     737     *              can be applied e.g. theme vs block etc.
     738     *
     739     * @param string $scope The scope or type of style variation to retrieve e.g. theme, block etc.
    710740     *
    711741     * @return array
    712742     */
    713     public static function get_style_variations() {
     743    public static function get_style_variations( $scope = 'theme' ) {
    714744        $variation_files    = array();
    715745        $variations         = array();
     
    734764        foreach ( $variation_files as $path => $file ) {
    735765            $decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) );
    736             if ( is_array( $decoded_file ) ) {
     766            if ( is_array( $decoded_file ) && static::style_variation_has_scope( $decoded_file, $scope ) ) {
    737767                $translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) );
    738768                $variation  = ( new WP_Theme_JSON( $translated ) )->get_raw_data();
Note: See TracChangeset for help on using the changeset viewer.