Skip to content

Instantly share code, notes, and snippets.

Avatar

Frankie Jarrett fjarrett

View GitHub Profile
@fjarrett
fjarrett / gist:5544469
Last active Jun 17, 2019
Return an attachment ID using a URL in WordPress
View gist:5544469
<?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 Jul 17, 2017
Add first and last classes to your WordPress loop without using JavaScript
View gist:5550855
<?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 Jul 11, 2013
Homepage posts potential workaround
View home.php
<?php
get_template_part( 'archive' );
@fjarrett
fjarrett / gist:7358625
Last active Dec 27, 2015
Activate font smoothing for MP6
View gist:7358625
<?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 Dec 20, 2013
Attempt to resolve IP value database error
View gist:8058052
<?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
View gist:8259070
<?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 Aug 29, 2015
Adds a Failed Login Attempts action to the Users Connector
View failed_login_attempts.php
<?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 Feb 13, 2017
Frankie Jarrett's WordCamp speaker bio
View gist:7294fdc422dc738fd6cb

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 Sep 3, 2017
Frankie's OS X Bash Profile
View .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 Aug 29, 2015
Detect and format music chords in a document
View gist:3d5095fcfd39b55f639e
<?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 );