Fixed the sanitize callback error

This commit is contained in:
Fabiano 2018-10-05 11:15:45 -03:00
parent b0c1772f4b
commit 2b2bb08390
1 changed files with 33 additions and 9 deletions

View File

@ -57,6 +57,7 @@ function tainacan_customize_register( $wp_customize ) {
*/ */
$wp_customize->add_setting( 'tainacan_footer_logo', array( $wp_customize->add_setting( 'tainacan_footer_logo', array(
'capability' => 'manage_options', 'capability' => 'manage_options',
'sanitize_callback' => 'tainacan_sanitize_upload',
) ); ) );
$wp_customize->add_control( $wp_customize->add_control(
@ -233,16 +234,39 @@ function tainacan_sanitize_email( $email, $setting ) {
* - Sanitization: number * - Sanitization: number
* - Control: text * - Control: text
* *
* @param string $email Email address to sanitize. * @param string $phone Phone to sanitize.
* @param WP_Customize_Setting $setting Setting instance. * @return string The sanitized phone if the number is <= 18; otherwise, the setting default.
* @return string The sanitized email if not null; otherwise, the setting default.
*/ */
function tainacan_sanitize_phone( $phone ) { function tainacan_sanitize_phone( $phone ) {
// Strips out all characters that are not allowable in an email address. // Replace out all characters that are not allowable in an phone number.
$phone = preg_replace('/[^0-9 \\-\\(\\)\\+\\/]/', '', $phone); $phone = preg_replace( '/[^0-9 \\-\\(\\)\\+\\/]/', '', $phone );
// If $email is a valid email, return it; otherwise, return the default. // If $phone is a valid number and <= 18, return it; otherwise, ''.
return ( strlen($phone) <= 18 ? $phone : '' ); return ( strlen( $phone ) <= 18 ? $phone : '' );
}
/**
* Tainacan Upload sanitization callback.
*
* - Sanitization: upload
* - Control: file
*
*/
function tainacan_sanitize_upload( $input ) {
/* default output */
$output = '';
/* check file type */
$filetype = wp_check_filetype( $input );
$mime_type = $filetype['type'];
/* only mime type "image" allowed */
if ( strpos( $mime_type, 'image' ) !== false ) {
$output = $input;
}
return $output;
} }
/** /**
@ -387,8 +411,8 @@ if ( ! function_exists( 'tainacan_get_color_scheme' ) ) :
*/ */
function tainacan_get_color_scheme() { function tainacan_get_color_scheme() {
$color_scheme_option = get_theme_mod( 'tainacan_color_scheme', 'default' ); $color_scheme_option = get_theme_mod( 'tainacan_color_scheme', 'default' );
$link_color = get_theme_mod( 'tainacan_link_color', 'default' ); // sanitized upon save $link_color = get_theme_mod( 'tainacan_link_color', 'default' ); // sanitized upon save
$tooltip_color = get_theme_mod( 'tainacan_tooltip_color', 'default' ); // sanitized upon save $tooltip_color = get_theme_mod( 'tainacan_tooltip_color', 'default' ); // sanitized upon save
$color_schemes = tainacan_get_color_schemes(); $color_schemes = tainacan_get_color_schemes();
if ( array_key_exists( $color_scheme_option, $color_schemes ) ) { if ( array_key_exists( $color_scheme_option, $color_schemes ) ) {