Skip to content

Instantly share code, notes, and snippets.


Tom J Nowell tomjn

View GitHub Profile

Force Gutenberg to Fullscreen Mode

This is an example snippet for forcing the Gutenberg editor into full screen mode in anticipation of the change coming to WordPress 5.4.

View color-log.js
function logColor(color, args) {
console.log(`%c ${args.join(' ')}`, `color: ${color}`);
const log = {
aliceblue: (...args) => { logColor('aliceblue', args)},
antiquewhite: (...args) => { logColor('antiquewhite', args)},
aqua: (...args) => { logColor('aqua', args)},
aquamarine: (...args) => { logColor('aquamarine', args)},
azure: (...args) => { logColor('azure', args)},
ahmadawais / upload-a-file.MD
Created Jun 18, 2017 — forked from websupporter/upload-a-file.MD
Upload a file using the WordPress REST API
View upload-a-file.MD

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

View WCMCR-Logo-BG.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
mboynes / trait-alley-cli-bulk-task.php
Last active Jul 22, 2021
WP-CLI methods to iterate over any number of posts efficiently and reliably
View trait-alley-cli-bulk-task.php
* Chunk up the task when you need to iterate over many posts.
* For instance, to iterate over every post on the site and add post meta:
* $this->bulk_task( function( $post ) {
* update_post_meta( $post->ID, 'some_meta', 'some value' );
* } );
tomjn /
Last active Mar 19, 2016
Copy paste into the terminal on OS X to download and install everything needed for VVV, then create a VVV vagrant box in ~/vvv

Open the "Terminal" application in MacOS X, then copy paste the script and press enter. It will install VVV and all its dependencies.

It will also install an additional site that will show how to add your own sites ( ).

When finished, it will do several things:

  • Open your www folder in Finder for editing
  • Open the VVV webpage for information
  • Open the CFTP Site init scaffold with information on how to add your own sites
bradphelan / SmallestAngleBetweenTestSuite.cs
Last active Mar 9, 2016
Test suite for smallest angle between in C#
View SmallestAngleBetweenTestSuite.cs
public void SmallestSignedAngleBetweenShouldWork ()
WMath.SmallestSignedAngleBetween(0.1, 0.2).Should().BeApproximately(0.1, 1e-5);
WMath.SmallestSignedAngleBetween(0.1, 0.2+Math.PI*2).Should().BeApproximately(0.1, 1e-5);
WMath.SmallestSignedAngleBetween(0.1, 0.2-Math.PI*2).Should().BeApproximately(0.1, 1e-5);
WMath.SmallestSignedAngleBetween(0.1+Math.PI*2, 0.2).Should().BeApproximately(0.1, 1e-5);
WMath.SmallestSignedAngleBetween(0.1-Math.PI*2, 0.2).Should().BeApproximately(0.1, 1e-5);
Rarst / doge.php
Last active Dec 27, 2019
Doge snippet for WordPress
View doge.php
?["Such $t","Very $t",'Wow'][rand(0,2)]
View gist:4fa3c4228a8bb53cc71d
load wp-config.php
set up default constants
load wp-content/advanced-cache.php if it exists
load wp-content/db.php if it exists
connect to mysql, select db
load object cache (object-cache.php if it exists, or wp-include/cache.php if not)
load wp-content/sunrise.php if it exists (multisite only)
westonruter / force_balance_tags2.php
Last active Aug 21, 2019
Use DOMDocument to do a more robust job at force_balance_tags.
View force_balance_tags2.php
* Use DOMDocument to do a more robust job at force_balance_tags.
* "force_balance_tags() is not a really safe function. It doesn’t use an HTML parser
* but a bunch of potentially expensive regular expressions. You should use it only if
* you control the length of the excerpt too. Otherwise you could run into memory issues
* or some obscure bugs." <>