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 / load-views.php
Created July 23, 2014 18:47
Load Ember templates in WordPress
<?php
/**
* Load Ember templates in WordPress
*/
public static function load_views() {
$iterator = new \DirectoryIterator( plugin_dir_path( __FILE__ ) . 'views' );
foreach ( $iterator as $file ) {
/**
* @var \SplFileInfo $file
@wpscholar
wpscholar / sanitize-mime-type.php
Created August 9, 2014 12:51
Sanitize mime type example
<?php
$mime_type = sanitize_mime_type( $_FILES['upload']['type'] );
update_post_meta( get_the_ID(), 'mime_type', $mime_type );
@wpscholar
wpscholar / sanitize-url.php
Created August 9, 2014 12:52
Sanitize url example
<?php
$url = esc_url_raw( $_POST['url'] );
update_post_meta( get_the_ID(), 'url', $url );
@wpscholar
wpscholar / sanitize-email.php
Created August 9, 2014 12:53
Sanitize email example
<?php
$email = sanitize_email( $_POST['email'] );
update_post_meta( get_the_ID(), 'email', $email );
@wpscholar
wpscholar / sanitize-title.php
Last active August 29, 2015 14:05
Sanitize title example
<?php
$slug = sanitize_title( $_POST['title'], 'untitled' );
update_post_meta( get_the_ID(), 'slug', $slug );
@wpscholar
wpscholar / sanitize-text-field.php
Created August 9, 2014 13:02
Sanitize text field example
<?php
$title = sanitize_text_field( $_POST['title'] );
update_post_meta( get_the_ID(), 'title', $title );
@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'] );