Make WordPress Core


Ignore:
Timestamp:
05/17/2023 11:56:47 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Docs: Improve Style Engine DocBlocks per the documentation standards.

Follow-up to [54156], [55719], [55733].

See #57840.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/style-engine.php

    r55719 r55819  
    1212
    1313/**
    14  * Global public interface method to generate styles from a single style object, e.g.,
    15  * the value of a block's attributes.style object or the top level styles in theme.json.
    16  * See: https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/theme-json-living/#styles and
    17  * https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/
     14 * Global public interface method to generate styles from a single style object,
     15 * e.g. the value of a block's attributes.style object or the top level styles in theme.json.
    1816 *
    1917 * Example usage:
    2018 *
    21  *     $styles = wp_style_engine_get_styles( array( 'color' => array( 'text' => '#cccccc' ) ) );
     19 *     $styles = wp_style_engine_get_styles(
     20 *         array(
     21 *             'color' => array( 'text' => '#cccccc' ),
     22 *         )
     23 *     );
    2224 *
    2325 * Returns:
    2426 *
    25  *     array( 'css' => 'color: #cccccc', 'declarations' => array( 'color' => '#cccccc' ), 'classnames' => 'has-color' )
     27 *     array(
     28 *         'css'          => 'color: #cccccc',
     29 *         'declarations' => array( 'color' => '#cccccc' ),
     30 *         'classnames'   => 'has-color',
     31 *     )
    2632 *
    27  * @access public
    2833 * @since 6.1.0
     34 *
     35 * @see https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/theme-json-living/#styles
     36 * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/
    2937 *
    3038 * @param array $block_styles The style object.
     
    3240 *     Optional. An array of options. Default empty array.
    3341 *
    34  *     @type string|null $context                    An identifier describing the origin of the style object, e.g., 'block-supports' or 'global-styles'. Default is `null`.
    35  *                                                   When set, the style engine will attempt to store the CSS rules, where a selector is also passed.
    36  *     @type bool        $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to `var( --wp--preset--* )` values. Default `false`.
    37  *     @type string      $selector                   Optional. When a selector is passed, the value of `$css` in the return value will comprise a full CSS rule `$selector { ...$css_declarations }`,
    38  *                                                   otherwise, the value will be a concatenated string of CSS declarations.
     42 *     @type string|null $context                    An identifier describing the origin of the style object,
     43 *                                                   e.g. 'block-supports' or 'global-styles'. Default null.
     44 *                                                   When set, the style engine will attempt to store the CSS rules,
     45 *                                                   where a selector is also passed.
     46 *     @type bool        $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns,
     47 *                                                   e.g. `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`,
     48 *                                                   to `var( --wp--preset--* )` values. Default false.
     49 *     @type string      $selector                   Optional. When a selector is passed,
     50 *                                                   the value of `$css` in the return value will comprise
     51 *                                                   a full CSS rule `$selector { ...$css_declarations }`,
     52 *                                                   otherwise, the value will be a concatenated string
     53 *                                                   of CSS declarations.
    3954 * }
    4055 * @return array {
    41  *     @type string   $css          A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag.
    42  *     @type string[] $declarations An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`.
     56 *     @type string   $css          A CSS ruleset or declarations block
     57 *                                  formatted to be placed in an HTML `style` attribute or tag.
     58 *     @type string[] $declarations An associative array of CSS definitions,
     59 *                                  e.g. `array( "$property" => "$value", "$property" => "$value" )`.
    4360 *     @type string   $classnames   Classnames separated by a space.
    4461 * }
     
    8097 * Example usage:
    8198 *
    82  *     $css_rules = array( array( 'selector' => '.elephant-are-cool', 'declarations' => array( 'color' => 'gray', 'width' => '3em' ) ) );
    83  *     $css       = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
     99 *     $css_rules = array(
     100 *         array(
     101 *             'selector'     => '.elephant-are-cool',
     102 *             'declarations' => array(
     103 *                 'color' => 'gray',
     104 *                 'width' => '3em',
     105 *             ),
     106 *         ),
     107 *     );
     108 *
     109 *     $css = wp_style_engine_get_stylesheet_from_css_rules( $css_rules );
    84110 *
    85111 * Returns:
     
    94120 *     @type array ...$0 {
    95121 *         @type string   $selector     A CSS selector.
    96  *         @type string[] $declarations An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`.
     122 *         @type string[] $declarations An associative array of CSS definitions,
     123 *                                      e.g. `array( "$property" => "$value", "$property" => "$value" )`.
    97124 *     }
    98125 * }
     
    100127 *     Optional. An array of options. Default empty array.
    101128 *
    102  *     @type string|null $context  An identifier describing the origin of the style object, e.g., 'block-supports' or 'global-styles'. Default is 'block-supports'.
     129 *     @type string|null $context  An identifier describing the origin of the style object,
     130 *                                 e.g. 'block-supports' or 'global-styles'. Default 'block-supports'.
    103131 *                                 When set, the style engine will attempt to store the CSS rules.
    104  *     @type bool        $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
    105  *     @type bool        $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined.
     132 *     @type bool        $optimize Whether to optimize the CSS output, e.g. combine rules.
     133 *                                 Default false.
     134 *     @type bool        $prettify Whether to add new lines and indents to output.
     135 *                                 Defaults to whether the `SCRIPT_DEBUG` constant is defined.
    106136 * }
    107137 * @return string A string of compiled CSS declarations, or empty string.
     
    148178 *     Optional. An array of options. Default empty array.
    149179 *
    150  *     @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`.
    151  *     @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined.
     180 *     @type bool $optimize Whether to optimize the CSS output, e.g. combine rules.
     181 *                          Default false.
     182 *     @type bool $prettify Whether to add new lines and indents to output.
     183 *                          Defaults to whether the `SCRIPT_DEBUG` constant is defined.
    152184 * }
    153185 * @return string A compiled CSS string.
Note: See TracChangeset for help on using the changeset viewer.