Skip to content

Instantly share code, notes, and snippets.

View tomjn's full-sized avatar
🎯
Focusing

Tom J Nowell tomjn

🎯
Focusing
View GitHub Profile
@tomjn
tomjn / local-kitten.php
Last active May 24, 2023 17:22
Replace missing attachments with placekitten placeholders, useful for local imports of databases without the uploads folder
<?php
/**
* Local Kitten images.
*
* Filters image URLs to load files from placekitten if they aren't present locally.
*
* @wordpress-plugin
* Plugin Name: Local Kitten Images
* Version: 1.0.2
* Description: Loads missing image files from placekitten when using local environment.
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Fragment } from 'react';
import { BlockControls } from '@wordpress/block-editor';
import { isUnmodifiedDefaultBlock } from '@wordpress/blocks';
import {
ToolbarButton,
ToolbarGroup,
} from '@wordpress/components';
@tomjn
tomjn / exclude.php
Last active February 26, 2021 21:11
<?php
function exclude_post_categories( $exclude = '', $spacer = ' ' ) {
$categories = get_the_category();
if ( empty( $categories ) ) {
return;
}
$exclude = explode( ',', $exclude );
$counter = count( get_the_category() ) - count( $exclude );
foreach ( $categories as $cat ) {
wp.blocks.registerBlockVariation(
'core/column',
{
name: 'featured-column',
isDefault: false,
title: 'Featured Column',
description: 'A highlighted central column!',
attributes: { className: 'central' },
}
@tomjn
tomjn / block.js
Created August 21, 2020 22:30
A basic server rendered block, like a shortcode but blocks!
( function( wp ) {
var el = wp.element.createElement;
wp.blocks.registerBlockType( 'tomjn/dynamic', {
title: 'Toms Dynamic Block',
edit: function( props ) {
return el( wp.serverSideRender, {
block: 'tomjn/dynamic',
attributes: props.attributes,
} );
},
@tomjn
tomjn / p2020.diff
Created August 6, 2020 17:20
Changes needed for p2020 theme to work without wp.com
Index: functions.php
===================================================================
--- functions.php (revision 56804)
+++ functions.php (working copy)
@@ -7,9 +7,19 @@
namespace P2020;
+function is_automattician() {
+ return false;
🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦
🟦🟦🟦🟨🟨🟨🟨🟦🟦🟦🟦
🟦🟦🟨🟨🟨🟨⬛🟨🟦🟦🟦
🟦🟨🟨⬛🟨🟨⬛🟨🟨🟦🟦
🟦🟨🟨⬛🟨🟨🟨🟨🟨🟦🟦
🟦🟨🟨🟨🟨🟨🟨🟨🟨🟦🟦
🟦🟨🟨🟨⬛⬛🟧🟧🟨🟦🟦
🟦🟦🟨🟨🟧🟧🟧🟧🟧🟧🟦
🟦🟦🟦🟨🟨🟨🟨🟧🟧🟧🟦
🟦🟦🟦🟦🟦🟦🟦🟧🟧🟦🟦
@tomjn
tomjn / standard-wpquery-post-loop.php
Created May 27, 2020 10:24
A standard WP_Query loop
<?php
$args = [
// parameters go here
];
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// display the post
@tomjn
tomjn / tomjn_http2_push.php
Created January 25, 2019 23:43
A naive and incomplete, but functional approach to http2 push
<?php
/**
* Plugin name: HTTP2 Push scripts
* Author: Tom J Nowell
*/
function tomjn_get_dep_url( /*\WP_Dependency*/ $dep ) {
global $wp_version;
$relative = str_replace( site_url(), '', $dep->src );
$ver = $dep->ver;
@tomjn
tomjn / gist:194136e3ecbe693cf1749c4622ea00a3
Created January 15, 2019 01:15
Provisioner log of tideways utility
==> default: Running provisioner: utility-mte90-tideways (shell)...
default: Running: /var/folders/jx/3t2z3sgx7sb3mwlml6v2xskh0000gp/T/vagrant-shell20190115-33101-1pdjm18.sh
default: Installing Tideways & XHgui
default: File copied for php 7.0
default: cp:
default: cannot stat ‘/home/vagrant/tideways.ini’
default: : No such file or directory
default: cp:
default: cannot stat ‘/home/vagrant/mongodb.ini’
default: : No such file or directory