Skip to content

Instantly share code, notes, and snippets.

View fjarrett's full-sized avatar

Frankie Jarrett fjarrett

View GitHub Profile
@fjarrett
fjarrett / foo-plugin.php
Last active April 28, 2017 20:42
Foo Plugin Boilerplate
<?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 December 16, 2021 23:00
How to use a Ceph (or S3) bucket for WordPress uploads

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 March 15, 2017 22:45
Collection of simple PS1s for bash profiles
# 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 March 4, 2017 07:41
Turn the entire Hero section into a clickable link
@fjarrett
fjarrett / .bash_profile
Last active March 29, 2017 03:23
Run WP Coding Standards sniffs on themes/plugins
# ------------------------------------------------------------
# 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/*"
@fjarrett
fjarrett / php5.php
Last active January 20, 2017 21:36
Bug in PHP5: ksort() w/ SORT_NUMERIC flag incorrectly sorts PHP_INT_MAX with a bitwise Not operator
<?php
/**
* PHP 5.6.29
*/
var_dump( ~PHP_INT_MAX < -PHP_INT_MAX ); // bool(true)
var_dump( ~PHP_INT_MAX > -PHP_INT_MAX ); // bool(false)
@fjarrett
fjarrett / child-functions.php
Created January 19, 2017 09:21
Replace mustache placeholders in Child Theme starter content
<?php
/**
* Filter starter content placeholders for new sites using this Child Theme.
*
* @var array
*/
add_filter( 'mysite_starter_content_placeholders', function () {
return [
@fjarrett
fjarrett / detect-serialized-data.sql
Last active January 18, 2017 07:57
Detect serialized data with regex in MySQL - https://regex101.com/r/mXyzmI/2
/* Select rows that contain serialized data */
SELECT * FROM `wp_options` WHERE `option_value` RLIKE '(a:[0-9]+:{)|(s:[0-9]+:)|(i:[0-9]+;)|(O:[0-9]+:\")';
/* Select rows that don't contain serialized data */
SELECT * FROM `wp_options` WHERE `option_value` NOT RLIKE '(a:[0-9]+:{)|(s:[0-9]+:)|(i:[0-9]+;)|(O:[0-9]+:\")';
@fjarrett
fjarrett / class-returner.php
Last active December 11, 2016 05:24
Return class for magic WordPress filter callback methods.
<?php
/**
* This class is designed to return a basic value by parsing the dynamic
* static method name you call to determine its type and value.
*
* It's useful for filtering values in WordPress quickly without having
* to create a callback function. Think of this as a continuation of the
* callback helpers already in WordPress: __return_true(), et al.
*
@fjarrett
fjarrett / search-css.php
Last active July 29, 2016 22:22
Return an array of CSS selectors that have certain properties.
<?php
/**
* Return an array of CSS selectors that have certain properties.
*
* Example: fjarrett_search_css( 'font-family: "Open Sans"' )
* Result: array( 'h1', 'h2', 'h3', 'h4', 'h5', 'p', 'blockquote' );
*
* @param string $path
* @param string $search