Skip to content

Instantly share code, notes, and snippets.

View bhubbard's full-sized avatar
:octocat:
Hello

Brandon Hubbard bhubbard

:octocat:
Hello
View GitHub Profile
@bhubbard
bhubbard / ajax_class.php
Created September 18, 2021 02:45 — forked from sfgarza/ajax_class.php
Boilerplate code for making AJAX calls to wordpress.
<?php
if (!defined('ABSPATH')) {
exit;
}
class ajax_class
{
public function __construct()
{
//Hook = 'wp_ajax_{$action}' where $action must equal the AJAX request's 'action' property.
@bhubbard
bhubbard / wp-config.php
Created June 23, 2021 16:44 — forked from MikeNGarrett/wp-config.php
All those damned wp-config constants you can never remember.
<?php
// PHP memory limit for this site
define( 'WP_MEMORY_LIMIT', '128M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M' ); // Increase admin-side memory limit.
// Database
define( 'WP_ALLOW_REPAIR', true ); // Allow WordPress to automatically repair your database.
define( 'DO_NOT_UPGRADE_GLOBAL_TABLES', true ); // Don't make database upgrades on global tables (like users)
// Explicitely setting url
@bhubbard
bhubbard / setup-phpunit.sh
Created June 19, 2021 03:04 — forked from DevinWalker/setup-phpunit.sh
Setup PHPUnit for use in the Local by Flywheel app
#!/usr/bin/env bash
# ===============================================================================
# Script to install PHPUnit in the Local by Flywheel Mac app
# These packages are installed
#
# PHPUnit, git, subversion, composer, curl and wget
#
# WordPress and the WP_UnitTestCase are installed in the /tmp directory
# The $WP_CORE_DIR and $WP_TESTS_DIR variables are added to the .bashrc file
@bhubbard
bhubbard / update-woo-order-billing-when-user-saves-address.php
Created May 12, 2021 18:46 — forked from zgordon/update-woo-order-billing-when-user-saves-address.php
Update WooCommerce Order Address Dynamically When Customer Updates Their Address
<?php
add_action( 'woocommerce_customer_save_address', 'jsforwp_update_address_for_orders', 10, 2 );
function jsforwp_update_address_for_orders( $user_id ) {
$customer_meta = get_user_meta( $user_id );
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
@bhubbard
bhubbard / delete-orphans-usermeta.sql
Created April 8, 2019 19:51 — forked from carlosleopoldo/delete-orphans-usermeta.sql
Delete all orphans user meta in WordPress
DELETE FROM wp_usermeta
WHERE NOT EXISTS (
SELECT * FROM wp_users
WHERE wp_usermeta.user_id = wp_users.ID
)
@bhubbard
bhubbard / .travis.yml
Created April 26, 2018 05:29 — forked from mderazon/.travis.yml
Automatic deployment to Google Cloud Functions with Travis-ci
# Use Dockerized infrastructure
sudo: false
# Use node_js environnement
language: node_js
node_js:
- "6"
# Cache Gcloud SDK between commands
cache:
@bhubbard
bhubbard / index.js
Created February 14, 2018 07:52 — forked from shigwata/index.js
Cloud Functions pubsub to slack
const IncomingWebhook = require('@slack/client').IncomingWebhook;
const url = 'Webhook URL'
const defaults = {
username: 'webhookbot',
iconEmoji: ':ghost:',
channel: '#general'
}
const webhook = new IncomingWebhook(url, defaults);
exports.subscribe = function subscribe(event, callback) {
@bhubbard
bhubbard / datastore-index.js
Created February 14, 2018 07:48 — forked from mfurlend/datastore-index.js
#cloud functions #datastore #google
'use strict';
const Datastore = require('@google-cloud/datastore');
// Instantiates a client
const datastore = Datastore();
/**
* Gets a Datastore key from the kind/key pair in the request.
*
@bhubbard
bhubbard / WordPress-wp_posts-MySQL-data-size
Created January 4, 2018 01:23 — forked from davidegreenwald/WordPress-wp_posts-MySQL-data-size
MySQL statement for WordPress wp_posts table breaking down data size for each post_type
-- This will show you the size of post, revision, attachment and other fields in `wp_posts`
-- this method can be applied to any WordPress table to get a breakdown of clutter and data use
-- this will not get you index size, but WP indexes are typically a small fraction of overall table size
SELECT post_type
COUNT(*) AS NUM, -- adds a column with the number of rows for each key value for comparison
SELECT post_type, COUNT(*) AS NUM,
(SUM(LENGTH(ID) -- add all column data together to group the total row data by post_type
+LENGTH(post_author)
+LENGTH(post_date)
+LENGTH(post_date_gmt)
@bhubbard
bhubbard / functions.php
Created October 27, 2017 18:43 — forked from lukecav/functions.php
Stop WordPress sending anything but essential data during the update check
function wp_update_privacy( $query ) {
unset($query['php']);
unset($query['mysql']);
unset($query['local_package']);
unset($query['blogs']);
unset($query['users']);
unset($query['multisite_enabled']);
unset($query['initial_db_version']);
return $query;
}