get_declarations example


    public function get_declarations_string( $should_prettify = false, $indent_count = 0 ) {
        $declarations_array  = $this->get_declarations();
        $declarations_output = '';
        $indent              = $should_prettify ? str_repeat( "\t", $indent_count ) : '';
        $suffix              = $should_prettify ? ' ' : '';
        $suffix              = $should_prettify && $indent_count > 0 ? "\n" : $suffix;
        $spacer              = $should_prettify ? ' ' : '';

        foreach ( $declarations_array as $property => $value ) {
            $filtered_declaration = static::filter_declaration( $property$value$spacer );
            if ( $filtered_declaration ) {
                $declarations_output .= "{$indent}{$filtered_declaration};$suffix";
            }
        }

    public function add_rules( $css_rules ) {
        if ( ! is_array( $css_rules ) ) {
            $css_rules = array( $css_rules );
        }

        foreach ( $css_rules as $rule ) {
            $selector = $rule->get_selector();
            if ( isset( $this->css_rules[ $selector ] ) ) {
                $this->css_rules[ $selector ]->add_declarations( $rule->get_declarations() );
                continue;
            }
            $this->css_rules[ $rule->get_selector() ] = $rule;
        }

        return $this;
    }

    /** * Gets the CSS rules as a string. * * @since 6.1.0 * * @param array $options { * Optional. An array of options. Default empty array. * * @type bool $optimize Whether to optimize the CSS output, e.g. combine rules. * Default true. * @type bool $prettify Whether to add new lines and indents to output. * Defaults to whether the `SCRIPT_DEBUG` constant is defined. * } * @return string The computed CSS. */
/** * Sets the declarations. * * @since 6.1.0 * * @param string[]|WP_Style_Engine_CSS_Declarations $declarations An array of declarations (property => value pairs), * or a WP_Style_Engine_CSS_Declarations object. * @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods. */
    public function add_declarations( $declarations ) {
        $is_declarations_object = ! is_array( $declarations );
        $declarations_array     = $is_declarations_object ? $declarations->get_declarations() : $declarations;

        if ( null === $this->declarations ) {
            if ( $is_declarations_object ) {
                $this->declarations = $declarations;
                return $this;
            }
            $this->declarations = new WP_Style_Engine_CSS_Declarations( $declarations_array );
        }
        $this->declarations->add_declarations( $declarations_array );

        return $this;
    }
Home | Imprint | This part of the site doesn't use cookies.