Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / wpuserqueryfix.php
Last active May 23, 2020 02:35
Remove duplicate users from WP_User_Query
<?php
/**
* Fix duplicate users appearing in WP_User_Query by specifying an OR meta query.
* This solution makes no sense but it works. ¯\_(ツ)_/¯
*
* See:
* 1. https://gist.github.com/RadGH/877ee20d99eee73fb0e933f199d4b8fb
* 2: https://wordpress.stackexchange.com/questions/220307/user-appears-twice-in-a-wp-user-query
* 3: https://core.trac.wordpress.org/ticket/17582
@RadGH
RadGH / edit-gf-entry.php
Last active February 17, 2025 02:53
Edit an existing gravityforms entry on the frontend
<?php
/*
Plugin Name: GF Editable by Radley
Description: Example classes to make a particular gravity form editable on the front-end.
Author: Radley Sustaire
Author URI: https://radleysustaire.com/
Version: 1.0.0
*/
// QUICK TEST INSTRUCTIONS:
@RadGH
RadGH / aa-process-all-users-once-daily.php
Last active June 5, 2020 15:19
WordPress Plugin: Loops through all users on your site, spread out throughout the day for efficiency. Provides a hook to do any sort of maintenance on those users. Does not actually modify any users, this just an API of sorts.
<?php
/*
Plugin Name: RS Process Users Daily
Description: Provides an API action for developers which iterates all users once per day, based on cofigurable settings. Usage: <code class="code">add_action( 'aa_process_all_users_daily/user', 'example_process_user' );</code>
Author: Radley Sustaire
Version: 1.1.0
*/
/*
// EXAMPLE
@RadGH
RadGH / .gitignore
Last active March 8, 2020 22:37
Radley's Git Ignore for WordPress development
# Radley's WP development structure. Git repo should be based in the wp-content folder.
#
# Alternatively, try the Github official WordPress gitignore structure from the document root:
# https://github.com/github/gitignore/blob/master/WordPress.gitignore
# File Extensions
*.log
*.sql
*.sqlite
@RadGH
RadGH / bulk-users-hourly-cron.php
Created February 24, 2020 23:56
WordPress Bulk process users on hourly cron event
<?php
/**
* Check expiration date for a set of users.
*
* @return string
*/
function dtl_course_expiry_check( $debug = false ) {
// option to start over when used manually via query string
if ( isset($_REQUEST['startover']) ) update_option( 'dtl-ce-user-index', 0, false );
@RadGH
RadGH / wp-get-terms-straight-join.php
Last active March 13, 2022 03:41
WordPress get_terms replace INNER JOIN with STRAIGHT_JOIN using filters
<?php
// Step 1. Add the filters surrounding the get_terms (which should be used in your code)
add_filter( 'terms_clauses', 'rs_replace_inner_with_straight_joins', 20 );
$terms = get_terms( $args );
remove_filter( 'terms_clauses', 'rs_replace_inner_with_straight_joins', 20 );
// Step 2. Add to functions.php or similar:
function rs_replace_inner_with_straight_joins( $pieces, $taxonomies = null, $args = null ) {
global $wpdb;
@RadGH
RadGH / ups-self-packed-products.php
Last active June 5, 2020 15:20
[WooCommerce UPS Shipping] This script allows you to specify products as "already packed". They will not be added to separate boxes, and will not be combined with other products.
<?php
// This script allows you to specify products as "already packed". They will not be added to separate boxes, and will not be combined with other products.
// This is useful if you have products that are already packed and ready to ship that should not be put into another box.
//
// IMPORTANT:
// The plugin 'WooCommerce UPS Shipping' does not currently support the filter "woocommerce_shipping_ups_skip_packing".
// For now, you must manually edit the UPS plugin directly. The two edits are located below (for version 3.2.18):
// 1. https://gist.github.com/RadGH/ad8d8e599366a27c81bc84dd1f66aaa9
// 2. https://gist.github.com/RadGH/b7b69f65bbeb7212083058d1d644b0c9
//
@RadGH
RadGH / class-wc-shipping-ups.php
Last active December 10, 2019 10:06
Modified version of "class-wc-shipping-ups.php" version "3.2.18". See: https://gist.github.com/RadGH/7c8f0ef77e242ce011932d41e9c06b8e
<?php
/**
* Shipping method class.
*
* @package WC_Shipping_UPS
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
@RadGH
RadGH / class-wc-boxpack.php
Last active June 5, 2020 15:20
Modified version of "class-wc-boxpack.php" version "3.2.18". See: https://gist.github.com/RadGH/7c8f0ef77e242ce011932d41e9c06b8e
<?php
/**
* WooCommerce Box Packer
*
* @version 2.0.1
* @author WooThemes / Mike Jolley
*/
class WC_Boxpack {
@RadGH
RadGH / js-local-storage.js
Last active January 7, 2020 06:15
JavaScript storage using localstorage with Get, Set, Delete. Falls back to 30-day cookies if LocalStorage is not supported.
// Usage:
cache.set('name', 'Radley');
alert( cache.get('name') ); // Displays "Radley"
cache.delete('name');
alert( cache.get('name') ); // Displays ""
// End of usage. Note that this code must go below the actual cache definition (below)