Skip to content

Instantly share code, notes, and snippets.

View markjaquith's full-sized avatar

Mark Jaquith markjaquith

View GitHub Profile
@markjaquith
markjaquith / home-page-redirect.php
Last active February 7, 2021 15:00 — forked from davidzack/gist:194f37444c9d68630308ee416381ef61
If user is logged in, and on the front page, redirect to /?firstName=FIRST&lastName=LAST
<?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 October 22, 2023 23:14
Version of `add_filter()` for WordPress that only runs once
<?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 August 5, 2016 13:17
Update all WordPress plugins using WP-CLI and make a separate git commit for each one
#!/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 February 7, 2016 17:56
iMessage texting stats
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 February 1, 2017 04:30
Grab non-locally-existing production images from Photon for your local WordPress dev environment
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;
}
@markjaquith
markjaquith / 0_reuse_code.js
Last active September 7, 2016 14:41
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@markjaquith
markjaquith / gist:1d1c5f7e0ff502928e89
Created March 18, 2015 20:28
exclude post type from search
<?php
add_action( 'parse_query', 'gws_exclude_from_search' );
function gws_exclude_from_search( $q ) {
$exclude_from_search = array( 'gallery-entries' );
if ( $q->is_search ) {
foreach ( $exclude_from_search as $post_type ) {
$post_type_object = get_post_type_object( $post_type );
$post_type_object->exclude_from_search = true;
@markjaquith
markjaquith / gist:dd3e5cf2bcadd888284e
Created February 22, 2015 23:17
Raw Notes from #wptybee Updates Session
<h1 id="updatesinyourface">Updates in your Face</h1>
<h2 id="farfuture">Far Future</h2>
<ul>
<li>Make updates as smooth and magical and graceful as possible</li>
<li>Continuous releases</li>
<li>Move from shrinkwrap to more agile, continuous development</li>
<li>Perhaps a direction, not a goal</li>
<li>People hate change, and they hate change they didn’t opt in to</li>
<li>Language pack Plugins, Core, Themes, in that order?</li>
</ul>
@markjaquith
markjaquith / nginx.conf
Last active December 25, 2022 15:55
My WordPress Nginx setup
upstream phpfpm {
server unix:/var/run/php5-fpm.sock;
}
upstream hhvm {
server unix:/var/run/hhvm/hhvm.sock;
}
# SSL
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

Keybase proof

I hereby claim:

  • I am markjaquith on github.
  • I am markjaquith (https://keybase.io/markjaquith) on keybase.
  • I have a public key whose fingerprint is 6537 F2DF 3921 E11E 46C5 D6B7 56AD 3A85 0F62 922E

To claim this, I am signing this object: