if ( strlen( $short_url ) > $length ) {
$short_url = substr( $short_url, 0, $length - 3 ) . '…';
* Returns either '', a 3 or 6 digit hex color (with #), or nothing.
* For sanitizing values without a #, see sanitize_hex_color_no_hash().
function sanitize_hex_color( $color ) {
// 3 or 6 hex digits, or the empty string.
if ( preg_match( '|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
* Sanitizes a hex color without a hash. Use sanitize_hex_color() when possible.
* Saving hex colors without a hash puts the burden of adding the hash on the
* UI, which makes it difficult to use or upgrade to other color types such as
* rgba, hsl, rgb, and HTML color names.
* Returns either '', a 3 or 6 digit hex color (without a #), or null.
function sanitize_hex_color_no_hash( $color ) {
$color = ltrim( $color, '#' );
return sanitize_hex_color( '#' . $color ) ? $color : null;
* Ensures that any hex color is properly hashed.
* Otherwise, returns value untouched.
* This method should only be necessary if using sanitize_hex_color_no_hash().
function maybe_hash_hex_color( $color ) {
$unhashed = sanitize_hex_color_no_hash( $color );