Skip to content

Instantly share code, notes, and snippets.

Avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / any_rgb_to_hex.js
Last active May 18, 2022
Javascript convert RGB and RGBA to Hex, any format
View any_rgb_to_hex.js
/**
* Convert RGB to Hex. Allows whitespace. If given hex, returns that hex. Alpha opacity is discarded.
* Supports formats:
* #fc0
* #ffcc00
* rgb( 255, 255, 255 )
* rgba( 255, 255, 255, 0.5 )
* rgba( 255 255 255 / 0.5 )
*/
function rgb_any_to_hex( orig ) {
@RadGH
RadGH / wp-metadata-fill-missing.php
Created May 18, 2022
When updating a post, user, or term, ensure specific fields have a blank entry in the database even when null.
View wp-metadata-fill-missing.php
<?php
/**
* When updating a post, user, or term, ensure specific fields have a blank entry in the database even when null.
*
* @param $object_id
* @param null $type
* @param null $subtype
*/
function rs_insert_missing_meta_keys_on_save( $object_id, $type = null, $subtype = null ) {
@RadGH
RadGH / gfield-type-class.php
Last active May 16, 2022
Gravity Forms: Add field type class to every gfield
View gfield-type-class.php
<?php
// Make every gravity form field add its input type as a class.
// Example (added class: gfield-type-radio):
// fieldset id="field_136_31" class="gfield gfield-type-radio ..."
// Some other types: name, email, html, select, ...
function aa_add_input_type_gravity_forms( $form ) {
foreach ( $form['fields'] as $field ) {
if ( $field instanceof GF_Field ) {
$field->cssClass .= 'gfield-type-' . $field->get_input_type();
@RadGH
RadGH / gf-example-editable-form.json
Created May 16, 2022
Gravity Forms example editable form JSON
View gf-example-editable-form.json
{"0":{"title":"Editable Form","description":"","labelPlacement":"top_label","descriptionPlacement":"below","button":{"type":"text","text":"Submit","imageUrl":"","width":"auto","location":"bottom","layoutGridColumnSpan":12},"fields":[{"type":"name","id":1,"formId":12,"label":"Name","adminLabel":"","isRequired":false,"size":"large","errorMessage":"","visibility":"visible","nameFormat":"advanced","inputs":[{"id":"1.2","label":"Prefix","name":"","autocompleteAttribute":"honorific-prefix","choices":[{"text":"Dr.","value":"Dr."},{"text":"Miss","value":"Miss"},{"text":"Mr.","value":"Mr."},{"text":"Mrs.","value":"Mrs."},{"text":"Ms.","value":"Ms."},{"text":"Prof.","value":"Prof."},{"text":"Rev.","value":"Rev."}],"isHidden":false,"inputType":"radio"},{"id":"1.3","label":"First","name":"fname","autocompleteAttribute":"given-name"},{"id":"1.4","label":"Middle","name":"","autocompleteAttribute":"additional-name","isHidden":false},{"id":"1.6","label":"Last","name":"lname","autocompleteAttribute":"family-name"},{"id":"1.8"
@RadGH
RadGH / wp-optimized-taxonomy-mysql.php
Last active May 13, 2022
Optimize wordpress WP_Term_Query mysql request
View wp-optimized-taxonomy-mysql.php
<?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
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.
View aa-gf-dynamic-progressbar.php
<?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 Apr 15, 2022
Change active parent menu and child menu items in WordPress Dashboard sidebar
View menu.php
<?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
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; } );
}