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: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 / home.php
Created July 11, 2013 15:58
Homepage posts potential workaround
<?php
get_template_part( 'archive' );
@fjarrett
fjarrett / gist:7358625
Last active December 27, 2015 16:59
Activate font smoothing for MP6
<?php
/**
* Adds font smoothing to MP6 in the Admin Bar and the entire WP Admin area.
*
* @print HTML
* @action admin_head
* @action wp_head
*/
function fjarrett_mp6_font_smoothing() {
if ( ! is_plugin_active( 'mp6/mp6.php' ) )
@fjarrett
fjarrett / gist:8058052
Created December 20, 2013 17:10
Attempt to resolve IP value database error
<?php
/**
* Log handler
* @param string $message sprintf-ready error message string
* @param array $args sprintf (and extra) arguments to use
* @param int $object_id Target object id
* @param string $action Action performed (stream_action)
* @param int $user_id User responsible for the action
* @param array $contexts Contexts of the action
<?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 / failed_login_attempts.php
Last active August 29, 2015 14:01
Adds a Failed Login Attempts action to the Users Connector
<?php
class WP_Stream_Connector_Failed_Login_Attempts extends WP_Stream_Connector_Users {
/**
* Actions registered for this connector
*
* @var array
*/
public static $actions = array(
@fjarrett
fjarrett / gist:7294fdc422dc738fd6cb
Last active February 13, 2017 18:39
Frankie Jarrett's WordCamp speaker bio

Frankie Jarrett is a full-stack developer from St. Joseph, Missouri who has been building WordPress products since 2007. He is Senior WordPress Product Engineer at GoDaddy and loves the fact that he gets to work with WordPress every single day.

From launching his own theme shop in 2011, to building large-scale enterprise websites, authoring dozens of plugins, and now creating amazing product experiences on GoDaddy's hosting platform - WordPress has always been at the center of Frankie's career, and he plans to keep it that way!

Outside of work, Frankie loves being a dad to his two boys, Rivers and Bear, traveling with his wife, Gracie, smoking his own BBQ, and yelling at the TV during games.

@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 / gist:3d5095fcfd39b55f639e
Last active August 29, 2015 14:04
Detect and format music chords in a document
<?php
function fjarrett_format_chords( $content ) {
$new_content = null;
$pattern = '/\b[A-G](?:##?|bb?)?(?:min|m)?(?:maj|add|sus|aug|dim)?[0-9]*(?:\/[A-G](?:##?|bb?)?)?(?!\S)/';
// Iterate over each line in the document
foreach ( preg_split( '/((\r?\n)|(\r\n?))/', $content ) as $line ) {
// Find chords on this line
preg_match_all( $pattern, $line, $matches );