Skip to content

Instantly share code, notes, and snippets.

Frankie Jarrett fjarrett

View GitHub Profile
@fjarrett
fjarrett / .profile
Created Aug 10, 2017
Docker <--> Valet
View .profile
# Toggle localhost between Docker and Valet
quitapp () {
command osascript -e 'quit app "'$*'"' &
}
alias usevalet="quitapp Kitematic && quitapp Docker && valet restart && mysqld &>/dev/null &"
alias usedocker="open -a Docker && valet stop && mysql.server stop && open -a Kitematic"
@fjarrett
fjarrett / cdn-baseurl.php
Created Jul 20, 2017
Filter the media uploads baseurl to point to a CDN
View cdn-baseurl.php
<?php
// Turn ON: $ wp option update cdn_baseurl https://abc123.cloudfront.net/wp-content/uploads
// Turn OFF: $ wp option delete cdn_baseurl
$cdn_baseurl = get_option( 'cdn_baseurl' );
if ( ! $cdn_baseurl ) {
return;
@fjarrett
fjarrett / php-constants-regex.md
Last active Jul 14, 2017
Match values of PHP constant definitions by type
View php-constants-regex.md

The Regex

/define\(\s*[\'"]FOO[\'"]\s*,\s*(?:[\'"](.+)[\'"]|([\d]+)|([\d\.]+)|(true|false))\s*\)/gi

Purpose: To reference constant values from a PHP file (wp-config.php) that should not be included.
Author: Frankie Jarrett
Link: https://regex101.com/r/kBFIl5/

@fjarrett
fjarrett / gist:4ef5890043a80904c542339b1fd1ffb2
Created Jun 6, 2017
List of cache groups used in WordPress core
View gist:4ef5890043a80904c542339b1fd1ffb2
_meta
blog-details
blog-id-cache
blog-lookup
bookmark
calendar
category
comment
counts
networks
@fjarrett
fjarrett / centos.sh
Created Jun 5, 2017
Bash alias to allow root to run WP-CLI commands as another user
View centos.sh
# force `wp` commands to run as the `www-data` user
wp() {
if [ $1 == "cli" ]; then
command wp $* --allow-root
elif [ $(whoami) != "www-data" ]; then
su www-data -c "wp $*"
else
command wp $*
fi
}
@fjarrett
fjarrett / foo-plugin.php
Last active Apr 28, 2017
Foo Plugin Boilerplate
View foo-plugin.php
<?php
/**
* Plugin Name: Foo Plugin
* Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit!
* Version: 1.0.0
* Author: Your Name
* Author URI: https://yourwebsite.com
* Text Domain: foo-plugin
* Domain Path: /languages
* License: GPL-2.0
@fjarrett
fjarrett / using-ceph-or-s3-bucket-for-wp-uploads.md
Last active Dec 21, 2017
How to use a Ceph (or S3) bucket for WordPress uploads
View using-ceph-or-s3-bucket-for-wp-uploads.md

How to use a Ceph (or S3) bucket for WordPress uploads

Listed below are the steps I took to use Ceph object store for WordPress media without a plugin. It works by mounting Ceph (or an AWS S3) bucket as a network device on the file system via s3fs and using wp-content/uploads/ as the mount path.

Since s3fs is POSIX compatible, it means you can still access (and manage) the media within wp-content/uploads/ over SFTP/SSH as if they are natively there.

WP-CLI commands such as wp media import and wp media regenerate also still work.

Although your media is being stored and fetched from a network storage bucket, your web server can still resolve all the requests to wp-content/uploads/ on the local filesystem like normal.

This means that image URLs do not have to be rewritten and will use the core format you're used to over HTTP https://mysite.com/wp-content/uploads/cat.jpg and any absolute filesystem paths in PHP that may exist `/path/to/wp-content

@fjarrett
fjarrett / ps1.sh
Last active Mar 15, 2017
Collection of simple PS1s for bash profiles
View ps1.sh
# HH:MM:SS [cwd] $
export PS1="\t [\W] \\$ "
# HH:MM:SS [cwd] $ (colorized)
export PS1="\[\e[37m\]\t\[\e[m\] \[\e[36m\][\[\e[m\]\[\e[36m\]\W\[\e[m\]\[\e[36m\]]\[\e[m\] \[\e[32m\]\\$\[\e[m\] "
# user@host [/path/to/cwd] $
export PS1="\u@\h [\w] \\$ "
# user@host [/path/to/cwd] $ (colorized)
@fjarrett
fjarrett / primer-hero-as-link.php
Last active Mar 4, 2017
Turn the entire Hero section into a clickable link
View primer-hero-as-link.php
@fjarrett
fjarrett / .bash_profile
Last active Mar 29, 2017
Run WP Coding Standards sniffs on themes/plugins
View .bash_profile
# ------------------------------------------------------------
# Run WP Coding Standards sniffs on themes/plugins
#
# See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
#
# $ composer require global wp-coding-standards/wpcs
# $ phpcs --config-set installed_paths ~/.composer/vendor/wp-coding-standards/wpcs
# ------------------------------------------------------------
WPCS_EXCLUDE="WordPress.WhiteSpace.ControlStructureSpacing,Squiz.Commenting.FileComment"
WPCS_IGNORE="*/.dev/*,*/.git/*,*/bin/*,*/build/*,*/lib/*,*/node_modules/*,*/tests/*,*/vendor/*"
You can’t perform that action at this time.