Skip to content

Instantly share code, notes, and snippets.

View JustinSainton's full-sized avatar

Justin Sainton JustinSainton

View GitHub Profile
(function($){
var hide_fields = function() {
$( '#wpsc-checkout-field-billingcity, #wpsc-checkout-field-billingstate, #wpsc-checkout-field-billingcountry' ).addClass( 'ui-helper-hidden-accessible' );
},
show_fields = function() {
$( '#wpsc-checkout-field-billingcity, #wpsc-checkout-field-billingstate, #wpsc-checkout-field-billingcountry' ).removeClass( 'ui-helper-hidden-accessible' );
},
@JustinSainton
JustinSainton / admin-bar-word-count.php
Created May 15, 2015 04:51
Show amount of words published this year in the admin bar. Pat yo'self on the back,
<?php
/*
* Plugin Name: Publish Count
* Plugin URI: http://zao.is
* Description: Check year-to-date published character count
* Version: 1.0
* Author: Justin Sainton
* Author URI: http://zao.is
*/
class WP_Word_Count {
@JustinSainton
JustinSainton / test.php
Last active August 29, 2015 14:21 — forked from lizkaraffa/gist:190587cfb7e653160141
Description
<?php
public function add_meta_box( $post_type ) {
$post_type = 'notes'; //limit meta box to certain post types
add_meta_box(
'handshaken_note_settings',
__( 'Note Settings', 'handshaken' ),
array( $this, 'render_meta_box_content_note' ),
$post_type,
'advanced',
@JustinSainton
JustinSainton / git-branch.php
Created April 22, 2015 23:43
Print current plugin branch to admin bar
<?php
public function admin_bar_menu() {
global $wp_admin_bar;
$plugin_path = ABSPATH . 'wp-content/plugins/WP-e-Commerce';
exec( 'cd ' . $plugin_path . ' && git rev-parse --abbrev-ref HEAD', $output, $return );
$wp_admin_bar->add_menu( array(
@JustinSainton
JustinSainton / what-the-crap.php
Created March 17, 2015 18:03
Seriously. What?
<?php
if ( some_irrelevant_condition() ) {
echo '(' . json_encode( $results ) . ')';
die();
} else {
echo '({"error":"' . __( 'Error updating product', 'wpsc' ) . '", "id": "'. esc_js( $_POST['id'] ) .'"})';
}
@JustinSainton
JustinSainton / 0_reuse_code.js
Last active August 29, 2015 14:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@JustinSainton
JustinSainton / gist:36be9fb9c7d9f55f6e37
Created November 28, 2014 22:34
Scrutinizer CI Config for WP eCommerce
tools:
puppet_lint:
flags: ''
js_hint: true
php_mess_detector:
config:
naming_rules: { boolean_method_name: true }
controversial_rules: { superglobals: false }
php_code_sniffer:
config:
@JustinSainton
JustinSainton / json-msg.php
Created September 26, 2014 00:22
json msg
<?php
if (!function_exists('json_last_error_msg')) {
function json_last_error_msg() {
static $errors = array(
JSON_ERROR_NONE => null,
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
@JustinSainton
JustinSainton / hide-testmode-conditionally.php
Created September 20, 2014 19:24
Hide test gateway if a user is not an admin
<?php
add_filter( 'option_custom_gateway_options', 'js_gateway_options' );
function js_gateway_options( $gateways ) {
if ( in_array( 'wpsc_merchant_testmode', $gateways ) && ! current_user_can( 'manage_options' ) ) {
unset( $gateways[ array_search( 'wpsc_merchant_testmode', $gateways ) ] );
}
<?php
/** Automatically append mtime to script and style versions for cache-busting action **/
add_action( 'wp_enqueue_scripts', function() {
global $wp_styles, $wp_scripts;
foreach( array( 'wp_styles', 'wp_scripts' ) as $resource ) {
foreach( $$resource->registered as $name => $registered_resource ) {
// Not hosted here