Skip to content

Instantly share code, notes, and snippets.

View wpscholar's full-sized avatar
😀
Happy

Micah Wood wpscholar

😀
Happy
View GitHub Profile
@wpscholar
wpscholar / sanitize-html-class.php
Created August 9, 2014 13:11
Sanitize HTML class example
<?php
$html_class = sanitize_html_class( $_POST['html_class'] );
update_post_meta( get_the_ID(), 'html_class', $html_class );
@wpscholar
wpscholar / validate-safe-html.php
Created August 9, 2014 13:15
Validate safe HTML example
<?php
$message = wp_kses_post( $_POST['message'] );
update_post_meta( get_the_ID(), 'message', $message );
@wpscholar
wpscholar / validate-html.php
Created August 9, 2014 13:19
Validate that HTML is valid and safe
<?php
$excerpt = wp_kses_post( balanceTags( substr( $_POST['content'], 0, 300 ), true ) );
update_post_meta( get_the_ID(), 'excerpt', $excerpt );
@wpscholar
wpscholar / validate-email.php
Created August 9, 2014 13:23
Validate email example
<?php
register_meta( 'post', 'email', 'is_email' );
update_post_meta( get_the_ID(), 'email', $_POST['email'] );
@wpscholar
wpscholar / validate-postal-code.php
Created August 9, 2014 13:26
Validate postal code example
<?php
$postal_code = $_POST['postal_code'];
if ( preg_match( '/[0-9]{5}/', $postal_code ) ) {
update_post_meta( get_the_ID(), 'postal_code', $postal_code );
}
@wpscholar
wpscholar / sanitize-postal-code.php
Last active August 29, 2015 14:05
Sanitize postal code example
<?php
$postal_code = preg_replace( '/[^0-9]/', '', $_POST['postal_code'] );
update_post_meta( get_the_ID(), 'postal_code', $postal_code );
@wpscholar
wpscholar / esc-attr.php
Last active August 29, 2015 14:05
Escape attribute example
<div class="<?php echo esc_attr( $_POST['layout'] ); ?>">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy...
</div>
@wpscholar
wpscholar / esc-attr-e.php
Created August 9, 2014 19:47
Escape attribute with translation example
<input name="s" placeholder="<?php esc_attr_e( 'Search', 'textdomain' ); ?>" />
@wpscholar
wpscholar / esc-html.php
Last active August 29, 2015 14:05
Escape HTML example
<h1><?php echo esc_html( $title ); ?></h1>
@wpscholar
wpscholar / esc-textarea.php
Created August 9, 2014 19:58
Escape textarea example
<label>
<span><?php _e( 'Label', 'textdomain' ); ?></span>
<textarea name="message"><?php echo esc_textarea( $_POST['message'] ); ?></textarea>
</label>