Skip to content

Instantly share code, notes, and snippets.

Mark Jaquith markjaquith

Block or report user

Report or block markjaquith

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@markjaquith
markjaquith / README.md
Created Apr 11, 2019
Identify images that are displayed wider than their natural width (which results in them looking blurry)
View README.md
  1. Paste this into your browser console.
  2. Start resizing the window.
  3. Any images that are ever displayed in a blurry fashion will throw an error and get faded out to 0.05 opacity.
@markjaquith
markjaquith / gform-stripe-use-older-api.php
Created Feb 25, 2018
Force Gravity Forms Stripe add-on to use an older version of the Stripe API, so subscriptions work
View gform-stripe-use-older-api.php
<?php
add_action( 'gform_stripe_post_include_api', function() {
if ( method_exists( '\Stripe\Stripe', 'setApiVersion' ) ) {
\Stripe\Stripe::setApiVersion( '2016-07-06' );
}
});
View plugin.php
<?php
/**
* Plugin Name: YOUR PLUGIN NAME
*/
include( dirname( __FILE__ ) . '/lib/requirements-check.php' );
$your_plugin_requirements_check = new YOUR_PREFIX_Requirements_Check( array(
'title' => 'YOUR PLUGIN NAME',
'php' => '5.4',
View block-unnecessary-image-queries.php
<?php
/*
Plugin Name: Block WordPress attachment queries
Description: Blocks MySQL queries for WordPress attachments that are on domains we know will never resolve to a local WordPress attachment ID.
Author: Mark Jaquith
*/
add_filter( 'query', function( $query ) {
global $wpdb;
@markjaquith
markjaquith / readme.md
Last active Jun 11, 2017
For WordPress, a method to re-index a multi-dimensional array by the (unique) value of a given array key
View readme.md

Okay, so, let's say you have some data like this:

$things = [
  0 => [ 'id' => 123, 'title' => '123 Title', 'content' => '123 Content' ],
  1 => [ 'id' => 456, 'title' => '456 Title', 'content' => '456 Content' ],
  2 => [ 'id' => 789, 'title' => '789 Title', 'content' => '789 Content' ],
];
@markjaquith
markjaquith / home-page-redirect.php
Last active Feb 20, 2017 — forked from davidzack/gist:194f37444c9d68630308ee416381ef61
If user is logged in, and on the front page, redirect to /?firstName=FIRST&lastName=LAST
View home-page-redirect.php
<?php
function home_page_first_last_name_redirect() {
if ( is_front_page() && is_user_logged_in() && ! isset( $_GET['firstName'] ) ) {
$user = wp_get_current_user();
$url = add_query_arg( array(
'firstName' => $user->first_name,
'lastName' => $user->last_name,
));
wp_redirect( $url );
@markjaquith
markjaquith / suicidal-filter.php
Last active May 11, 2019
Version of `add_filter()` for WordPress that only runs once
View suicidal-filter.php
<?php
/*
Use this just like `add_filter()`, and then run something that calls the filter (like
`new WP_Query`, maybe).
That's it. If the filter gets called again, your callback will not be.
This works around the common "filter sandwich" pattern where you have to remember to
call `remove_filter` again after your call.
@markjaquith
markjaquith / wp-update-plugins-git.sh
Created Aug 5, 2016
Update all WordPress plugins using WP-CLI and make a separate git commit for each one
View wp-update-plugins-git.sh
#!/bin/bash
PLUGINS=$(wp plugin list --update=available --field=name | tr -d '\r');
wp plugin update-all;
for plugin in $PLUGINS; do
git add -A "wp-content/plugins/$plugin";
git commit -m "Update plugin: $plugin";
done;
@markjaquith
markjaquith / iMessage.sql
Created Feb 7, 2016
iMessage texting stats
View iMessage.sql
SELECT COUNT(*) as messages_count, handle.id as person from message JOIN handle on handle.ROWID = message.handle_id WHERE strftime( '%Y-%m', datetime(message.date + strftime('%s','2001-01-01'), 'unixepoch')) = '2016-01' GROUP BY handle_id ORDER BY messages_count DESC;
@markjaquith
markjaquith / aaa.nginxconf
Last active Feb 1, 2017
Grab non-locally-existing production images from Photon for your local WordPress dev environment
View aaa.nginxconf
location ~* \.(jpe?g|gif|png)$ {
try_files $uri @photon;
}
location @photon {
rewrite ^(.*)-([0-9]+)x([0-9]+)\.(jpe?g|gif|png)$ http://i0.wp.com/$host$1.$4?resize=$2,$3;
rewrite . http://i0.wp.com/$host$request_uri;
}
You can’t perform that action at this time.