Skip to content

Instantly share code, notes, and snippets.

View JustinSainton's full-sized avatar

Justin Sainton JustinSainton

View GitHub Profile
function avr_replace_title_with_meta( $title, $id ) {
$type = get_post_type();
if ( in_array( $type, array( 'property', 'rate' ) ) )
$title = get_post_meta( $id, 'avr_' . $type . '_title', true );
return $title;
}
add_filter( 'the_title', 'avr_replace_title_with_meta', 10, 2 );
<?php
if ( is_home() )
nivo_slider( 123 );
?>
<?php
/**
* API shit
*/
error_reporting(E_ALL);
ini_set('display_errors', true);
include_once '/var/www/xhprof/external/header.php';
$start = microtime(true);
@JustinSainton
JustinSainton / gist:4062453
Created November 12, 2012 22:31
Potential ?s issue in wpsc_start_the_query()
<?php
function remove_start_the_query() {
remove_action( 'template_redirect', 'wpsc_start_the_query', 8 );
}
add_action( 'template_redirect', 'remove_start_the_query' );
@JustinSainton
JustinSainton / form_list.php
Created November 18, 2012 21:30
Gravity Forms code example (yoda conditions, whitespace, indentation, brackets, camelcase, etc.)
<?php
class GFFormList{
public static function form_list_page(){
global $wpdb;
if(!GFCommon::ensure_wp_version())
return;
echo GFCommon::get_remote_message();
<?php
$args = array(
'meta_key' => '_cs-expire-date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_cs-expire-date',
'value' => time(),
'compare' => '>=',
@JustinSainton
JustinSainton / Random list
Created March 11, 2013 20:40
This will generate and post 4 random links from an array of 8.
<?php
$links = array(
'web development' => 'http://www.c9labs.com/web-dev/',
'web development' => 'http://www.c9labs.com/web-dev/',
'web development' => 'http://www.c9labs.com/web-dev/',
'web development' => 'http://www.c9labs.com/web-dev/',
'web development' => 'http://www.c9labs.com/web-dev/',
'web development' => 'http://www.c9labs.com/web-dev/',
'web development' => 'http://www.c9labs.com/web-dev/',
@JustinSainton
JustinSainton / gist:5400735
Created April 17, 2013 00:13
Here's the gist of it (buh dun dun pssssh) - The '_wpsc_product_metadata' meta key is an array of metadata. There's a key in that array that I always want to return false ( '0' in this case). I'd have thought that filtering get_post_metadata, removing the filter, grabbing the value, modifying and returning would do the trick. It doesn't. Always …
<?php
add_filter( 'get_post_metadata', 'zao_edit_per_product_shipping', 10, 4 );
function zao_edit_per_product_shipping( $check, $object_id, $meta_key, $single ) {
if ( '_wpsc_product_metadata' === $meta_key && has_filter( 'get_post_metadata', 'zao_edit_per_product_shipping' ) ) {
remove_filter( 'get_post_metadata', 'zao_edit_per_product_shipping', 10, 4 );
@JustinSainton
JustinSainton / url-spamcheck.php
Last active February 4, 2016 13:02 — forked from norcross/url-spamcheck.php
Marks any comment as spam whose author link is greater than 50 chars.
<?php
function rkv_url_spamcheck( $approved , $commentdata ) {
return ( strlen( $commentdata['comment_author_url'] ) > 50 ) ? 'spam' : $approved;
}
add_filter( 'pre_comment_approved', 'rkv_url_spamcheck', 99, 2 );
@JustinSainton
JustinSainton / gist:5475788
Created April 28, 2013 03:42
Working on cleaning up some javascript in WPeC. Getting rid of eval(), using .on(), using proper ajax endpoints, etc. Ran into an interesting challenge. We have "Fancy Notifications". You add a product to the cart and there's a little popup saying "Hey, you added a product to the cart." The function that does this essentially echoes jQuery code,…
//This would be the code that hooks into the custom event. Plugin authors should take this approach vs. the old PHP hook.
jQuery( document ).on( 'wpsc_fancy_notification', function( event ){
console.log(event.response);
});
function() {
var success = function( response ) {
jQuery( document ).trigger( { type : 'wpsc_fancy_notification', response : response } );
jQuery('div.shopping-cart-wrapper').html( response.widget_output );