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 / 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 / edit-gf-entry.php
Last active February 17, 2025 02:53
Edit an existing gravityforms entry on the frontend
<?php
/*
Plugin Name: GF Editable by Radley
Description: Example classes to make a particular gravity form editable on the front-end.
Author: Radley Sustaire
Author URI: https://radleysustaire.com/
Version: 1.0.0
*/
// QUICK TEST INSTRUCTIONS:
@RadGH
RadGH / aa-process-all-users-once-daily.php
Last active June 5, 2020 15:19
WordPress Plugin: Loops through all users on your site, spread out throughout the day for efficiency. Provides a hook to do any sort of maintenance on those users. Does not actually modify any users, this just an API of sorts.
<?php
/*
Plugin Name: RS Process Users Daily
Description: Provides an API action for developers which iterates all users once per day, based on cofigurable settings. Usage: <code class="code">add_action( 'aa_process_all_users_daily/user', 'example_process_user' );</code>
Author: Radley Sustaire
Version: 1.1.0
*/
/*
// EXAMPLE
@RadGH
RadGH / acf-custom-metabox-on-options-page.php
Last active October 23, 2024 21:33
ACF: Display custom metabox on an ACF (sub-) options page
<?php
/**
* Add sub options page with a custom post id
*/
if( function_exists('acf_add_options_page') ) {
acf_add_options_sub_page(array(
'page_title' => 'CSV Sync',
'menu_title' => 'CSV Sync',
'parent_slug' => 'users.php',
@RadGH
RadGH / rs_upload_from_url.php
Last active March 10, 2025 21:21
Upload a file from a URL to the WordPress media gallery. Supports images, PDFs, and other file types.
<?php
/**
* This function uploads a file from a URL to the media library, designed to be placed in your own theme or plugin.
* Metadata will be generated and images will generate thumbnails automatically.
*
* HOW TO USE:
* 1. Add the function below to your theme or plugin
* 2. Call the function and provide the URL to an image or other file.
* 3. If successful, the attachment ID will be returned.
@mommaroodles
mommaroodles / functions.php
Created February 2, 2014 00:16
Woocommerce: Remove Company Input Field in Checkout Page
<?php
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_company']);
return $fields;
}
?>