amitrh
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Themes and Templates
In reply to: Theme customizer sanitizationThanks, @aaron Beverly
Forum: Themes and Templates
In reply to: Theme customizer sanitizationI am also running into the same issue. i have added
'sanitize_callback'to everyadd_setting()
function but it still show the error. Please anyone Check My Code snippet and give me suggestionfunction bookish_customize_register( $wp_customize ) { $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->remove_control( 'header_textcolor' ); $wp_customize->remove_control( 'background_color' ); $wp_customize->remove_section( 'background_image' ); $wp_customize->remove_section( 'header_image' ); /*-----------------------------------------------------------* * Assent Color section *-----------------------------------------------------------*/ $wp_customize->add_setting( 'tcx_link_color', array( 'default' => '#000000', 'sanitize_callback' => 'bookish_sanitize_text', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array( 'label' => __( 'Link Color', 'tcx' ), 'section' => 'colors', 'settings' => 'tcx_link_color' ) ) ); /*-----------------------------------------------------------* * Defining General Setting section *-----------------------------------------------------------*/ $wp_customize->add_section( 'bookish_general_setting', array( 'title' => 'General Settings', 'priority' => 1 ) ); $wp_customize->add_setting( 'bookish-logo', array( 'default' => '', 'sanitize_callback' => 'esc_url_raw', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'bookish-logo', array( 'label' => __( ' Logo', 'bookish' ), 'section' => 'bookish_general_setting', 'settings' => 'bookish-logo', 'priority' => 1 ) ) ); $wp_customize->add_setting( 'bookish-retina-logo', array( 'default' => '', 'sanitize_callback' => 'esc_url_raw', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'bookish-retina-logo', array( 'label' => __( 'Retina Logo', 'bookish' ), 'section' => 'bookish_general_setting', 'settings' => 'bookish-retina-logo', 'priority' => 2 ) ) ); $wp_customize->add_setting( 'bookish-favicon', array( 'default' => '', 'sanitize_callback' => 'esc_url_raw', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'bookish-favicon', array( 'label' => __( ' Favicon', 'bookish' ), 'section' => 'bookish_general_setting', 'settings' => 'bookish-favicon', 'priority' => 3 ) ) ); $wp_customize->add_setting( 'bookish-avatar', array( 'default' => '', 'sanitize_callback' => 'esc_url_raw', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'bookish-avatar', array( 'label' => __( 'Avatar', 'bookish' ), 'section' => 'bookish_general_setting', 'settings' => 'bookish-avatar', 'priority' => 4 ) ) ); $wp_customize->add_setting( 'bookish-retina-avatar', array( 'default' => '', 'sanitize_callback' => 'esc_url_raw', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'bookish-retina-avatar', array( 'label' => __( 'Retina Avatar', 'bookish' ), 'section' => 'bookish_general_setting', 'settings' => 'bookish-retina-avatar', 'priority' => 5 ) ) ); $wp_customize->add_setting( 'bookish_profile_name', array( 'default' => 'Vincent Doe', 'sanitize_callback' => 'bookish_sanitize_text', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'bookish_profile_name', array( 'section' => 'bookish_general_setting', 'label' => 'Profile Name', 'type' => 'text' ) ); $wp_customize->add_setting( 'bookish_profile_desc', array( 'default' => 'I lie close to the earth, a thousand unknown plants are noticed by me: when I hear the buzz of the little world among the stalks.', 'sanitize_callback' => 'bookish_sanitize_textarea', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'bookish_profile_desc', array( 'section' => 'bookish_general_setting', 'label' => 'Profile Description', 'type' => 'textarea' ) ); /*-----------------------------------------------------------* * Contact section *-----------------------------------------------------------*/ $wp_customize->add_section( 'contact_setting', array( 'title' => 'Contact Info', 'priority' => 2 ) ); $wp_customize->add_setting( 'contact_heading', array( 'default' => 'Get in touch', 'sanitize_callback' => 'bookish_sanitize_text', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'contact_heading', array( 'section' => 'contact_setting', 'label' => 'Contact Heading', 'type' => 'text' ) ); $wp_customize->add_setting( 'contact_email', array( 'default' => '', 'sanitize_callback' => 'bookish_sanitize_email', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'contact_email', array( 'section' => 'contact_setting', 'label' => 'Email', 'type' => 'email' ) ); $wp_customize->add_setting( 'contact_phone', array( 'default' => '', 'sanitize_callback' => 'bookish_sanitize_number', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'contact_phone', array( 'section' => 'contact_setting', 'label' => 'Phone Number', 'type' => 'text' ) ); } add_action( 'customize_register', 'bookish_customize_register', 11 ); /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function bookish_customize_preview_js() { wp_enqueue_script( 'bookish_customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), '20130508', true ); } add_action( 'customize_preview_init', 'bookish_customize_preview_js' ); function bookish_sanitize_text( $str ) { return sanitize_text_field( $str ); } function bookish_sanitize_textarea( $text ) { return esc_textarea( $text ); } function bookish_sanitize_number( $int ) { return absint( $int ); } function bookish_sanitize_email( $email ) { if(is_email( $email )){ return $email; }else{ return ''; } } function bookish_sanitize_file_url( $url ) { $output = ''; $filetype = wp_check_filetype( $url ); if ( $filetype["ext"] ) { $output = esc_url( $url ); } return $output; } function tcx_customizer_css() { ?> <style type="text/css"> .TopBanner { background-color: <?php echo get_theme_mod( 'tcx_link_color' ); ?>!important; } </style> <?php } add_action( 'wp_head', 'tcx_customizer_css' );Thanks in advance
Viewing 2 replies - 1 through 2 (of 2 total)