Skip to content

Instantly share code, notes, and snippets.

View wturnerharris's full-sized avatar

Wes Turner-Harris wturnerharris

View GitHub Profile
@wturnerharris
wturnerharris / mysql_procedure_loop_ids_and_insert.sql
Created April 17, 2019 16:25
Here's a mysql stored procedure to loop through the results of a select query that returns ids and performs an additional operation on each id.
DROP PROCEDURE IF EXISTS migrateById;
DELIMITER $$
CREATE PROCEDURE migrateById()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE _post_id INT;
DECLARE migrate_ids CURSOR FOR
# modify the select statement to returns IDs, which will be assigned the variable `_post_id`
@wturnerharris
wturnerharris / nav-walker.php
Last active November 25, 2021 05:41
Use custom walker to modify wp_nav_menu()
<?php
/* **** USAGE ****
* <?php wp_nav_menu( array(
* 'walker' => new custom_walker_nav_menu()
* )); ?>
*/
class custom_walker_nav_menu extends Walker {
var $tree_type = array( 'post_type', 'taxonomy', 'custom' );
@wturnerharris
wturnerharris / w3tc-mu.md
Last active May 21, 2021 18:48
Install procedures to enable W3TC as a WordPress MU (must-use) plugin.

###W3TC MU-Plugins Install

  1. ####Add Apache Rewrite Rule -> .htaccess:

    • RewriteRule ^wp-content/plugins/w3-total-cache(/.*|)$ /wp-content/mu-plugins/w3-total-cache$1 [L,NC]
  2. ####Add WP-Config Option -> wp-config.php:

    • define('W3TC_DIR', dirname(FILE).'/wp-content/mu-plugins/w3-total-cache');
  3. ####Add w3tc plugin -> mu-plugins/:

  • Upload entire plugin to mu-plugins/w3-total-cache/
@wturnerharris
wturnerharris / xinitrc
Created January 20, 2015 20:35
X initialization script. This configures matchbox, resets chrome profile data, instructs the framebuffer to conform to explicit configuration, and starts an instance of chromium.
#!/bin/sh
while true; do
# Clean up previously running apps, gracefully at first then harshly
killall -TERM chromium 2>/dev/null;
killall -TERM matchbox-window-manager 2>/dev/null;
echo "Chrome and Matchbox terminated";
sleep 2;
killall -9 chromium 2>/dev/null;
@wturnerharris
wturnerharris / class-backend-tables.php
Created November 11, 2013 14:29
This is an example of extending the default class for tables in the admin section, WP_List_Table. It does take some setup arguments, but works and looks seamlessly within WordPress.
<?php
if(!class_exists('WP_List_Table')) require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
/**
* Extended class for displaying a list of items in an HTML table.
*
* @usage
* // be sure to modify the display_rows function to customize the output of the rows
* $args = array(
@wturnerharris
wturnerharris / .bash_alias
Last active April 10, 2019 00:32
Some helpful bash aliases
#!/bin/bash
adduser()
{
if [ -z "$1" ] # Is parameter #1 zero length?
then
echo "-Parameters are zero length.-" # Or no parameter passed.
else
echo "-Parameter #1 is \"$1\".-"
fi
@wturnerharris
wturnerharris / class-membership.php
Last active February 15, 2019 12:46
Class to make things members-only in WordPress.--This class depends on a custom capability called 'is_approved_member' for user member access and the custom post meta key '_members_only' as a post-level custom field.
<?php
/**
* Custom class for WP_Membership routines.
*
*
* @package WP_Membership
* @since WP_Membership 0.1
*/
if(realpath(__FILE__) === realpath($_SERVER["SCRIPT_FILENAME"]))
@wturnerharris
wturnerharris / gateway-braintree.php
Created November 13, 2013 04:02
BrainTree extensions for Events Manager Pro Requires Braintree PHP libraries available via composer or direct download: https://www.braintreepayments.com/assets/client_libraries/php/braintree-php-2.23.1.tar.gz
<?php
if ( class_exists('EM_Gateway') ) :
class BraintreeGateway extends EM_Gateway {
var $gateway = 'braintree';
var $title = 'BrainTree';
var $status = 4;
var $status_txt = 'Processing (BrainTree)';
var $button_enabled = false;
var $supports_multiple_bookings = true;
EXCLUDED_IDS = [
1234567890
]
DISCOUNT_CODE = "DISCOUNT_CODE"
DISCOUNT_PERCENTAGE = 0.70
discount = Input.cart.discount_code
if discount and discount.code == DISCOUNT_CODE
Input.cart.line_items.each do |line_item|
@wturnerharris
wturnerharris / update_postmeta_loop.sql
Created October 26, 2018 21:28
Stored procedure to migrate some meta fields to mapped ACF fields
DROP PROCEDURE IF EXISTS STEPBYSTEP;
DELIMITER ;;
CREATE PROCEDURE STEPBYSTEP()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE POST_ID INT DEFAULT 0;
DECLARE cursor_results CURSOR FOR SELECT ID FROM wp_posts WHERE post_type = 'press_materials';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor_results;