Skip to content

Instantly share code, notes, and snippets.

View hlashbrooke's full-sized avatar
🎲

Hugh Lashbrooke hlashbrooke

🎲
View GitHub Profile
@hlashbrooke
hlashbrooke / function.php
Last active December 13, 2023 12:19
WooCommerce - Check if you are running a specified WooCommerce version (or higher)
<?php
function woocommerce_version_check( $version = '2.1' ) {
if ( function_exists( 'is_woocommerce_active' ) && is_woocommerce_active() ) {
global $woocommerce;
if( version_compare( $woocommerce->version, $version, ">=" ) ) {
return true;
}
}
return false;
}
@hlashbrooke
hlashbrooke / style.css
Last active September 5, 2023 01:35
CSS for a responsive 2-column layout in the TTRPG Roll Tables WordPress plugin: https://hlashbrooke.itch.io/ttrpg-roll-tables-wordpress-plugin
#rolltable-data-tables, .rolltable_tables {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
gap: 0.5em;
}
.rolltable_data_block {
flex: 0 0 45%;
min-width: 450px;
@hlashbrooke
hlashbrooke / class.php
Created February 28, 2014 08:37
A complete, versatile options page class for any WordPress plugin
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class WordPress_Plugin_Template_Settings {
private $dir;
private $file;
private $assets_dir;
private $assets_url;
private $settings_base;
@hlashbrooke
hlashbrooke / functions.php
Created October 27, 2015 06:43
Seriously Simple Podcasting: Use raw audio file URL instead of custom rewrite
add_filter( 'ssp_episode_download_link', 'ssp_use_raw_audio_file_url', 10, 3 );
function ssp_use_raw_audio_file_url ( $url, $episode_id, $file ) {
return $file;
}
@hlashbrooke
hlashbrooke / functions.php
Last active January 21, 2023 11:13
Seriously Simple Podcasting: Modify podcast archive slug
add_filter( 'ssp_archive_slug', 'ssp_modify_podcast_archive_slug' );
function ssp_modify_podcast_archive_slug ( $slug ) {
return 'new-slug';
}
@hlashbrooke
hlashbrooke / function.php
Created July 12, 2013 11:13
WordPress: Add plugin settings link to plugins list table
<?php
function plugin_add_settings_link( $links ) {
$settings_link = '<a href="options-general.php?page=plugin_name">' . __( 'Settings' ) . '</a>';
array_push( $links, $settings_link );
return $links;
}
$plugin = plugin_basename( __FILE__ );
add_filter( "plugin_action_links_$plugin", 'plugin_add_settings_link' );
?>
@hlashbrooke
hlashbrooke / function.php
Created August 21, 2013 11:01
WooCommerce: Get all order statuses as an array
<?php
function woocommerce_get_order_statuses() {
$order_statuses = get_terms( 'shop_order_status', array( 'hide_empty' => false ) );
$statuses = array();
foreach ( $order_statuses as $status ) {
$statuses[ $status->slug ] = $status->name;
}
return $statuses;
}
?>
@hlashbrooke
hlashbrooke / function.php
Last active July 4, 2022 21:35
WordPress: Display posts in a random order, but retain persistent pagination
<?php
session_start();
add_filter( 'posts_orderby', 'randomise_with_pagination' );
function randomise_with_pagination( $orderby ) {
if( is_front_page() ) {
// Reset seed on load of initial archive page
@hlashbrooke
hlashbrooke / functions.php
Last active April 6, 2022 16:49
WooCommerce Product Vendors: Add extra custom fields to vendor profiles
<?php
// Add fields to new vendor form
add_action( 'shop_vendor_add_form_fields', 'custom_add_vendor_fields', 2, 1 );
function custom_add_vendor_fields( $taxonomy ) {
?>
<div class="form-field">
<label for="vendor_website"><?php _e( 'Vendor website' ); ?></label>
<input type="text" name="vendor_data[website]" id="vendor_website" class="vendor_fields" /><br/>
<span class="description"><?php _e( 'The vendor\'s website.' ); ?></span>
@hlashbrooke
hlashbrooke / seriously-simple-podcasting.conf
Created November 11, 2015 19:27
Seriously Simple Podcasting: Fix for Nginx servers where the podcast downloads and audio player are not working and/or returning a 404 error.
location ~* ^/podcast-download/ {
try_files $uri $uri/
fastcgi_index /index.php;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
location ~* ^/podcast-player/ {
try_files $uri $uri/
fastcgi_index /index.php;