Make WordPress Core


Ignore:
Timestamp:
11/28/2019 12:28:50 AM (7 years ago)
Author:
SergeyBiryukov
Message:

KSES: Add support for gradient backgrounds.

Props jorgefilipecosta.
Merges [46793] to the 5.3 branch.
Fixes #48376.

Location:
branches/5.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.3

  • branches/5.3/src/wp-includes/kses.php

    r46235 r46794  
    20742074         * @since 5.3.0 Added support for `grid`, `flex` and `column` layout properties.
    20752075         *              Extend `background-*` support of individual properties.
     2076         * @since 5.3.1 Added support for gradient backgrounds.
    20762077         *
    20772078         * @param string[] $attr Array of allowed CSS attributes.
     
    22102211        );
    22112212
     2213        /*
     2214         * CSS attributes that accept gradient data types.
     2215         *
     2216         */
     2217        $css_gradient_data_types = array(
     2218                'background',
     2219                'background-image',
     2220        );
     2221
    22122222        if ( empty( $allowed_attr ) ) {
    22132223                return $css;
     
    22242234                $found           = false;
    22252235                $url_attr        = false;
     2236                $gradient_attr   = false;
    22262237
    22272238                if ( strpos( $css_item, ':' ) === false ) {
     
    22322243
    22332244                        if ( in_array( $css_selector, $allowed_attr, true ) ) {
    2234                                 $found    = true;
    2235                                 $url_attr = in_array( $css_selector, $css_url_data_types, true );
     2245                                $found         = true;
     2246                                $url_attr      = in_array( $css_selector, $css_url_data_types, true );
     2247                                $gradient_attr = in_array( $css_selector, $css_gradient_data_types, true );
    22362248                        }
    22372249                }
     
    22592271                                        $css_test_string = str_replace( $url_match, '', $css_test_string );
    22602272                                }
     2273                        }
     2274                }
     2275
     2276                if ( $found && $gradient_attr ) {
     2277                        $css_value = trim( $parts[1] );
     2278                        if ( preg_match( '/^(repeating-)?(linear|radial|conic)-gradient\(([^()]|rgb[a]?\([^()]*\))*\)$/', $css_value ) ) {
     2279                                // Remove the whole `gradient` bit that was matched above from the CSS.
     2280                                $css_test_string = str_replace( $css_value, '', $css_test_string );
    22612281                        }
    22622282                }
Note: See TracChangeset for help on using the changeset viewer.