Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / wp-optimized-taxonomy-mysql.php
Last active May 21, 2023 21:35
Optimize wordpress WP_Term_Query mysql request
<?php
// Example long query (2.557 seconds):
// @see https://radleysustaire.com/s3/1c66a3/
// Example optimized query (0.316 seconds):
// @see https://radleysustaire.com/s3/fb794e/
// Example of what your code would look like:
$args = array(
'taxonomy' => array( 'account-menu' ),
@RadGH
RadGH / aa-gf-dynamic-progressbar.php
Last active May 3, 2022 20:01
Gravity Forms that use a progressbar for multiple pages will adjust as answers are filled in, rather than only when progressing to the next page.
<?php
/*
Plugin Name: A+A Gravity Forms Dynamic Progressbar
Description: Gravity Forms that use a progressbar for multiple pages will adjust as answers are filled in, rather than only when progressing to the next page.
Author: Radley Sustaire, Alchemy + Aim
*/
class AA_GF_Dynamic_Progressbar {
public function __construct() {
@RadGH
RadGH / menu.php
Created April 15, 2022 09:12
Change active parent menu and child menu items in WordPress Dashboard sidebar
<?php
// Below are some example fixes for a structure such as this:
//
// Post Type: lesson (Hidden from menu)
// Taxonomy: course (Hidden from menu)
// Taxonomy: cohort (Hidden from menu)
// And a Gravity Form with ID 3, which links to the Entries page
//
// Note that cm_is_taxonomy_page() and cm_is_homework_entries_page() check the current page using $pagenow, $typenow, and $_GET.
// They are not included
@RadGH
RadGH / crafting.zs
Created May 1, 2021 22:44
minecraft crafttweaker nice to haves
//Imports
import crafttweaker.api.tag.MCTag;
/*
*************
* a * b * c *
*************
* d * e * f *
*************
* g * h * i *
@RadGH
RadGH / wp-custom-post-status.php
Created March 5, 2021 22:10
WordPress: Add new post status to custom post types and quick edit menu
<?php
// Based on:
// https://www.wpbeginner.com/wp-tutorials/how-to-add-custom-post-status-for-blog-posts-in-wordpress/
// https://rudrastyh.com/wordpress/custom-post-status-quick-edit.html
class BP_Custom_Post_Status {
public $post_types = array( 'videographer', 'photographer' );
public function __construct() {
@RadGH
RadGH / log-gettext.php
Created September 23, 2020 04:25
Log all gettext strings on a page in wordpress
<?php
function log_gettext_string( $text ) {
global $mylist;
if ( !isset($mylist) ) {
$mylist = array();
register_shutdown_function(function($a = null) { global $mylist; echo implode('<br>', $mylist); exit; } );
}
@RadGH
RadGH / gf_hooks.php
Created August 28, 2020 10:13
Gravity Forms: Action on payment complete for stripe and paypal standard
<?php
// Both of these work
// @hook do_action( 'gform_stripe_fulfillment', $session, $entry, $feed, $form );
function bpc_debug_stripe( $session, $entry, $feed, $form ) {
error_log( 'Payment received for STRIPE' );
}
add_action( 'gform_stripe_fulfillment', 'bpc_debug_stripe', 20, 4 );
// @hook do_action( 'gform_paypal_fulfillment', $entry, $feed, $transaction_id, $amount )
@RadGH
RadGH / php-error.php
Created August 26, 2020 06:29
PHP Fatal Error Handler - Drop the file right into wp-content folder
<?php
/*
* A+A Error Reporter
* Created by radley@alchemyandaim.com
*/
if ( !isset($error) || !isset($handled) ) {
echo 'Error: Unhandled exception occurred and required parameters $error and $handled were not supplied in '. __FILE__ .':'. __LINE__;
exit;
}
@RadGH
RadGH / windows-gulp-fix.txt
Created July 28, 2020 22:30
Windows Fixes for gulp/npm/node errors: Python compile error, MSBuild.exe exit code 1, node-sass, and Primordials not defined
problem:
"npm i" fails with an error that Python failed to compile something like "%s.%s.%s"
solution 1:
revert python 3.8.5 to 2.7.13 to fix a compiler error
solution 2:
to install python and VC Redist automatically run:
npm install --global windows-build-tools
@RadGH
RadGH / add_action_after_save_post.php
Last active July 16, 2020 10:24
Queue an action that occurs after acf has completed saving a post, providing the callback, post id, and arguments up front. Useful if other fields that are saved with the post need to be overwritten.
<?php
/**
* Triggers an action after the "acf/save_post" action, priority 1000.
* If hooks are not called, they will be called at the end of the PHP thread
*
* Specify your callback as the first argument, and any arguments to pass to it as the second argument.
*
* @param callable Callback
* @param post_id The ACF-formatted post id you want to hook into