Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / code-time-execution-calculation.php
Last active July 12, 2020 09:12
Get time difference from start to end in seconds, for measuring speed of operations in php
<?php
// How to use:
// 1. Copy the class at the end of the file into your code.
// 2. Follow the examples below for usage.
// -----------------------
// Example #1: Basic usage
// Start
@RadGH
RadGH / sw-rate-of-change.lua
Created July 3, 2020 01:47
Stormworks Lua Microcontroller: Rate of Change
--[[
Microcontroller Name: Rate of Change
Description: Take an input value and outputs the rate of change per second.
Inputs:
1) Value (number, required): Input number (eg, fuel tank capacity)
2) Refresh Rate (number, optional, default 60): Game ticks between each update
Outputs:
1) Number: Change since last update
@RadGH
RadGH / wp-rocket-wont-cache-this.php
Created June 1, 2020 00:06
WP Rocket won't cache pages with these related posts
<?php
// get list of category IDs that this post belongs to
$cats = array();
if ( $categories = get_the_category() ) {
foreach ( $categories as $category ) {
$cats[] = $category->term_id;
}
}
$blogname = get_bloginfo( 'name', 'display' );
@RadGH
RadGH / wp-acf-edit-field-group-links.php
Last active May 26, 2020 01:53
[ACF] Displays a link to edit a field group in the title of a field group for user and taxonomy pages on the backend.
@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 August 17, 2023 01:26
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;