Skip to content

Instantly share code, notes, and snippets.


Richard Tape richardtape

View GitHub Profile
richardtape / clean-slate.php
Created Oct 14, 2022
WP Theme Clean Slate
View clean-slate.php
// Add this to your functions.php for example...
add_action( 'init', 'rkn_clean_slate__init' );
* WP has a lot of initial...err...stuff even with a completely blank theme. Let's remove quite a bit
* of that.
View gutenberg-slot-and-fill.js
// Reduced Example. You'll need to do your imports.
// Add a custom control which contains a Slot
export const exampleAdditionalControl = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
return (
<BlockEdit { ...props } />
View gutenberg-sidebar-panel-and-control-dependencies.js
const { assign } = lodash;
const { __ } = wp.i18n;
const { Fragment } = wp.element;
const { addFilter } = wp.hooks;
const { TextControl, PanelBody } = wp.components;
const { createHigherOrderComponent } = wp.compose;
const { InspectorControls } = wp.editor;
View gutenberg-sidebar-panel-and-control-validate.js
// See
* Is the passed block name one which supports our custom field?
* @param {string} name The name of the block.
function isValidBlockType( name ) {
const validBlockTypes = [
richardtape / gutenberg-sidebar-add-attr-and-prop.js
Created Oct 5, 2018
Create custom gutenberg sidebar panel and control [add extra attr and props]
View gutenberg-sidebar-add-attr-and-prop.js
// See
* Filters registered block settings, extending attributes with our custom data.
* @param {Object} settings Original block settings.
* @return {Object} Filtered block settings.
export function addAttribute( settings ) {
richardtape / gutenberg-sidebar-panel-and-control.js
Created Oct 5, 2018
Create custom gutenberg sidebar panel and control
View gutenberg-sidebar-panel-and-control.js
// See
* Override the default edit UI to include a new block inspector control for
* adding our custom control.
* @param {function|Component} BlockEdit Original component.
* @return {string} Wrapped component.
richardtape / why-do-i-need-a-filename.hmm
Created Sep 14, 2017
wp-cli with sharded databases
View why-do-i-need-a-filename.hmm
# Be *very* careful with this.
# In your wp-config.php file
$db_name = getenv( 'WP_CLI_DB_NAME' );
define( 'DB_NAME', ( !empty( $db_name ) ? $db_name : 'default_global' ) ); # Default often 'wpmu_global'
# Then, when calling wp-cli, if the tables you want are in a shard called prefix_3f
# And you want to grab the comments table for a site with an ID of 10175
WP_CLI_DB_NAME=prefix_3f; export WP_CLI_DB_NAME; wp db export --tables=wp_10175_comments
richardtape /
Created Mar 3, 2017 — forked from jed/
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

richardtape /
Created May 7, 2015
Create multiple composer.json files automatically with name of directory and push to repos
# Scenario: You have a lot (say, 200+) plugins/themes/whatevers that you need to add to a composer setup
# and none of them have composer.json files. Also, none of them are on a git repo anywhere
# Here's how I solved this problem which would have taken days to do manually
# To get git repo in each directory and then push existing code to appropriate repo
for d in ./*/ ; do (cd "$d" && git init); done
for d in ./*/ ; do (cd "$d" && git add .); done
# To allow an empty commit message, don't judge me
git config --global alias.nccommit 'commit -a --allow-empty-message -m ""'
richardtape / subdir-loader.php
Created Aug 23, 2014
Allow WordPress-MU plugins to be loaded automatically from a sub directory
View subdir-loader.php
* Plugin Name: MU plugins subdirectory loader
* Plugin URI:
* Description: Enables the loading of plugins sitting in mu-plugins (as folders)
* Version: 0.1
* Author: iamfriendly, CTLT
* Author URI: