Skip to content

Instantly share code, notes, and snippets.

@weartstudio
Last active September 10, 2022 08:55
Show Gist options
  • Select an option

  • Save weartstudio/d4365d33c3f3c9da681211fc767027a5 to your computer and use it in GitHub Desktop.

Select an option

Save weartstudio/d4365d33c3f3c9da681211fc767027a5 to your computer and use it in GitHub Desktop.

Revisions

  1. weartstudio revised this gist Jun 26, 2019. No changes.
  2. weartstudio revised this gist Jun 26, 2019. 1 changed file with 54 additions and 45 deletions.
    99 changes: 54 additions & 45 deletions sanitize.php
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,58 @@
    <?php

    //sanitize adsense box adsense codes
    function weart_sanitize_adsense( $input ) {
    esc_js($input);
    $input = str_replace(array("\r", "\n"), '', $input);
    return $input;
    }

    //sanitize checkbox
    function weart_sanitize_checkbox( $input ) {
    return ( ( isset( $input ) && true == $input ) ? true : false );
    }

    //sanitize text
    function weart_sanitize_text( $input ) {
    return wp_kses_post( force_balance_tags( $input ) );
    }

    //sanitize select
    function weart_sanitize_select( $input, $setting ) {
    global $wp_customize;
    $control = $wp_customize->get_control( $setting->id );
    if ( array_key_exists( $input, $control->choices ) ) {
    return $input;
    } else {
    return $setting->default;

    //sanitize adsense box adsense codes
    function weart_sanitize_adsense( $input ) {
    esc_js($input);
    $input = str_replace(array("\r", "\n"), '', $input);
    return $input;
    }

    //sanitize checkbox
    function weart_sanitize_checkbox( $input ) {
    return ( ( isset( $input ) && true == $input ) ? true : false );
    }
    }

    // sanitize number
    function weart_sanitize_number_absint( $number, $setting ) {
    // Ensure $number is an absolute integer (whole number, zero or greater).
    $number = absint( $number );
    // If the input is an absolute integer, return it; otherwise, return the default
    return ( $number ? $number : $setting->default );
    }

    // sanitize radio button
    function weart_sanitize_radio( $input, $setting ) {
    // Ensure input is a slug.
    $input = sanitize_key( $input );
    // Get list of choices from the control associated with the setting.
    $choices = $setting->manager->get_control( $setting->id )->choices;
    // If the input is a valid key, return it; otherwise, return the default.
    return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
    }

    //sanitize text
    function weart_sanitize_text( $input ) {
    return esc_html( $input );
    }

    //sanitize select
    function weart_sanitize_select( $input, $setting ) {
    global $wp_customize;
    $control = $wp_customize->get_control( $setting->id );
    if ( array_key_exists( $input, $control->choices ) ) {
    return $input;
    } else {
    return $setting->default;
    }
    }

    // sanitize number
    function weart_sanitize_number_absint( $number, $setting ) {
    // Ensure $number is an absolute integer (whole number, zero or greater).
    $number = absint( $number );
    // If the input is an absolute integer, return it; otherwise, return the default
    return ( $number ? $number : $setting->default );
    }

    // sanitize radio button
    function weart_sanitize_radio( $input, $setting ) {
    // Ensure input is a slug.
    $input = sanitize_key( $input );
    // Get list of choices from the control associated with the setting.
    $choices = $setting->manager->get_control( $setting->id )->choices;
    // If the input is a valid key, return it; otherwise, return the default.
    return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
    }

    // sanitize img upload
    function weart_sanitize_image( $input ) {
    $filetype = wp_check_filetype( $input );
    if ( $filetype['ext'] && wp_ext2type( $filetype['ext'] ) === 'image' ) {
    return esc_url( $input );
    }
    return '';
    }

    ?>
  3. weartstudio revised this gist Oct 20, 2017. No changes.
  4. weartstudio revised this gist Oct 20, 2017. 1 changed file with 39 additions and 39 deletions.
    78 changes: 39 additions & 39 deletions sanitize.php
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,49 @@
    <?php

    //sanitize adsense box adsense codes
    function weart_sanitize_adsense( $input ) {
    esc_js($input);
    $input = str_replace(array("\r", "\n"), '', $input);
    return $input;
    }
    //sanitize adsense box adsense codes
    function weart_sanitize_adsense( $input ) {
    esc_js($input);
    $input = str_replace(array("\r", "\n"), '', $input);
    return $input;
    }

    //sanitize checkbox
    function weart_sanitize_checkbox( $input ) {
    return ( ( isset( $input ) && true == $input ) ? true : false );
    }
    //sanitize checkbox
    function weart_sanitize_checkbox( $input ) {
    return ( ( isset( $input ) && true == $input ) ? true : false );
    }

    //sanitize text
    function weart_sanitize_text( $input ) {
    return wp_kses_post( force_balance_tags( $input ) );
    }
    //sanitize text
    function weart_sanitize_text( $input ) {
    return wp_kses_post( force_balance_tags( $input ) );
    }

    //sanitize select
    function weart_sanitize_select( $input, $setting ) {
    global $wp_customize;
    $control = $wp_customize->get_control( $setting->id );
    if ( array_key_exists( $input, $control->choices ) ) {
    return $input;
    } else {
    return $setting->default;
    }
    //sanitize select
    function weart_sanitize_select( $input, $setting ) {
    global $wp_customize;
    $control = $wp_customize->get_control( $setting->id );
    if ( array_key_exists( $input, $control->choices ) ) {
    return $input;
    } else {
    return $setting->default;
    }
    }

    // sanitize number
    function weart_sanitize_number_absint( $number, $setting ) {
    // Ensure $number is an absolute integer (whole number, zero or greater).
    $number = absint( $number );
    // If the input is an absolute integer, return it; otherwise, return the default
    return ( $number ? $number : $setting->default );
    }
    // sanitize number
    function weart_sanitize_number_absint( $number, $setting ) {
    // Ensure $number is an absolute integer (whole number, zero or greater).
    $number = absint( $number );
    // If the input is an absolute integer, return it; otherwise, return the default
    return ( $number ? $number : $setting->default );
    }

    // sanitize radio button
    function weart_sanitize_radio( $input, $setting ) {
    // Ensure input is a slug.
    $input = sanitize_key( $input );
    // Get list of choices from the control associated with the setting.
    $choices = $setting->manager->get_control( $setting->id )->choices;
    // If the input is a valid key, return it; otherwise, return the default.
    return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
    }
    // sanitize radio button
    function weart_sanitize_radio( $input, $setting ) {
    // Ensure input is a slug.
    $input = sanitize_key( $input );
    // Get list of choices from the control associated with the setting.
    $choices = $setting->manager->get_control( $setting->id )->choices;
    // If the input is a valid key, return it; otherwise, return the default.
    return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
    }

    ?>
  5. weartstudio created this gist Oct 20, 2017.
    49 changes: 49 additions & 0 deletions sanitize.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    <?php

    //sanitize adsense box adsense codes
    function weart_sanitize_adsense( $input ) {
    esc_js($input);
    $input = str_replace(array("\r", "\n"), '', $input);
    return $input;
    }

    //sanitize checkbox
    function weart_sanitize_checkbox( $input ) {
    return ( ( isset( $input ) && true == $input ) ? true : false );
    }

    //sanitize text
    function weart_sanitize_text( $input ) {
    return wp_kses_post( force_balance_tags( $input ) );
    }

    //sanitize select
    function weart_sanitize_select( $input, $setting ) {
    global $wp_customize;
    $control = $wp_customize->get_control( $setting->id );
    if ( array_key_exists( $input, $control->choices ) ) {
    return $input;
    } else {
    return $setting->default;
    }
    }

    // sanitize number
    function weart_sanitize_number_absint( $number, $setting ) {
    // Ensure $number is an absolute integer (whole number, zero or greater).
    $number = absint( $number );
    // If the input is an absolute integer, return it; otherwise, return the default
    return ( $number ? $number : $setting->default );
    }

    // sanitize radio button
    function weart_sanitize_radio( $input, $setting ) {
    // Ensure input is a slug.
    $input = sanitize_key( $input );
    // Get list of choices from the control associated with the setting.
    $choices = $setting->manager->get_control( $setting->id )->choices;
    // If the input is a valid key, return it; otherwise, return the default.
    return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
    }

    ?>