Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
RadGH / rs_sideload_test.php
Last active February 2, 2024 15:15
WordPress Plugin used to test uploading images from a URL using the function rs_upload_from_url(). Here is a link to a screenshot of the results screen: Here is a link to usage instructions, and how to download: https://gist.…
Plugin Name: RS Sideload Test
Description: Test your website's ability to upload images from a URL using the function `rs_upload_from_url()`. To get started, visit your site url ending in `?rs_9e86e751eacb` to run the tool. See Gist at the plugin URL below for more information.
Plugin URI:
Author: Radley Sustaire
Author URI:
Version: 1.3.1
RadGH / block-editor.js
Last active October 25, 2023 09:04
WordPress Block Editor - Custom SVG icon using javascript filter
// Result:
// Enqueue this script in PHP during the action "enqueue_block_editor_assets":
// $deps = array('wp-element', 'wp-hooks');
// wp_register_script( 'rs-download-block-editor', RSD_URL . '/assets/block-editor.js', $deps );
// This filter replaces the icon of any block with the prefix "rs-downloads/" using a custom SVG icon
RadGH / rs-import-thumbnails.php
Last active July 18, 2023 21:43
Import featured images from the post content for all posts on a WordPress site that do not have a featured image thumbnail
Plugin Name: RS Import Thumbnails
Description: Import thumbnails to your posts using the first image in the post content. To use this tool add to the end of your site url: ?rs_import_thumbnails_2023318_2330
Version: 1.0
Author: Radley Sustaire
Author URI:
RadGH / get_phone_number_link.php
Last active May 31, 2023 08:04
Convert a phone number into an HTML link
RadGH / gf-entries-by-user.php
Created May 15, 2023 19:01
GF Entries By User
* Gets gravity form entries for the given user. This includes entries where the user was logged in when they submitted the entry, and entries
* that were used to create their account with the GF User Registration Addon.
* @param $user_id
* @return array
RadGH / rs_gf_get_checked_boxes.php
Last active May 27, 2023 10:49
Get checked checkboxes from Gravity Forms checkbox field, as array
// 1/3) Usage:
$entry_id = 100; // usually provided in a filter, if so you can remove this line.
$entry = GFAPI::get_entry( $entry_id ); // get the entry, if this was provided in a filter you can remove this line.
$field_id = 35; // field ID can be found when field is selected while editing the form
$value = rs_gf_get_checked_boxes( $entry, $field_id );
// 2/3) Example output:
RadGH / any_rgb_to_hex.js
Last active May 18, 2022 17:58
Javascript convert RGB and RGBA to Hex, any format
* 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 / wp-metadata-fill-missing.php
Created May 18, 2022 03:07
When updating a post, user, or term, ensure specific fields have a blank entry in the database even when null.
* 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 / gfield-type-class.php
Last active May 16, 2022 18:53
Gravity Forms: Add field type class to every gfield
// 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 / gf-example-editable-form.json
Created May 16, 2022 02:34
Gravity Forms 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"