Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / upload-and-process.php
Created July 17, 2013 22:29
Upload and process an image in Wordpress
<?php
$image = abjj_upload_image('profile_picture', $existing_image, 'abjj_process_profile_picture' );
echo '<pre style="font-size: 11px;">RESULT: ---------------------------', "\n",
htmlspecialchars( print_r( $image, true)),
'</pre>';
exit;
// Other functions
// Either process and upload a new image, or retrieve the old image
// $process is a callback that allows the image to be processed once uploaded via Wordpress' image editor
@RadGH
RadGH / wpsc-get-owned-products.php
Last active December 20, 2015 03:49
These two functions allow you two retrieve the products purchased by a user. One returns an array of all objects with crucial purchase log/cart info, the other returns true or false whether the specific product has been purchased.
<?php
function wpsc_get_owned_products( $user_id = false ) {
global $user_purchases, $wpdb;
// Get current user by default
if ( !$user_id ) {
$current = wp_get_current_user();
if ($current) $user_id = $current->ID;
else return false;
@RadGH
RadGH / add-user-caps.php
Created August 14, 2013 17:16
This script adds capabilities to wordpress role by role name
<?php
/* --------------------------------------------------
/ If used within a plugin, you will want to run this function on plugin activation
/ For development, you can simply call the function below . To do this, uncomment
/ the line below, then visit any page.
-------------------------------------------------- */
// custom_user_roles();
function custom_user_roles() {
@RadGH
RadGH / rate-limiter.js
Last active December 21, 2015 09:28
This is a simple JavaScript rate limiter that you can stick in any function
// This script prevents a function from running too frequently.
// Pick one of these three variations, then copy the code to a function of your choice. Do not copy the entire script.
// VARIATION A: Simply ignore any excessive function calls
// VARIATION B: Ignore excessive function calls, but call the function again once the limiter has expired. Ignore parameters.
// VARIATION C: Like variation B, call the function after limiter expired - but pass in function's parameters.
// Variation A ----------------
// Replace 150 with the rate limit amount of your choice.
@RadGH
RadGH / easy-lightbox.js
Last active December 23, 2015 00:49
Easy lightbox
/*
Accompanying CSS is commented below.
Example Usage:
show_lightbox("Hello World", "Good morning, friend", {ok_button: true});
---
show_lightbox( title, content, [options] )
Title: The title of the lightbox. Optional. If only title is specified, the title will be used as content instead.
@RadGH
RadGH / world_init.txt
Created December 23, 2015 06:20
Custom param set for a world. Add to the end of data\init\world_init.txt
[WORLD_GEN]
[TITLE:RAD]
[DIM:257:257]
[EMBARK_POINTS:1504]
[END_YEAR:1050]
[BEAST_END_YEAR:300:80]
[REVEAL_ALL_HISTORY:1]
[CULL_HISTORICAL_FIGURES:1]
[ELEVATION:1:400:800:800]
[RAINFALL:0:100:400:400]
@RadGH
RadGH / remove-options-framework-sanitization.php
Created October 1, 2013 18:20
Remove sanitization filters from the Options Framework plugin by Devin Price
<?php
// Disable sanitization of specific fields by removing the sanitization filter hooks
// Note that at least one filter must exist for the field to be saved.
function optionsframework_remove_sanitization() {
// Text areas
remove_filter( 'of_sanitize_textarea', 'of_sanitize_textarea' );
add_filter( 'of_sanitize_textarea', function ($input) { return $input; });
@RadGH
RadGH / wpp_rescan_views.php
Last active January 21, 2016 20:31
Wordpress Popular Posts - Store views for existing posts
<?php
/*
Include this script then access your wordpress website with the URL ending in: ?wppscan=1
It will go through each post, 10 at a time, and update the views total/daily/weekly/monthly as post meta.
This is to co-exist with your own option that saves these values periodically when saving post. That functionality is not included here.
*/
global $ld_recalc;
@RadGH
RadGH / admin.js
Last active April 7, 2016 08:14
WordPress media "browse" button
/*
HOW TO USE:
0. Ensure the admin page has enqueue the media library scripts. Here is an example to include it on the "Page" edit screen (post.php):
function page_enqueue_media_scripts() {
$screen = get_current_screen();
if ( $screen->base == 'post' && $screen->id == 'page' ) wp_enqueue_media();
}
add_action('admin_enqueue_scripts', 'page_enqueue_media_scripts');
@RadGH
RadGH / woocommmerce-product-variations.php
Created September 25, 2013 18:40
For the WooCommerce plugin for WordPress, this function returns all variations of a product by referencing the product ID.
<?php /*
Takes a product ID and returns an array that includes all types of variations of the product, and the attributes of that variation.
Variations are normally returned as a term object. They belong to the original product ID and the taxonomy name is equal to the attribute name.
If a custom variation is provided instead of a term object, the variation will simply be a string of the option's name.
Example return result is given below. This is a single product with one attribute and two different variations.
Array (
[pa_oregon-training-classes] => Array (
[attribute] => Array (