Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
WillBrubaker / pre-commit
Created June 8, 2014 14:40
A pre-commit hook to minify css & js when committing to branch 'master'
#!/bin/sh
#
# A pre-commit hook to minify js & css files
# if committing to branch 'master'
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [ "$BRANCH" == 'master' ]
then
csspath='css/*.css'
jspath='js/*.js'
@WillBrubaker
WillBrubaker / auth-filter.php
Last active August 29, 2015 14:02
An authentication filter for your WordPress development environment
<?php
/**
* Filters 'authenticate'
* to keep user with id 1
* logged in without needing
* to enter l/p
*/
add_filter( 'authenticate', 'wwm_authenticate_filter', 10, 1 );
@WillBrubaker
WillBrubaker / custom-redirect.php
Last active August 29, 2015 14:03
An example of how to redirect after survey submission for the Awesome Surveys WordPress plugin. Requires Awesome Surveys version > 1.1.1
<?php
/*
Plugin Name: Custom Redirect for Awesome Surveys
Plugin URI: http://www.willthewebmechanic.com/awesome-surveys
Description: Redirects to a specified link after survey submission
Version: 1.0
Author: Will Brubaker
Author URI: http://www.willthewebmechanic.com
License: GPLv3.0
*/
@WillBrubaker
WillBrubaker / products_sold_snippet.php
Created August 6, 2014 15:33
A snippet of code demonstrating how to create a shortcode that will output a number of items sold - This is specific to woocommerce
<?php
/* Do not copy the opening <?php tag above */
//Add the shortcode tag with its callback function:
add_shortcode( 'display_tickets_sold', 'wwm_display_tickets_sold' );
/**
* Given a valid product id, Outputs a number of 'units sold'
* Usage [display_tickets_sold product_id="####"] where #### is a valid product id.
@WillBrubaker
WillBrubaker / messages_nl.js
Created August 21, 2014 12:44
Language file for the jquery validation plugin - edited to work with noconflict mode
/*
* Translated default messages for the jQuery validation plugin.
* Locale: NL (Dutch; Nederlands, Vlaams)
*/
jQuery.extend(jQuery.validator.messages, {
required: "Dit is een verplicht veld.",
remote: "Controleer dit veld.",
email: "Vul hier een geldig e-mailadres in.",
url: "Vul hier een geldige URL in.",
date: "Vul hier een geldige datum in.",
@WillBrubaker
WillBrubaker / snippet.php
Created August 21, 2014 12:46
Code snippet to load custom messages for jQuery validation plugin within the Awesome Surveys WordPress plugin
<?php
/*
Plugin Name: Code With WP Custom Snippets
Plugin URI: http://codewithwp.com/
Description: This plugin holds custom code snippets that interact with both themes and plugins related to this website.
Author: Thomas Griffin
Author URI: http://thomasgriffinmedia.com/
Version: 1.0.0
License: GNU General Public License v2.0 or later
License URI: http://www.opensource.org/licenses/gpl-license.php
@WillBrubaker
WillBrubaker / subscriptions-remove-strings.php
Created October 29, 2014 19:45
For WooCommerce Subscriptions, removes some of the strings during on the checkout page
<?php
/*
Don't copy the opening PHP tag
*/
add_filter( 'woocommerce_cart_item_subtotal', 'wooninja_display_subtotal', 20, 1 );
add_filter( 'woocommerce_cart_subtotal', 'wooninja_display_subtotal', 20, 1 );
add_filter( 'woocommerce_cart_total', 'wooninja_display_subtotal', 20, 1 );
function wooninja_display_subtotal( $subtotal ) {
@WillBrubaker
WillBrubaker / custom-durations.php
Last active August 29, 2015 14:09
Adds custom durations to woocommerce-subscriptions
<?php
//* Do NOT include the opening php tag
add_filter( 'woocommerce_subscription_lengths', 'wooninja_custom_subscription_duration' );
/**
* Filters the subscription lengths available
* @param array $ranges the array of ranges (lengths)
* @return array $ranges the filtered array of ranges (lengths)
*/
@WillBrubaker
WillBrubaker / num-answers-snippet.php
Created November 30, 2014 14:30
Customize the number of possible answers for questions with options (radio, checkbox, select) in Awesome Surveys survey builder
<?php
/*
Don't copy the opening php tag
*/
/*
The filter 'wwm_as_admin_script_vars' was added in version 1.6 of Awesome Surveys.
This is a sample of it's implementation. If you're comfortable with editing PHP files, use the snippet below.
It's usually recommended that these types of snippets be placed in your theme's functions.php file,
but I personally don't think that's a good idea since depending on how the theme update works you may
@WillBrubaker
WillBrubaker / bookings-label-filter.php
Created December 15, 2014 18:38
Filter WooCommerce bookings label
<?php
/*
Change the 'Persons' label to 'Qty. of Chairs'
*/
add_filter( 'booking_form_fields', 'wooninja_booking_form_fields' );
function wooninja_booking_form_fields( $fields ) {
$fields['wc_bookings_field_persons']['label'] = 'Qty. of Chairs';
return $fields;
}