Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / short-number-format.php
Last active February 25, 2025 21:33
Short Number Formatter for PHP (1000 to 1k; 1m; 1b; 1t)
<?php
// Converts a number into a short version, eg: 1000 -> 1k
// Based on: http://stackoverflow.com/a/4371114
function number_format_short( $n, $precision = 1 ) {
if ($n < 900) {
// 0 - 900
$n_format = number_format($n, $precision);
$suffix = '';
} else if ($n < 900000) {
@RadGH
RadGH / image-sizes.php
Created November 16, 2015 17:45
define & use custom image sizes
<?php
// $src = wp_get_attachment_image_src( $attachment_id, 'store-archive' );
// $src[0] = "http://.../uploads/my_image-240x350.jpg"
// $src[1] = 240
// $src[2] = 350
add_action( 'after_setup_theme', 'ld_theme_image_sizes' );
function ld_theme_image_sizes() {
// archive pages
@RadGH
RadGH / df-rooms.md
Last active December 10, 2017 16:04
Dwarf Fortress Rooms & Industries for 42.04

Dwarf Fortress Rooms & Industries

This is a list of rooms and industries that you will be building in Dwarf Fortress v42.xx. Use it to help plan your fortress, get some ideas, or figure out what should go in your stockpiles.

Primary Industries

Food

Indoor Storage: Raw plants, Prepared meals

@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 / 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 / install.php
Last active October 15, 2020 06:49
Custom install script for WordPress to update some common settings during installation
<?php
function ld_custom_installation( $user_id ) {
global $wpdb, $wp_rewrite, $table_prefix;
// Use a blank site description instead of "Just another WordPress site"
update_option( 'blogdescription', '' );
// Set Timezone to PST -- Full list at http://php.net/manual/en/timezones.america.php
update_option( 'timezone_string', "America/Los_Angeles" );
@RadGH
RadGH / featured_image_fallback.php
Created July 7, 2016 16:40
Use the first image from post content as a featured image, if no featured image is set for a post
@RadGH
RadGH / swipebox-autoplay-for-youtube.js
Created October 14, 2016 22:27
Swipebox autoplay fix (Youtube Only)
// Autoplay youtube videos in Swipebox
var autoplaySlide = function() {
var $slider = jQuery('#swipebox-slider');
var $slide = $slider.children('.slide.current');
var $iframe = $slide.find('iframe');
if ( $iframe.length > 0 ) {
if ( $iframe.attr('src').indexOf('youtu') >= 0 ) {
if ( $iframe.attr('src').indexOf('autoplay=') >= 0 ) {
$iframe.attr('src', function() { return jQuery(this).attr('src').replace('autoplay=0', 'autoplay=1'); });
@RadGH
RadGH / get-video-oembed-wordpress.php
Last active October 3, 2022 01:03
Get oEmbed data using WordPress oEmbed API, specifically for Video iframe
<?php
// Example 1) Using a function. Returns an array.
function radgh_get_video_data( $url, $width = null, $height = null ) {
if ( function_exists('_wp_oembed_get_object') ) {
require_once( ABSPATH . WPINC . '/class-oembed.php' );
}
$args = array();
if ( $width ) $args['width'] = $width;
if ( $height ) $args['height'] = $height;
@RadGH
RadGH / woocommerce-add-to-cart-url-with-redirect.php
Last active September 27, 2017 12:38
WooCommerce URL to add to cart and redirect to cart or checkout with quantity, limit, and option to remove other products.
<?php
/*
* Returns a URL that upon visiting, will add the product to the cart and do some other things as described below.
* $qty = How many items to add to the cart
* $limit = If true, it will prevent you from having more than $qty in your cart.
* $remove_others = If true, any other products will be removed from the cart.
* $redirect_to = If set to "cart" or "checkout", will redirect after adding the item. Does not work with a URL (to avoid XSS).
*
* @param $product_id
* @param int $qty