Skip to content

Instantly share code, notes, and snippets.

Avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / crafting.zs
Created May 1, 2021
minecraft crafttweaker nice to haves
View crafting.zs
//Imports
import crafttweaker.api.tag.MCTag;
/*
*************
* a * b * c *
*************
* d * e * f *
*************
* g * h * i *
@RadGH
RadGH / wp-custom-post-status.php
Created Mar 5, 2021
WordPress: Add new post status to custom post types and quick edit menu
View wp-custom-post-status.php
<?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 Sep 23, 2020
Log all gettext strings on a page in wordpress
View log-gettext.php
<?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 Aug 28, 2020
Gravity Forms: Action on payment complete for stripe and paypal standard
View gf_hooks.php
<?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 Aug 26, 2020
PHP Fatal Error Handler - Drop the file right into wp-content folder
View php-error.php
<?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 Jul 28, 2020
Windows Fixes for gulp/npm/node errors: Python compile error, MSBuild.exe exit code 1, node-sass, and Primordials not defined
View windows-gulp-fix.txt
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 Jul 16, 2020
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.
View add_action_after_save_post.php
<?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
@RadGH
RadGH / code-time-execution-calculation.php
Last active Jul 12, 2020
Get time difference from start to end in seconds, for measuring speed of operations in php
View code-time-execution-calculation.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 Jul 3, 2020
Stormworks Lua Microcontroller: Rate of Change
View sw-rate-of-change.lua
--[[
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 Jun 1, 2020
WP Rocket won't cache pages with these related posts
View wp-rocket-wont-cache-this.php
<?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' );