WordPress.org

Make WordPress Core

Ticket #20600: 20600.diff

File 20600.diff, 1.0 KB (added by kovshenin, 6 years ago)

Uses a sanitize function to convert an empty string to the default header color for the theme, also accepts "blank" and properly sanitizes the rest.

  • class-wp-customize.php

     
    560560                ) );
    561561
    562562                $this->add_setting( 'header_textcolor', array(
    563                         // @todo: replace with a new accept() setting method
    564                         // 'sanitize_callback' => 'sanitize_hexcolor',
     563                        'sanitize_callback' => 'sanitize_header_textcolor',
    565564                        'theme_supports' => array( 'custom-header', 'header-text' ),
    566565                        'default'        => get_theme_support( 'custom-header', 'default-text-color' ),
    567566                ) );
     
    789788        }
    790789};
    791790
     791// Callback function for sanitizing the header textcolor setting.
     792function sanitize_header_textcolor( $color ) {
     793        if ( empty( $color ) )
     794                return get_theme_support( 'custom-header', 'default-text-color' );
     795
     796        elseif ( $color == 'blank' )
     797                return 'blank';
     798
     799        return sanitize_hexcolor( $color );
     800}
     801
    792802// Callback function for sanitizing a hex color
    793803function sanitize_hexcolor( $color ) {
    794804        $color = preg_replace( '/[^0-9a-fA-F]/', '', $color );