Skip to content

Instantly share code, notes, and snippets.

@nacin
nacin / auto-update.php
Last active March 11, 2019 17:17
This is how @dd32 and I test automatic background updates in WordPress 3.7. Then just do example.com/?wp_maybe_auto_update. (If you use a checkout of develop.svn.wordpress.org, you can run this on the `build` directory, then simply run `grunt copy` between updates to copy over the latest code from `src`. This is how we are able to make adjustmen…
<?php
// Add this as a mu-plugin.
if ( isset( $_GET['wp_maybe_auto_update'] ) ) {
add_filter( 'automatic_updates_is_vcs_checkout', '__return_false' );
add_action( 'template_redirect', function() {
$time = date( 'r' );
echo "Starting... $time<br />";
delete_site_option( 'auto_core_update_failed' );
@nacin
nacin / .bashrc
Created September 13, 2012 18:41
SVN status at the prompt
parse_svn_revision() {
local BRANCH WPVER INFO=$(svn info 2>/dev/null)
[ "$INFO" ] || return
REV=$(printf "%s\n" "$INFO" | grep Revision | sed -e 's/Revision: //')
BRANCH=$(printf "%s\n" "$INFO" | grep URL | sed -e 's/URL: //' | xargs basename)
if [ -f wp-includes/version.php ]; then
WPVER=$(grep wp_version\ = wp-includes/version.php | sed -e "s/.* '/ /" -e "s/';//")
fi
echo "$BRANCH:r$REV$WPVER"
}
@nacin
nacin / trac-attach.sh
Last active March 21, 2016 09:37
A script that leverages Trac XML-RPC (I know, I know) to upload patches. Usage: `trac-attach.sh 12345`
#!/bin/sh
# A script that leverages Trac XML-RPC (I know, I know) to upload patches.
#
# This script is written specifically for the Mac, in that it reads from
# your keychain to derive your SVN password. You can change the SVN_PASS
# line below if you wanted to pull from ~/.svn/ or what not.
#
# Basic usage: `trac-attach.sh 12345` uploads a patch to ticket #12345,
# using the name 12345.diff. If there exists a 12345.diff, the patch is
@nacin
nacin / london-contribute.md
Created November 24, 2013 12:40
WordCamp London 2013 Contributor Day Notes from the introduction to contributing to core.
@nacin
nacin / functions.php
Created September 23, 2013 14:00
Removes 'Private:' and 'Protected' from the start of post titles.
<?php
function nacin_remove_private_protected_from_titles( $format ) {
return '%s';
}
add_filter( 'protected_title_format', 'nacin_remove_private_protected_from_titles' );
add_filter( 'private_title_format', 'nacin_remove_private_protected_from_titles' );
<?php
/*
* Plugin Name: Hacky Taxonomy Archives
* Description: Don't use this on a live site, plz. Proof of concept for Aaron Holbrook.
* Author: Andrew Nacin
*/
add_action( 'template_redirect', function() {
global $wp_rewrite;
$taxonomy = 'fruits';
@nacin
nacin / gist:5533549
Last active December 17, 2015 02:08 — forked from rlerdorf/gist:5530518
PemFTP
--------------------------------
File : wp-admin/includes/class-ftp.php:508
Reason : UseUndeclaredVariable
Snippet : $arg
Line : return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist");
--------------------------------
File : wp-admin/includes/class-ftp.php:508
Reason : UseUndeclaredVariable
Snippet : $arg
<?php
//** Redirect if not logged in
add_action( 'template_redirect', function() {
if ( ! is_user_logged_in() ) {
wp_redirect( wp_login_url() );
exit;
}
} );
<?php
class GP_WPorg_Rosetta_Roles extends GP_Plugin {
var $id = 'wporg-rosetta-roles';
function __construct() {
parent::__construct();
$this->add_filter( 'pre_can_user', array( 'args' => 2, 'priority' => 9 ) );
}
@nacin
nacin / update-wordpress.sh
Created January 31, 2013 19:37
Update WordPress with a dirty bash script. (Please use version control, not this...)
#!/bin/sh
WEBROOT=/var/www/wordpress
LATEST_VER=$(curl -s http://api.wordpress.org/core/version-check/1.5/ | head -n 4 | tail -n 1)
LOCAL_VER=$(grep wp_version\ = $WEBROOT/wordpress/wp-includes/version.php | grep -o "'.*'" | sed -e "s/'//g")
echo "Latest version of WordPress: $LATEST_VER"
echo "Version on $(uname -n): $LOCAL_VER"
if [ "$LATEST_VER" == "$LOCAL_VER" ]; then
echo "No need to update.";