Skip to content

Instantly share code, notes, and snippets.

Avatar

Ross Wintle rosswintle

View GitHub Profile
@rosswintle
rosswintle / get_post_meta_filter.php
Last active Aug 7, 2021
Generic meta data filter for WordPress posts
View get_post_meta_filter.php
<?php
/*
* Add a generic post meta filter that allows you to create filters like
* get_post_metadata_{$key}
*/
add_filter('get_post_metadata', 'generic _meta_filter', 100, 5);
function generic_meta_filter($value, $object_id, $meta_key, $single, $meta_type) {
remove_filter('get_post_metadata' 'generic_meta_filter', 100, 5);
@rosswintle
rosswintle / build.php
Last active Jun 24, 2021
A VERY simple PHP static HTML generator that does a single-level extend, and includes with variable passing and that's about it.
View build.php
<?php
/*
* Input: files matching src/pages/*.html
* Output: public/*.html
*
* Pages can extend a template by calling:
*
* extend(string $relativeTemplatePath, array $variables)
*
* at the start and:
@rosswintle
rosswintle / spam-pixel.php
Created Mar 26, 2021
WordPress Spam Pixel code for WP Forms
View spam-pixel.php
<?php
/**
* Plugin Name: Spam Pixel
* Description: This simple plugin integrates Ross's spam pixel idea with WP Forms
* Author: Ross Wintle
* Author URI: https://rosswintle.uk
* Text Domain: spam-pixel
* Domain Path: /languages
* Version: 0.1.0
*
@rosswintle
rosswintle / AppNavigationMenu.php
Last active Sep 23, 2021
Laravel Jetstream Livewire Navigation Menu
View AppNavigationMenu.php
<?php
/**
* This class extends the base NavigationClass provided by Jetstream.
* Note that the base class includes the navigation-menu.blade.php
*/
namespace App\Http\Livewire;
class AppNavigationMenu extends \Laravel\Jetstream\Http\Livewire\NavigationMenu
{
@rosswintle
rosswintle / functions.php
Created Nov 20, 2020
Filter to make WordPress YouTube oembeds use the nocookie version
View functions.php
<?php
add_filter('oembed_result', 'youtubeEmbedNocookieFilter', 10, 3);
function youtubeEmbedNocookieFilter(string $data, string $url, array $args)
{
return str_replace('src="https://www.youtube.com/embed', 'src="https://www.youtube-nocookie.com/embed', $data);
}
@rosswintle
rosswintle / .bashrc-searches
Last active Oct 16, 2020
Command-line (bash) code-searching functions.
View .bashrc-searches
# Add these to your .bashrc file for some quick and clever recursive web-dev code searching
# from the command line/terminal.
#
# Should be easy enough to add your own too.
#
# Usage is just:
#
# phprgrep <regular expression>
#
# Regular expresssions need to be escaped/quoted if you're being clever.
@rosswintle
rosswintle / weird-wide-webring.php
Created May 19, 2020
Simple WordPress Widget for Jack McDade's Weird Wide Webring
View weird-wide-webring.php
<?php
/**
* Plugin Name: Weird Wide Webring
* Plugin URI: https://weirdwidewebring.net
* Description: A widget for displaying the Weird Wide Webring links
* Author: Ross Wintle
* Author URI: https://rosswintle.uk/
* Text Domain: weird-wide-webring
* Domain Path: /languages
* Version: 1.0.0
@rosswintle
rosswintle / AssetCache.php
Last active Feb 22, 2020
Statamic tag for my LaravelAssetCache package
View AssetCache.php
<?php
/*
* Tag for my LaravelAssetCache package: https://github.com/rosswintle/laravel-asset-cache/
*
* This grabs the asset file from the specified npm package from jsdelivr.net, and caches and serves it locally
*
* Before use you'll need to:
* composer require rosswintle/laravel-asset-cache
* php artisan storage:link (in all environments)
*
View wordpress-cleanup.php
<?php
/**
* Plugin Name: Wordpress Cleanup
*/
namespace WordPress_Cleanup;
/**
* Change filters here to control what this does
*/
@rosswintle
rosswintle / pair.php
Created Jan 10, 2019
Secret Santa Recursive Pairings
View pair.php
function make_valid_pairing( $people_to_pair, $people_yet_to_have_gifts ) {
// We made it! No more people left to pair! Return an empty array of pairings.
if (empty($people_to_pair)) {
return [];
}
// Get the first person
$person_to_pair = $people_to_pair[0];
// Get all the other people