Skip to content

Instantly share code, notes, and snippets.

View petertwise's full-sized avatar

Peter Wise petertwise

View GitHub Profile
@petertwise
petertwise / swiftmailer-example.php
Last active August 19, 2018 19:51
example of swiftmailer usage
<?php
define('SITE_EMAIL', 'no-reply@example.com');
define('SITE_NAME', 'My Project');
function send_password_reset($email, $name, $resetlink) {
require_once( 'swiftmailer/swift_required.php' );
$subject = 'Resetting your password for ' . SITE_NAME;
@petertwise
petertwise / youtube-cover-art.php
Last active July 31, 2020 07:52
Get the best version of youtube cover image without using the API
<?php
function url_exists( $url ) {
$headers = get_headers($url);
return stripos( $headers[0], "200 OK" ) ? true : false;
}
function get_youtube_id( $url ) {
$youtubeid = explode('v=', $url);
$youtubeid = explode('&', $youtubeid[1]);
@petertwise
petertwise / Gruntfile.js
Created May 9, 2018 00:03
My Grunt Setup - no ruby required version
// inspired by https://gist.github.com/jshawl/6225945
// Thanks @jshawl!
// now using grunt-sass to avoid Ruby dependency
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: { // sass tasks
dist: {
@petertwise
petertwise / amazon-links.php
Last active October 8, 2019 21:00
Add Amazon affiliate tag to all Amazon links in WordPress the_content
@petertwise
petertwise / all-kinds-of-acf-fields.json
Last active March 9, 2018 03:33
ACF all fields for testing
[
{
"key": "group_5aa17612b7168",
"title": "Page Fields with Gutenberg",
"fields": [
{
"key": "field_5aa1807a67935",
"label": "Message",
"name": "",
"type": "message",
@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