Skip to content

Instantly share code, notes, and snippets.

@davidsword
davidsword / wp-image-filters.php
Last active January 15, 2023 22:20
WordPress - All filters to modify an images URL (as far as I could find)
<?php
// Images in post galleries
add_filter( 'get_post_galleries', '_img_url_filter', PHP_INT_MAX );
add_filter( 'widget_media_image_instance', '_img_url_filter', PHP_INT_MAX );
// Core image retrieval
add_filter( 'image_downsize', '_img_url_filter', 10, 3 );
// Responsive image srcset substitution
@davidsword
davidsword / convert-alfred-snippets-to-espanso.php
Last active November 8, 2022 00:38
Convert Alfred Snippets to Espanso matches
<?php
/**
* Convert Alfred Snippets to Espanso matches
*
* @see https://www.alfredapp.com/help/features/snippets/
* @see https://espanso.org/
*/
define('SNIPPETS_DIR', '/path/to/export/of/Alfred/snippets/');
<?
// ✅ will work
add_shortcode('rocktheboat', function () {
ob_start();
echo " Hello world";
return ob_get_clean();
});
<?
// ❌ won't work, will show at top of page
add_shortcode('rocktheboat', function ()  {
   echo "hello world";
});
// ✅ will work, will replace shortcode with returned text
add_shortcode('rocktheboat', function () {
@davidsword
davidsword / http-status-codes.json
Created July 7, 2022 23:16
HTTP STATUS CODES IN .JSON parsed from https://github.com/waldemarnt/http-status-codes . forked text a little, I added prepended extras on descriptions of 301+302 for myself.
{
"100" : {
"title": "Continue",
"description": "Client should continue with request."
},
"101" : {
"title": "Switching Protocols",
"description": "Server is switching protocols."
},
"102" : {
<body onload="showOrHideAlert()">
<div id='alert' style="background:yellow">
Alert banner generated by PHP, always in the HTML
<a id='alert_dismiss' onclick="setDismissAlertCookie()">[X]</a>
</div>
<script>
function showOrHideAlert() {
const hidden = document.cookie.split('; ').find(row => row.startsWith('dismissAlert='))?.split('=')[1];
@davidsword
davidsword / dsca-convert-db-to-localhost.sh
Created April 7, 2022 18:59
script to do s+r on mysql dump from davidsword.ca -> local dev env
#!/bin/bash
#$1 is the first parameter being passed when calling the script. The variable filename will be used to refer to this.
FILENAME=$1
DSCA_LOCALHOST_ADDR=""
echo "🏃 doing r+r"
# s+r https to http (until I get a RP setup locally)
@davidsword
davidsword / dollarsign-minimal.zsh-theme
Last active January 3, 2022 23:13
Minimal ZSH theme, for those who copy/pasta their terminal a lot.
# install:
#
# 1. create a file with this gists contents
# $ vi ~/.oh-my-zsh/themes/dollarsign-minimal.zsh-theme
#
# 2. edit ~/.zshrc and set `ZSH_THEME="dollarsign-minimal"`
# $ vi ~/.zshrc
#
# 3. reload zshrc
# $ source ~/.zshrc
<?
// this is to be put in a single site/plugin.. not network wide.
// if it's network wide it will run a `transient` for each site. which'd be ridiculous
// it only needs to run in a single site enviroment
add_action('init', 'update_super_admins_access');
function update_super_admins_access() {
// since this is a big thing to do, we can run a test and see whats
// going to happen before it does
$test = false;
<?
// settings
$url = "https://example.com/queryforjson"; // json source
$cache = __DIR__."/json.cache"; // make this file in same dir
$force_refresh = false; // dev
$refresh = 60*60; // once an hour
// cache json results so to not over-query (api restrictions)
if ($force_refresh || ((time() - filectime($cache)) > ($refresh) || 0 == filesize($cache))) {