Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / wc-sortable-custom-taxonomy.php
Created July 22, 2015 06:49
Woocommerce - Sortable custom taxonomy
<?php
// This is so easy, it's embarassing that I took 20 minutes to find it.
// "Catalog" is a custom taxonomy.
function make_catalog_sortable( $sortables ) {
$sortables[] = 'catalog';
return $sortables;
}
add_filter( 'woocommerce_sortable_taxonomies', 'make_catalog_sortable' );
@RadGH
RadGH / convert-term.php
Created July 22, 2015 07:24
Magic term conversion with WordPress
<?php
/*
Takes a term from many input types: object, id, slug, name
Returns one of many outputs: WP_Term (object), id (int), slug, name, or any WP_Term property
Example Inputs:
smart_term_convert( 390, 'category', 'id' ); // Returns 390
smart_term_convert( 'test-category', 'category', 'id' ); // Returns 390
smart_term_convert( 'Test Category', 'category', 'id' ); // Returns 390
@RadGH
RadGH / curl_get_post_url.php
Last active August 29, 2015 14:26
Perform a POST request using curl as a function, with arguments as an array
<?php
/**
* Example Usage
*/
$url = 'http://example.org/';
$vars = array(
'name' => 'Radley',
'awesome' => 1,
);
@RadGH
RadGH / yarp-template-image-previews.php
Created August 3, 2015 22:37
Yet Another Related Posts Plugin (YARPP) - Template with post thumbnails and better markup
<?php
/*
YARPP Template: Image Previews
Description: Four columns of posts, each with a photo.
Author: radgh (RadleyGH@gmail.com)
*/
// Put your placeholder image ID here, from the media tab in the dashboard, or leave it false to disable.
$placeholder_media_id = false;
@RadGH
RadGH / rs_upload_from_path.php
Last active November 2, 2023 17:52
Upload a local file as a WordPress attachment, placing it in the Media library. Supports images, PDFs, and other file types.
<?php
/**
* This function uploads from a local file path.
* To upload from a URL instead
* @see: https://gist.github.com/RadGH/966f8c756c5e142a5f489e86e751eacb
*
* Example usage: Upload photo from file, display the attachment as as html <img>
* $attachment_id = rs_upload_from_path( "/images/photo.png" );
* echo wp_get_attachment_image( $attachment_id, 'large' );
@RadGH
RadGH / wc-attributes-variations.php
Created September 10, 2015 18:10
WooCommerce: Display dropdowns for values of attributes (variations or text)
<?php
global $product;
if ( !isset($product) ) return;
if ( !method_exists( $product, 'get_attributes' ) ) return; // Doesn't support attributes, won't have a dropdown
$attributes = $product->get_attributes();
// Note: <form> is just so this section is styled like the default variation dropdown The form isn't meant to do anything.
?>
<form class="cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo $product->id; ?>">
@RadGH
RadGH / wp-video-thumbnail-attachments.php
Last active April 10, 2022 00:05
WP Utility functions to get youtube/vimeo images and store their thumbnails as attachments
<?php
function video_get_service( $video_url ) {
if ( stristr( $video_url, 'vimeo.com') ) {
return 'vimeo';
}
if ( stristr( $video_url, 'youtube.com' ) || stristr( $video_url, 'youtu.be' ) ) {
return 'youtube';
}
@RadGH
RadGH / recalculate-acf-locations.php
Last active July 19, 2023 19:16
Get latitude and longitude for addresses saved in Advanced Custom Fields, using Google's GeoLocation API
<?php
global $acf_recalc_settings;
// IMPORTANT: Customize these settings for your website.
$acf_recalc_settings = array(
// How many updates to do each page load. As of November 2018, Google's GeoLocation API limit is 100 per second.
'posts_per_run' => 16,
@RadGH
RadGH / git-pull.php
Created October 15, 2015 06:38
Git auto pull on commit from Bitbucket with PHP + Webhook
<?php
// Set up a webhook for your Bitbucket repo (or other service) that will visit this script (eg, http://example.org/git-pull.php).
// When you commit, Bitbucket will visit that URL.
// Now the script below runs, which will then pull from the bitbucket repo, grabbing the recently uploaded commit.
// All you have to do is push to Bitbucket!
// NOTE: This script relies on shell_exec and may not work on shared hosts.
$LOCAL_REPO = "/ABSOLUTE/PATH/TO/LOCAL/GIT/REPO/";
{
"kind": "metapackage",
"abstract": "A list of modules installed on the default KSP instance",
"name": "installed-default",
"license": "unknown",
"version": "2015.10.23.04.07.26",
"identifier": "installed-default",
"spec_version": "v1.6",
"depends": [
{