WordPress.org

Make WordPress Core

Ticket #19100: 19100.diff

File 19100.diff, 1.5 KB (added by mfields, 2 years ago)

Changed function name to esc_color_hex()

  • wp-includes/formatting.php

     
    24322432} 
    24332433 
    24342434/** 
     2435 * Escape a color represented in hexadecimal notation for use in css. 
     2436 * 
     2437 * @param string $color RGB color represented in hexadecimal notation. 
     2438 * @return string The value of $color if it is a color represented in hexadecimal notation prepended with the hash (#) character; The string 'transparent' otherwise. 
     2439 * 
     2440 * @since 3.4 
     2441 */ 
     2442function esc_color_hex( $color ) { 
     2443        $color = esc_color_hex_raw( $color ); 
     2444        if ( 'transparent' != $color ) 
     2445                $color = '#' . $color; 
     2446        return $color; 
     2447} 
     2448 
     2449/** 
     2450 * Escape a color represented in hexadecimal notation for database saves. 
     2451 * 
     2452 * @param string $color RGB color represented in hexadecimal notation. 
     2453 * @return string The value of $color if it is a color represented in hexadecimal notation; The string 'transparent' otherwise. 
     2454 * 
     2455 * @since 3.4 
     2456 */ 
     2457function esc_color_hex_raw( $color ) { 
     2458        $default = 'transparent'; 
     2459        $color = trim( $color ); 
     2460 
     2461        if ( 0 === strpos( $color, '#' ) ) 
     2462                $color = substr( $color, 1 ); 
     2463 
     2464        if ( 0 === strpos( $color, '%23' ) ) 
     2465                $color = substr( $color, 3 ); 
     2466 
     2467        if ( ! ctype_xdigit( $color ) ) 
     2468                return $default; 
     2469 
     2470        if ( ! in_array( strlen( $color ), array( 3, 6 ) ) ) 
     2471                return $default; 
     2472 
     2473        return strtolower( $color ); 
     2474} 
     2475 
     2476/** 
    24352477 * Escape a HTML tag name. 
    24362478 * 
    24372479 * @since 2.5.0