Skip to content

Instantly share code, notes, and snippets.

View fjarrett's full-sized avatar

Frankie Jarrett fjarrett

View GitHub Profile
@fjarrett
fjarrett / gist:5544469
Last active June 17, 2019 16:13
Return an attachment ID using a URL in WordPress
<?php
/**
* Return an ID of an attachment by searching the database with the file URL.
*
* First checks to see if the $url is pointing to a file that exists in
* the wp-content directory. If so, then we search the database for a
* partial match consisting of the remaining path AFTER the wp-content
* directory. Finally, if a match is found the attachment ID will be
* returned.
*
@fjarrett
fjarrett / gist:2657482
Last active April 4, 2019 00:31
How to hide your WordPress version number…completely
<?php
/* Hide WP version meta tag from header and generator tag from feeds
* @return null
* @filter the_generator
*/
function fjarrett_remove_wp_version_tag() {
return null;
}
add_filter( 'the_generator', 'fjarrett_remove_wp_version_tag' );
@fjarrett
fjarrett / cdn-baseurl.php
Created July 20, 2017 16:53
Filter the media uploads baseurl to point to a CDN
<?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 / wp-config.php
Last active November 15, 2017 06:21
Replacement wp-config.php file for WP project repos
<?php
/**
* This is a `wp-config.php` replacement file for WP project repositories.
*
* It's purpose is to allow WP configurations such as database credentials,
* auth salts and other constants to be environment-agnostic and live outside
* of version control and outside the `public_html` docroot.
*
* Place your environment-specific `wp-config.php` one level above the docroot
* in a `config` dir.
<?php
/**
* Override the output of the submit button on forms, useful for
* adding custom classes or other attributes.
*
* @param string $button An HTML string of the default button
* @param array $form An array of form data
* @return string $button
*
* @filter gform_submit_button
@fjarrett
fjarrett / .bash_profile
Last active September 3, 2017 23:22
Frankie's OS X Bash Profile
# ------------------------------------------------------------
# Set paths
# ------------------------------------------------------------
export PATH=/usr/local/bin:$PATH
export WP_CLI_PHP="/Applications/MAMP/bin/php5.2/bin/php"
# ------------------------------------------------------------
# Add color to the terminal
# ------------------------------------------------------------
export CLICOLOR=1
@fjarrett
fjarrett / .profile
Created August 10, 2017 15:55
Docker <--> Valet
# 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 / gist:b15788c0786bac78e0ba
Created September 8, 2014 20:36
Missouri Senator Roy Blunt's response to net neutrality
Dear Frankie,
Thank you for contacting me regarding net neutrality.
As you know, in 2010, the Federal Communications Commission (FCC)
established rules to regulate the Internet. The FCC claimed it could
regulate the Internet under the authority of its traditional telephone
regulations developed during the monopoly-era. A DC Circuit Court
recently struck down certain parts of these rules and decided the FCC
@fjarrett
fjarrett / gist:5550855
Last active July 17, 2017 09:33
Add first and last classes to your WordPress loop without using JavaScript
<?php
/**
* Display the classes for the post div and automatically mark the first and last posts
*
* @param string|array $class One or more classes to add to the class list.
* @param int|WP_Post $post_id Optional. Post ID or post object.
*/
function fjarrett_post_class( $class = '', $post_id = null ) {
global $wp_query;
@fjarrett
fjarrett / php-constants-regex.md
Last active July 14, 2017 07:25
Match values of PHP constant definitions by type

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/