Skip to content

Instantly share code, notes, and snippets.

Radley Sustaire RadGH

Block or report user

Report or block RadGH

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@RadGH
RadGH / ups-self-packed-products.php
Last active Dec 10, 2019
[WooCommerce UPS Shipping] This script allows you to specify products as "already packed". They will not be added to separate boxes, and will not be combined with other products.
View ups-self-packed-products.php
<?php
// This script allows you to specify products as "already packed". They will not be added to separate boxes, and will not be combined with other products.
// This is useful if you have products that are already packed and ready to ship that should not be put into another box.
//
// IMPORTANT:
// The plugin 'WooCommerce UPS Shipping' does not currently support the filter "woocommerce_shipping_ups_skip_packing".
// For now, you must manually edit the UPS plugin directly. The two edits are located below (for version 3.2.18):
// 1. https://gist.github.com/RadGH/ad8d8e599366a27c81bc84dd1f66aaa9
// 2. https://gist.github.com/RadGH/b7b69f65bbeb7212083058d1d644b0c9
//
@RadGH
RadGH / class-wc-shipping-ups.php
Last active Dec 10, 2019
Modified version of "class-wc-shipping-ups.php" version "3.2.18". See: https://gist.github.com/RadGH/7c8f0ef77e242ce011932d41e9c06b8e
View class-wc-shipping-ups.php
<?php
/**
* Shipping method class.
*
* @package WC_Shipping_UPS
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
@RadGH
RadGH / class-wc-boxpack.php
Last active Dec 10, 2019
Modified version of "class-wc-boxpack.php" version "3.2.18". See: https://gist.github.com/RadGH/7c8f0ef77e242ce011932d41e9c06b8e
View class-wc-boxpack.php
<?php
/**
* WooCommerce Box Packer
*
* @version 2.0.1
* @author WooThemes / Mike Jolley
*/
class WC_Boxpack {
@RadGH
RadGH / js-local-storage.js
Last active Jan 7, 2020
JavaScript storage using localstorage with Get, Set, Delete. Falls back to 30-day cookies if LocalStorage is not supported.
View js-local-storage.js
// Usage:
cache.set('name', 'Radley');
alert( cache.get('name') ); // Displays "Radley"
cache.delete('name');
alert( cache.get('name') ); // Displays ""
// End of usage. Note that this code must go below the actual cache definition (below)
@RadGH
RadGH / gf-get-field-value.php
Created Oct 20, 2019
Gets a field value from a Gravity Form field, formatted to be compatible with the "gform_field_value" filter (particularly for checkboxes)
View gf-get-field-value.php
<?php
// FOR GRAVITY FORMS
/**
* Get the values for a field, compatible with the filter "gform_field_value" particularly for checkbox fields.
*
* Uses the native "get_post_field_value" function which is sadly private (for no good reason).
*
* @see https://stackoverflow.com/a/40441769
@RadGH
RadGH / wp-remote-request-wrapper.php
Last active Sep 6, 2019
WP Remote Get/Post/Put/Patch/Del wrapper for apis with json decoded body and consistent result data
View wp-remote-request-wrapper.php
<?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 Aug 23, 2019
WordPress settings api for simple settings fields
View wp-settings-api-text-fields.php
<?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 Aug 5, 2019
Process/iterate through all posts in a post type
View wp-process-post-type.php
<?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 Aug 2, 2019
WordPress: Show current screen ID and Base in the admin footer, visible only on hover
View wp-show-screen-id-in-admin-footer.php
@RadGH
RadGH / wp-search-custom-db.php
Last active Jun 24, 2019
How to add a custom table in WordPress to collect search results
View wp-search-custom-db.php
<?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.
You can’t perform that action at this time.