Skip to content

Instantly share code, notes, and snippets.

View richardtape's full-sized avatar

Richard Tape richardtape

View GitHub Profile
@richardtape
richardtape / clean-slate.php
Created October 14, 2022 23:02
WP Theme 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.
*
@richardtape
richardtape / gutenberg-slot-and-fill.js
Created September 12, 2019 21:13
Gutenberg Slot and Fill
// 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 } />
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;
// 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 October 5, 2018 00:24
Create custom gutenberg sidebar panel and control [add extra attr and props]
// 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 October 5, 2018 00:18
Create custom gutenberg sidebar panel and control
// 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 September 14, 2017 01:06
wp-cli with sharded databases
# 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 March 3, 2017 22:42 — 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

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 23:39
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
richardtape / subdir-loader.php
Created August 23, 2014 01:35
Allow WordPress-MU plugins to be loaded automatically from a sub directory
<?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/
*