Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Tape richardtape

View GitHub Profile
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 (
<Fragment>
<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 richardtape.com/?p=348
/**
* 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
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 https://richardtape.com/?p=348
/**
* 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
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 richardtape.com/?p=348
/**
* 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
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
richardtape / how-to-set-up-stress-free-ssl-on-os-x.md
Created Mar 3, 2017 — forked from jed/how-to-set-up-stress-free-ssl-on-os-x.md
How to set up stress-free SSL on an OS X development machine
View how-to-set-up-stress-free-ssl-on-os-x.md

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
richardtape / saved-me-hours-and-hours.sh
Created May 7, 2015
Create multiple composer.json files automatically with name of directory and push to repos
View saved-me-hours-and-hours.sh
# 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
richardtape / subdir-loader.php
Created Aug 23, 2014
Allow WordPress-MU plugins to be loaded automatically from a sub directory
View subdir-loader.php
<?php
/**
* Plugin Name: MU plugins subdirectory loader
* Plugin URI: http://code.ctlt.ubc.ca
* Description: Enables the loading of plugins sitting in mu-plugins (as folders)
* Version: 0.1
* Author: iamfriendly, CTLT
* Author URI: http://ubc.ca/
*
@richardtape
richardtape / install-oh-my-zsh-on-ubuntu
Created Aug 4, 2014
Install Oh My ZSH on Ubuntu 14.04
View install-oh-my-zsh-on-ubuntu
# Where is the location of your current shall. Useful if we need to revert
echo $0
# Install ZSH
sudo apt-get install zsh
# Instal GIT
sudo apt-get install git-core
# Install OhMyZSH
You can’t perform that action at this time.