Skip to content

Instantly share code, notes, and snippets.

View petertwise's full-sized avatar

Peter Wise petertwise

View GitHub Profile
@petertwise
petertwise / wpcf7-thankyou-per-form.js
Last active March 1, 2018 18:06
Contact Form 7 - thank you page per form
document.addEventListener( 'wpcf7mailsent', function(event) {
// console.log(event.detail.contactFormId, event);
switch( event.detail.contactFormId ) {
case "1234":
// thank you page for form ID 1234 "My Form 1"
location='https://example.com/form1/thank-you/';
break;
case "1235":
// thank you page for form ID 1235 "My Form 2"
location='https://example.com/form2/thank-you/';
@petertwise
petertwise / subnetmasks.txt
Created October 18, 2017 01:57
Cheat Sheet for IP Address "wildcards" CIDR Notation - Subnet Mask
# These are the only common ones ever used...
# If you need a reference for anything inbetween these: https://tools.ietf.org/html/rfc4632#page-7
123.456.0.0/8 = 123.*.*.*
123.456.0.0/16 = 123.456.*.*
123.456.789.0/24 = 123.456.789.*
123.456.789.012/32 = 123.456.789.012
@petertwise
petertwise / functions.php
Last active June 7, 2023 05:29
Resolve GiveWP and WooCommerce stripe-js loading twice conflict
<?php
// account for conflicts between GiveWP Stripe AND WooCommerce Stripe script loading
function squarecandy_givewp_woocommerce_stripe_resolve() {
// check if both Stripe plugins are active
if ( is_plugin_active( 'woocommerce-gateway-stripe/woocommerce-gateway-stripe.php' ) && is_plugin_active( 'give-stripe/give-stripe.php' ) ) :
// WC doesn't load stripe on every page.
// Check if they are both being enqueued in the current context before disabling one.
if ( wp_script_is( 'stripe', 'enqueued' ) && wp_script_is( 'give-stripe-js', 'enqueued' ) ) {
// @TODO - should we compare and make sure the file contents are actually the same here?
@petertwise
petertwise / gist:b30a253fa087c66bfe33e34f4e3df998
Created August 24, 2017 15:52 — forked from icemancast/gist:d94c2fcfe5ccf073330aab4a7d55765b
WooCommerce: change "add to cart" button text by product type
<?php
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
/**
* custom_woocommerce_template_loop_add_to_cart
*/
function custom_woocommerce_product_add_to_cart_text() {
global $product;
$product_type = $product->get_type();
@petertwise
petertwise / squarecandy-woocommerce-customizations.php
Created August 15, 2017 23:42
Square Candy WooCommerce Customizations
<?php
/*
Plugin Name: Square Candy WooCommerce Customizations
@petertwise
petertwise / debug-givewp.php
Last active March 2, 2018 19:00
Give givewp.com Donation Plugin - list of all actions and filters for testing.
<?php
/*
Plugin Name: Debug Give Wp
Plugin URI: https://gist.github.com/squarecandy/8ed8265bde0c39e42ab8a19c062bf534
Description: Help discover where all of Give's action can plop in some content, and what all the filters do
Version: 1.0
Author: Square Candy
Author URI: http://squarecandy.net
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl.txt
@petertwise
petertwise / social-sharer.php
Created May 20, 2017 06:15
PHP social sharer function for WordPress w/ FontAwesome
<?php
function squarecandy_get_share_icons($url, $text = '', $twitterhandle = '', $subject = 'I thought you might enjoy this...' ){
// encode url and text parts
$encodedurl = urlencode($url);
$encodedtext = urlencode($text);
$rawencodedtext = rawurldecode($text);
// calculate the allowable tweet length... 140 - ( elipsis and two spaces [5 char] + the url [always counts as 23] + @twittername [calculate length] )
$tweetlength = 140 - ( 5 + 23 + strlen($twitterhandle) );
@petertwise
petertwise / functions.php
Last active May 4, 2017 17:25
SearchWP support request
<?php
## This is what I want to do - create a straight meta_key ordering for search results - no SearchWP weights involved at all
// Modify the default blog page & archive queries
function squarecandy_modify_main_query( $query ) {
// main page / main blog query
if ( $query->is_home() && $query->is_main_query() ) {
$query->query_vars['posts_per_page'] = -1;
$query->query_vars['orderby'] = 'meta_value_num';
@petertwise
petertwise / program.html
Created April 26, 2017 17:09
marathon 2017 program order
<p><em><strong>[SET TIMES ARE APPROXIMATE]</strong></em></p>
<h3>2:00pm</h3>
<div class="work"><span class="composer">Julia Wolfe</span> <em>Steel Hammer</em></div>
<p><span class="performer">Bang on a Can All-Stars with:<br>Emily Eagen, Katie Geissinger, Molly Quinn - voice</span></p>
<p><span class="location">Beaux Arts Court Stage</span></p>
<h3>3:30pm</h3>
<div class="work"><span class="composer">Innov Gnawa</span> works to be announced from stage</div>
<p><span class="performer">Innov Gnawa</span></p>
<p><span class="location">Beaux Arts Court Stage</span></p>
<h3>4:00pm</h3>
@petertwise
petertwise / awsconvert
Created April 19, 2017 04:34
Custom Elastic Transcoder Script for Bang on a Can by Square Candy
#!/bin/bash
# Custom Elastic Transcoder Script for Bang on a Can by Square Candy
# Check for valid input
[[ "$1" && "$2" && "$3" ]] || { printf "Missing command arguments.\nUsage: awsconvert [audio/video] file-name_base ext\n" >&2; exit 1; }
[[ $1 = audio || $1 = video ]] || { printf "First argument must be either 'audio' or 'video'\nUsage: awsconvert [audio/video] file-name_base ext\n" >&2; exit 2; }
[[ $2 != *[^a-z0-9\_-]* ]] || { printf "Error: filename argument must contain only lowercase letters, numbers, underscores and dashes.\nUsage: awsconvert [audio/video] file-name_base ext\n" >&2; exit 3; }
case "$1" in
'audio')