Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / gf-get-field-value.php
Last active August 11, 2022 22:38
Gets a field value from a Gravity Form field, formatted to be compatible with the "gform_field_value" filter (particularly for checkboxes). Replaced with: https://gist.github.com/RadGH/d08a7466b097dfb895ec6dede2e474f5
<?php
// -------------------------------------------------------------------------------------
// Replaced with: https://gist.github.com/RadGH/d08a7466b097dfb895ec6dede2e474f5
//
// Gravity Forms still does not have an official method to get selected checkboxes lmao.
// -------------------------------------------------------------------------------------
@RadGH
RadGH / wp-remote-request-wrapper.php
Last active April 8, 2024 09:15
WP Remote Get/Post/Put/Patch/Del wrapper for apis with json decoded body and consistent result data
<?php
// sample usage
$url = 'http://example.org/';
$url_args = array( 'id' => 47, 'name' => 'radley' );
$body_fields = array( 'nonce' => 12345 );
$headers = array( 'Authorization' => 'api 123456' ); // Mailchimp-style api key using basic authorization
$result = rs_remote_request( $url, 'GET', $url_args, $body_fields, $headers );
@RadGH
RadGH / wp-settings-api-text-fields.php
Created August 23, 2019 06:15
WordPress settings api for simple settings fields
<?php
add_action( 'admin_menu', 'myplugin_register_settings_menu_page' );
add_action( 'admin_init', 'myplugin_register_settings_fields' );
function myplugin_register_settings_menu_page() {
add_options_page( 'My plugin', 'My plugin', 'manage_options', 'myplugin-settings', 'myplugin_display_settings_menu' );
}
function myplugin_register_settings_fields() {
@RadGH
RadGH / wp-process-post-type.php
Created August 5, 2019 22:42
Process/iterate through all posts in a post type
<?php
/*
This function will loop through all posts matching a filter, allowing you to make some edits to them with PHP.
To begin just visit your site ending with /?FojVDY83
Important: To avoid re-processing the same post infinitely, you need to make sure the meta_query will not match the same post after it has been processed. This is done below by checking if the meta key "status" exists or not.
*/
@RadGH
RadGH / wp-show-screen-id-in-admin-footer.php
Created August 2, 2019 22:11
WordPress: Show current screen ID and Base in the admin footer, visible only on hover
@RadGH
RadGH / wp-search-custom-db.php
Last active June 24, 2019 18:50
How to add a custom table in WordPress to collect search results
<?php
/*
HOW TO USE:
1. Modify the table and logging function if needed. You probably want to remove "groups" which for my case, represented
which group your user account belonged to. We needed to be able to isolate search requests based on group.
2. After your search term has been performed, log the search using rad_log_search_term().
3. Build some fancy dashboard to show the data, or be a nerd and do your own mysql queries every time.
4. IMPORTANT: The activation hook for "rad_activate_plugin" MUST go in your plugin main directory. If the plugin is active
when you add this code, just call rad_activate_plugin() manually once, refresh a page, then remove the manual call.
@RadGH
RadGH / wp-get-terms-used-by-post-ids.php
Created June 13, 2019 02:12
WordPress: Get all terms used by the given post ids
<?php
/**
* Returns an array of terms used by the list of post IDs.=
* By default returns an array of arrays, each with the keys: term_id, slug, name, term_taxonomy_id
* You can get an array of single values by changing $return to one of: term_id, slug, name, term_taxonomy_id
*
* @param $post_ids
* @param $taxonomy
* @param string $return
*
@RadGH
RadGH / wicked-folder-set-folder-attachment_upload.php
Created June 6, 2019 00:05
Assign folder to an uploaded attachment with Wicked Folders using PHP
<?php
/**
* Adds an object to the given folder name.
*
* @param $object_id
* @param $folder_name
* @param $parent_folder_id
*
* @return bool
@RadGH
RadGH / infsrole.php
Last active May 29, 2019 23:30
Infusionsoft POST to wordpress to change role
<?php
/*
UNTESTED CODE BELOW
Infusionsoft triggers a POST request that sets user roles.
This function retrieves that request and processes the role change.
Be sure to enter your $internal_access_key below.
You may need to change the meta key "infusionsoft_contact_id". Consult your infusionsoft plugin documentation to find what that key is named (or search the wp_usermeta table in the database)
@RadGH
RadGH / acf-custom-metabox-on-options-page.php
Last active November 7, 2025 00:38
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',