-
-
Save tommcfarlin/3ecc9e078352ecb5da61 to your computer and use it in GitHub Desktop.
[WordPress] Sanitization Classes of the WordPress Settings API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Address_Setting { | |
/** | |
* A custom sanitization function that will take the incoming input, and sanitize | |
* the input before handing it back to WordPress to save to the database. | |
* If the input is not valid, then the data will not be saved and an error | |
* message will be added to WordPress' error collection. | |
* | |
* @since 1.0.0 | |
* | |
* @param array $input The address input. | |
* @return mixed $new_input The sanitized input or false (to prevent the data from saving) | |
*/ | |
public function sanitize( $input ) { | |
$new_input = false; | |
$validator = new Address_Validator( $this ); | |
if ( $validator->is_valid( $input ) ) { | |
$new_input = array(); | |
foreach ( $input as $key => $val ) { | |
$new_input[ $key ] = sanitize_text_field( $val ); | |
} | |
} | |
return $new_input; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class City_Setting { | |
/** | |
* A custom sanitization function that will take the incoming input, and sanitize | |
* the input before handing it back to WordPress to save to the database. | |
* If the input is not valid, then the data will not be saved and an error | |
* message will be added to WordPress' error collection. | |
* | |
* @since 1.0.0 | |
* | |
* @param array $input The city input. | |
* @return mixed $new_input The sanitized input or false (to prevent the data from saving) | |
*/ | |
public function sanitize( $input ) { | |
$new_input = false; | |
$validator = new Postal_Code_Validator( $this ); | |
if ( $validator->is_valid( $input ) ) { | |
$new_input = array(); | |
foreach ( $input as $key => $val ) { | |
$new_input[ $key ] = sanitize_text_field( $val ); | |
} | |
} | |
return $new_input; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Postal_Code_Setting { | |
/** | |
* A custom sanitization function that will take the incoming input, and sanitize | |
* the input before handing it back to WordPress to save to the database. | |
* If the input is not valid, then the data will not be saved and an error | |
* message will be added to WordPress' error collection. | |
* | |
* @since 1.0.0 | |
* | |
* @param array $input The city input. | |
* @return mixed $new_input The sanitized input or false (to prevent the data from saving) | |
*/ | |
public function sanitize( $input ) { | |
$new_input = false; | |
$validator = new Postal_Code_Validator( $this ); | |
if ( $validator->is_valid( $input ) ) { | |
$new_input = array(); | |
foreach ( $input as $key => $val ) { | |
$new_input[ $key ] = sanitize_text_field( $val ); | |
} | |
} | |
return $new_input; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment