Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Tom J Nowell tomjn

🎯
Focusing
View GitHub Profile
View exclude.php
<?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 ) {
View central-column-variation.js
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 Aug 21, 2020
A basic server rendered block, like a shortcode but blocks!
View block.js
( 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 Aug 6, 2020
Changes needed for p2020 theme to work without wp.com
View p2020.diff
Index: functions.php
===================================================================
--- functions.php (revision 56804)
+++ functions.php (working copy)
@@ -7,9 +7,19 @@
namespace P2020;
+function is_automattician() {
+ return false;
View emoji.txt
🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦
🟦🟦🟦🟨🟨🟨🟨🟦🟦🟦🟦
🟦🟦🟨🟨🟨🟨⬛🟨🟦🟦🟦
🟦🟨🟨⬛🟨🟨⬛🟨🟨🟦🟦
🟦🟨🟨⬛🟨🟨🟨🟨🟨🟦🟦
🟦🟨🟨🟨🟨🟨🟨🟨🟨🟦🟦
🟦🟨🟨🟨⬛⬛🟧🟧🟨🟦🟦
🟦🟦🟨🟨🟧🟧🟧🟧🟧🟧🟦
🟦🟦🟦🟨🟨🟨🟨🟧🟧🟧🟦
🟦🟦🟦🟦🟦🟦🟦🟧🟧🟦🟦
View standard-wpquery-post-loop.php
<?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 Jan 25, 2019
A naive and incomplete, but functional approach to http2 push
View tomjn_http2_push.php
<?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 Jan 15, 2019
Provisioner log of tideways utility
View gist:194136e3ecbe693cf1749c4622ea00a3
==> 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
View rest_endpoint.php
<?php
function toms_addition_endpoint( \WP_REST_Request $request ) {
$result = $request['a'] + $request['b'];
return rest_ensure_response( $result );
}
function toms_addition_routes() {
register_rest_route( 'tomjn/v1', '/addition', array(
View datastore.lua
DataStore = {
data = {},
subscribers = {}
}
function DataStore:new (o)
o = o or {} -- create object if user does not provide one
setmetatable(o, self)
self.__index = self
return o
end