<?php
/** Theme Customizer Functions */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
/*========================== CUSTOMIZER SANITIZE FUNCTIONS ==========================*/
// Sanitize the predefined theme styles.
function pmthemes_sanitize_theme_styles( $value ) {
    if ( ! in_array( $value, array('colors', 'bermuda', 'berry', 'black', 'blackberry', 'bluelights', 'blacknblue', 'blue', 'blueairforce', 'blueberry', 'blueline', 'blues', 'carrotman', 'charcoal', 'chocoberry', 'chocolate', 'cobalt', 'coolblue', 'cottoncandy', 'countryside', 'crimson', 'deepblue', 'fairytail', 'fernland', 'fruitella', 'golden', 'green', 'greenline', 'greengray', 'greyorange', 'magenta', 'orange', 'orangefox', 'orangeline', 'orangina', 'pastel-blue', 'pink', 'pinkish', 'pinkpoodle', 'pinkred', 'pinky', 'pomegranate', 'purplegreen', 'purplehaze', 'red', 'redhotchilipepper', 'rednblue', 'redocean', 'redrock', 'redrose', 'redslate', 'salsa', 'showtime', 'simplewish', 'skylight', 'springtime', 'starrynights', 'teblugre', 'tequilasun', 'walruspink', 'white'), true ) ) :
        $value = 'colors';
    endif;
    return $value;
}
// Sanitize checkboxes
function pmthemes_sanitize_checkbox( $value ) {
    if ( $value == 1) :
        return 1;
    else:
        return '';
    endif;
}
// Sanitize the layout width value.
function pmthemes_sanitize_layout_width( $value ) {
    if ( ! in_array( $value, array( 'boxed', 'wide' ), true ) ) :
        $value = 'boxed';
    endif;
    return $value;
}
// Sanitize the top header location
function pmthemes_sanitize_topnav_align( $value ) {
    if ( ! in_array( $value, array( 'top-menu-left', 'top-menu-right'), true ) ) :
        $value = 'top-menu-left';
    endif;
    return $value;
}
// Sanitize the main header location
function pmthemes_sanitize_main_nav_loc( $value ) {
    if ( ! in_array( $value, array( 'main-menu-below', 'main-menu-header'), true ) ) :
        $value = 'main-menu-below';
    endif;
    return $value;
}
// Sanitize the top bar location
function pmthemes_sanitize_top_bar_loc( $value ) {
    if ( ! in_array( $value, array( 'top-bar-most', 'top-bar-under'), true ) ) :
        $value = 'top-bar-most';
    endif;
    return $value;
}
// Gradient Direction
function pmthemes_sanitize_gradient_direction( $value ) {
    if ( ! in_array( $value, array( 'to bottom', 'to right', 'to top', 'to left'), true ) ) :
        $value = 'to bottom';
    endif;
    return $value;
}
// Sanitize relates posts order
function pmthemes_sanitize_related_post_order( $value ) {
    if ( ! in_array( $value, array('latest-posts', 'old-posts', 'random-posts'), true ) ) :
        $value = 'latest-posts';
    endif;
    return $value;
}
// Sanitize the layout sidebar value.
function pmthemes_sanitize_layout( $value ) {
    if ( ! in_array( $value, array('left-sidebar', 'right-sidebar', 'fullwidth' ), true ) ) :
        $value = 'right-sidebar';
    endif;
    return $value;
}
// Sanitize the WC shop page layout value.
function pmthemes_sanitize_wc_layout( $value ) {
    if ( ! in_array( $value, array('wc_full_page', 'wc_show_sbar'), true ) ) :
        $value = 'wc_full_page';
    endif;
    return $value;
}
// Sanitize the theme style value.
function pmthemes_sanitize_theme_style( $value ) {
    if ( ! in_array( $value, array('boxed-one', 'wide-head' ), true ) ) :
        $value = 'boxed-one';
    endif;
    return $value;
}
// Sanitize the related post style value.
function pmthemes_sanitize_related_post_style( $value ) {
    if ( ! in_array( $value, array('four-cols', 'three-cols', 'two-cols', 'simple-list'), true ) ) :
        $value = 'four-cols';
    endif;
    return $value;
}
// Sanitize the grid with value.
function pmthemes_sanitize_pmth_grid_width( $value ) {
    if ( ! in_array( $value, array('one-column', 'one-hundred', 'one-fifty', 'two-hundred', 'two-fifty', 'three-hundred', 'three-fifty', 'four-hundred', 'four-fifty ', 'five-hundred'), true ) ) :
        $value = 'one-column';
    endif;
    return $value;
}
// Sanitize grid columns.
function pmthemes_sanitize_pmth_grid_column( $value ) {
    if ( ! in_array( $value, array('one-col', 'two-col', 'three-col', 'four-col', 'five-col', 'six-col', 'seven-col', 'eight-col', 'nine-col', 'ten-col', 'eleven-col', 'twelve-col'), true ) ) :
        $value = 'one-col';
    endif;
    return $value;
}
// Sanitize align images.
function pmthemes_sanitize_align_images( $value ) {
    if ( ! in_array( $value, array('alignleft', 'alignright', 'aligncenter', 'alignnone'), true ) ) :
        $value = 'alignleft';
    endif;
    return $value;
}
// Sanitize align elements.
function pmthemes_sanitize_align_elements( $value ) {
    if ( ! in_array( $value, array('pmthleft', 'pmthrigth', 'pmthcenter', 'pmthjustify', 'pmthnone'  ), true ) ) :
        $value = 'pmthleft';
    endif;
    return $value;
}
// Sanitize grid column option.
function pmthemes_sanitize_grid_col_opt( $value ) {
    if ( ! in_array( $value, array( 'pmth-grid-coln', 'pmth-grid-itmw'  ), true ) ) :
        $value = 'pmth-grid-itmw';
    endif;
    return $value;
}
// Sanitize image size.
function pmthemes_sanitize_image_size( $value ) {
    if ( ! in_array( $value, array( 'pmth-img-large', 'pmth-img-thumb'  ), true ) ) :
        $value = 'pmth-img-thumb';
    endif;
    return $value;
}
// Sanitize the theme width value.
function pmthemes_sanitize_theme_width( $value ) {
    if ( ! in_array( $value, array( 'wd1', 'wd2', 'wd3', 'wd4', 'wd5', 'wd6', 'wd7', 'wd8', 'wd9', 'wd10'), true ) ) :
        $value = 'wd1';
    endif;
    return $value;
}
// Sanitize the footer widgets value.
function pmthemes_sanitize_fwidgets( $value ) {
    if ( ! in_array( $value, array( '0', '1', '2', '3', '4'), true ) ) :
        $value = '3';
    endif;
    return $value;
}
// Sanitize the post length value.
function pmthemes_sanitize_post_length( $value ) {
    if ( ! in_array( $value, array( 'excerpt', 'fullpost'  ), true ) ) :
        $value = 'excerpt';
    endif;
    return $value;
}
// Sanitize the slider animation value.
function pmthemes_sanitize_slider_animation( $value ) {
    if ( ! in_array( $value, array( 'horizontal', 'fade' ), true ) ) :
        $value = 'horizontal';
    endif;
    return $value;
}
// Sanitize footer content textarea
function pmthemes_sanitize_footer_text( $value ) {
    if ( current_user_can('unfiltered_html') ) :
        return $value;
    else :
        return stripslashes( wp_filter_post_kses( addslashes($value) ) );
    endif;
}
// Sanitize header code textarea
function pmthemes_sanitize_header_code( $value ) {
    if ( current_user_can('unfiltered_html') ) :
        return $value;
    else :
        return stripslashes( wp_filter_post_kses( addslashes($value) ) );
    endif;
}
// Sanitize footer code textarea
function pmthemes_sanitize_track_code( $value ) {
    if ( current_user_can('unfiltered_html') ) :
        return $value;
    else :
        return stripslashes( wp_filter_post_kses( addslashes($value) ) );
    endif;
}
// Sanitize read more content textarea
function pmthemes_sanitize_read_text( $value ) {
    if ( current_user_can('filtered_html') ) :
        return $value;
    else :
        return stripslashes( wp_filter_post_kses( ($value) ) );
    endif;
}
// Sanitize available fonts value.
function pmthemes_sanitize_available_fonts( $value ) {
    if ( ! in_array( $value, array( 'default', 'favorites', 'popular', 'all' ), true ) ) :
        $value = 'favorites';
    endif;
    return $value;
}
function pmthemes_sanitize_number( $value ) {
    return is_numeric( $value ) ? $value : 0;
}
function pmthemes_sanitize_number_blank( $val ) {
    return is_numeric( $val ) ? $val : '';
}
function pmthemes_sanitize_decimal_int( $input ) {
    return abs( floatval( $input ) );
}
function pmthemes_sanitize_decimal_int_empty( $input ) {
    if ( '' == $input ) {
        return '';
    }
    return abs( floatval( $input ) );
}