Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Jaquith markjaquith

View GitHub Profile
@markjaquith
markjaquith / gist:2653957
Created May 10, 2012
WordPress Fragment Caching convenience wrapper
View gist:2653957
<?php
/*
Usage:
$frag = new CWS_Fragment_Cache( 'unique-key', 3600 ); // Second param is TTL
if ( !$frag->output() ) { // NOTE, testing for a return of false
functions_that_do_stuff_live();
these_should_echo();
// IMPORTANT
$frag->store();
// YOU CANNOT FORGET THIS. If you do, the site will break.
@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 / home-page-redirect.php
Last active Feb 7, 2021 — 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 );
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',
@markjaquith
markjaquith / disable-plugins-when-doing-local-dev.php
Created Jun 24, 2011
Disables specified WordPress plugins when doing local development
View disable-plugins-when-doing-local-dev.php
<?php
/*
Plugin Name: Disable plugins when doing local dev
Description: If the WP_LOCAL_DEV constant is true, disables plugins that you specify
Version: 0.1
License: GPL version 2 or any later version
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
@markjaquith
markjaquith / suicidal-filter.php
Last active Jan 22, 2021
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.
View Disable-ACF-UI.php
<?php
// Block the ACF settings UI entirely, except on local dev.
if (! defined('WP_LOCAL_DEV') || ! WP_LOCAL_DEV) {
add_filter('acf/settings/show_admin', '__return_false');
add_filter('acf/settings/capability', function () { return 'do_not_allow'; });
}
@markjaquith
markjaquith / gist:7029068
Created Oct 17, 2013
How to get git-svn working in OS X Mavericks with Homebrew
View gist:7029068
sudo xcodebuild -license
xcode-select --install # There will be a GUI prompt
sudo cpan SVN::Core # use the "sudo" method when prompted
# Then add this to your ~/.profile:
# export PATH=/Library/Developer/CommandLineTools/usr/bin:$PATH
# Then probably:
brew reinstall git
brew reinstall subversion
@markjaquith
markjaquith / nginx.conf
Last active Sep 22, 2020
My WordPress Nginx setup
View nginx.conf
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;
@markjaquith
markjaquith / gist:6225805
Last active Jul 22, 2020
WordPress multi-tenant directory structure sharing core files for opcode awesomeness, fast deployments, and low disk usage. With inspiration from @weskoop. "=>" indicates a symlink.
View gist:6225805
sites
|__ ms.dev
| |__ content
| |__ index.php
| |__ wp => ../../wordpress/stable
| |__ wp-config.php
|__ one.dev
| |__ content
| |__ index.php
| |__ wp => ../../wordpress/stable