Skip to content

Instantly share code, notes, and snippets.

View justinwhall's full-sized avatar

Justin W Hall justinwhall

View GitHub Profile
@justinwhall
justinwhall / gist:2925755
Created June 13, 2012 18:49
PHP: sanitize inputs
function sanitize($input) {
if (is_array($input)) {
foreach($input as $var=>$val) {
$output[$var] = sanitize($val);
}
}
else {
if (get_magic_quotes_gpc()) {
$input = stripcslashes($input);
}
@justinwhall
justinwhall / gist:2638815
Created May 8, 2012 19:48
PHP: mysql_prep | escape data for mysql INSERTS
function mysql_prep( $value ) {
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
if( $new_enough_php ) { // PHP v4.3.0 or higher
// undo any magic quote effects so mysql_real_escape_string can do the work
if( $magic_quotes_active ) { $value = stripslashes( $value ); }
$value = mysql_real_escape_string( $value );
} else { // before PHP v4.3.0
// if magic quotes aren't already on then add slashes manually
if( !$magic_quotes_active ) { $value = addslashes( $value ); }
@justinwhall
justinwhall / gist:2362880
Created April 11, 2012 21:38
PHP: WordPress | ex Widget
class Example_Widget extends WP_Widget {
/**
* Widget setup.
*/
function Example_Widget() {
/* Widget settings. */
$widget_ops = array( 'classname' => 'sidebar-menu', 'description' => __('Displays a menu in the side bar of "Review Us", "Welcome Packet" and "Patient Forms".', 'example') );
/* Widget control settings. */
@justinwhall
justinwhall / gist:2286328
Created April 2, 2012 18:57
PHP : WordPress | Custom Meta Box
//meta box
$prefix = 'sic_';
$meta_box = array(
'id' => 'my-meta-box',
'title' => 'Ride Stats!',
'page' => 'rides',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
@justinwhall
justinwhall / gist:2286312
Created April 2, 2012 18:56
PHP : WordPress | Register Custom Post Type
//Register Custom Post Type
add_action('init', 'codex_custom_init');
function codex_custom_init()
{
$labels = array(
'name' => _x('Rides', 'Ride'),
'singular_name' => _x('Rides', 'Ride'),
'add_new' => _x('Add New', 'Ride'),
'add_new_item' => __('Add New Ride'),
'edit_item' => __('Edit Ride'),
@justinwhall
justinwhall / gist:2286280
Created April 2, 2012 18:50
PHP : WordPress | Custom Taxonomy
//Custom taxonomy
function build_taxonomies() {
// create a new taxonomy
register_taxonomy(
'Tax_name',
'For_post_ype',
array(
'label' => __( 'Tax_label' ),
'sort' => true,
@justinwhall
justinwhall / gist:2139927
Created March 20, 2012 19:07
PHP: WordPress | Social_Share_it
//social share
function social_share_it(){
//get the user entered URLS/usernames from WP backend
$twitter = mytheme_option('twitter');
$facebook = mytheme_option('facebook');
$googleplus = mytheme_option('googleplus');
?>
<?php //print he icons ?>
<ul id="social-share">
@justinwhall
justinwhall / gist:2051050
Created March 16, 2012 16:46
PHP: WordPress | register basic widget
add_action( 'widgets_init', 'example_load_widgets' );
/**
* Register our widget.
* 'Example_Widget' is the widget class used below.
*
* @since 0.1
*/
function example_load_widgets() {
register_widget( 'Example_Widget' );
@justinwhall
justinwhall / CSS | Centered Menu
Created March 15, 2012 22:43
CSS Centered Menu
#centered{
width:100%;
float: left;
overflow: hidden;
position: relative;
}
#centered ul{
clear:left;
float:left;
list-style:none;
@justinwhall
justinwhall / form-validator.js
Created March 8, 2012 01:42
jQuery: Form validator
jQuery(document).ready(function() {
jQuery('form#contactForm').submit(function() {
jQuery('form#contactForm .error').remove();
var hasError = false;
jQuery('.requiredField').each(function() {
if(jQuery.trim(jQuery(this).val()) == '') {
//var labelText = jQuery(this).prev('label').text();
jQuery(this).parent().append('<span class="error text-error">&larr; Required field</span>');
hasError = true;
}