Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / rs-acf-specific-term-location.php
Created March 5, 2025 20:54
Advanced Custom Fields (ACF) - Adds a custom ACF location rule to field groups to choose "Specific Term" on taxonomy pages. This location rule is available to any field group, allowing you to show fields for a specific term within a taxonomy.
<?php
/*
Plugin Name: RS ACF Specific Term Location
Description: Adds a custom ACF location rule "Specific Term". It lets you restrict a field group to show only for a specific term when editing a term in the backend.
Version: 1.0.2
*/
// category ancestor location rule
function rs_acf_location_types_specific_term( $choices ) {
if ( !isset( $choices['Forms']['specific_term_id'] ) ) {
@RadGH
RadGH / wc-membership-discount-sale-price-calculation.php
Last active February 18, 2025 22:07
WooCommerce Membership Discount
<?php
// Posted for Stack Overflow:
// @see https://stackoverflow.com/questions/77198717/temporary-global-sale-price-discount-for-all-products-in-woocommerce
// Note this code supports WooCommerce Subscriptions.
// If you aren't using that, you need to remove the references to WC_Subscriptions_Product and the related functions.
// 1. Custom function that should return true if the user is a member.
// Modified to just check if you are an admin, but you could change this to look at your previous subscriptions
@RadGH
RadGH / re-order-wp-admin.php
Created November 22, 2024 20:05
Re-order WordPress dashboard admin menu by top-level page slugs
<?php
// Reorder admin menu
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', 'my_theme_reorder_admin_menu' );
function my_theme_reorder_admin_menu() {
return array(
'index.php',
'edit.php?post_type=page',
@RadGH
RadGH / gform_validate_two_date_fields.php
Last active July 16, 2024 20:34
Gravity Forms: Validate two date fields to ensure the "End date" is after the "Start date"
<?php
// Form #215
// Start date field id: #18
// End date field id: #19
// Validation only applies to the end date, but checks the value of both dates
add_filter('gform_field_validation_215_19', 'rs_validate_two_gf_date_fields', 10, 4);
function rs_validate_two_gf_date_fields( $result, $value, $form, $field ) {
$start_date_field_id = 18;
@RadGH
RadGH / footer.php
Last active July 1, 2024 18:22
Loker Footer Staging vs Live
@RadGH
RadGH / wp_replace_block_page_template.php
Last active June 19, 2024 21:30
Replace block page template dynamically using PHP
<?php
/**
* Before the block template is displayed, replace it with a different block template.
*
* IMPORTANT: You must create the block template through the editor: Templates > Add New
*
* @param string $template
*
* @return string
@RadGH
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: https://s3.us-west-2.amazonaws.com/elasticbeanstalk-us-west-2-868470985522/ShareX/2024/02/chrome_2024-02-02_07-03-56.jpg. Here is a link to usage instructions, and how to download: https://gist.…
<?php
/*
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: https://gist.github.com/RadGH/be30af96617b13e7848a4626ef179bbd
Author: Radley Sustaire
Author URI: https://gist.github.com/RadGH
Version: 1.3.1
*/
@RadGH
RadGH / block-editor.js
Last active October 25, 2023 09:04
WordPress Block Editor - Custom SVG icon using javascript filter
// Result: https://radleysustaire.com/s3/d87fe5/chrome
// 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
wp.hooks.addFilter(
'blocks.registerBlockType',
'rs-downloads/modify_icon',
@RadGH
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
<?php
/*
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: https://radleysustaire.com/
*/
@RadGH
RadGH / get_phone_number_link.php
Last active May 31, 2023 08:04
Convert a phone number into an HTML link