WordPress.org

Make WordPress Core

Ticket #19100: 19100.2.diff

File 19100.2.diff, 1.4 KB (added by mbijon, 3 years ago)

Renamed method & using suggested preg_match

  • wp-includes/formatting.php

     
    24332433} 
    24342434 
    24352435/** 
     2436 * Escape a color represented in hexadecimal notation for use in css. 
     2437 * 
     2438 * @param string $color RGB color represented in hexadecimal notation. 
     2439 * @return string The value of $color if it is a color represented in hexadecimal notation prepended with the hash (#) character; The string 'transparent' otherwise. 
     2440 * 
     2441 * @since 3.4 
     2442 */ 
     2443function sanitize_color_hex( $color ) { 
     2444        $color = sanitize_color_hex_raw( $color ); 
     2445        if ( 'transparent' != $color ) 
     2446                $color = '#' . $color; 
     2447        return $color; 
     2448} 
     2449 
     2450/** 
     2451 * Escape a color represented in hexadecimal notation for database saves. 
     2452 * 
     2453 * @param string $color RGB color represented in hexadecimal notation. 
     2454 * @return string The value of $color if it is a color represented in hexadecimal notation; The string 'transparent' otherwise. 
     2455 * 
     2456 * @since 3.4 
     2457 */ 
     2458function sanitize_color_hex_raw( $color ) { 
     2459        $default = 'transparent'; 
     2460        $color = trim( strtolower( urldecode( $color ) ), "# \t\n\r\0\x0B" ); 
     2461 
     2462        if ( ! in_array( strlen( $color ), array( 3, 6 ) ) ) 
     2463                return $default; 
     2464         
     2465        if ( ! preg_match( "/(([a-f0-9]){3}){1,2}$/i", $color ) ) 
     2466                return $default; 
     2467         
     2468        return $color; 
     2469} 
     2470 
     2471/** 
    24362472 * Escape a HTML tag name. 
    24372473 * 
    24382474 * @since 2.5.0