| 2435 | * Escape a color for use in css. |
| 2436 | * |
| 2437 | * @param string $color RGB color represented in hexidecimal notation. |
| 2438 | * @return string The value of $color if it is a color represented in hexidecimal notation; The string 'transparent' otherwise. |
| 2439 | * |
| 2440 | * @since 3.4 |
| 2441 | */ |
| 2442 | function esc_color( $color ) { |
| 2443 | $color = esc_color_raw( $color ); |
| 2444 | if ( 'transparent' != $color ) |
| 2445 | $color = '#' . $color; |
| 2446 | return $color; |
| 2447 | } |
| 2448 | |
| 2449 | /** |
| 2450 | * Escape a color for database saves. |
| 2451 | * |
| 2452 | * @param string $color RGB color represented in hexidecimal notation. |
| 2453 | * @return string The value of $color if it is a color represented in hexidecimal notation; The string 'transparent' otherwise. |
| 2454 | * |
| 2455 | * @since 3.4 |
| 2456 | */ |
| 2457 | function esc_color_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 | /** |