Skip to content

Instantly share code, notes, and snippets.

View helen's full-sized avatar
🥇
#first-name-club

Helen Hou-Sandi helen

🥇
#first-name-club
View GitHub Profile
@johnpbloch
johnpbloch / short-circuit.php
Created November 21, 2011 20:10
Short Circuit a post save in WordPress and give the user a notice saying why.
<?php
namespace JPB;
function wp_insert_post_data( $data, $postarr ){
if($data['foo'] !== 'bar' || $data['baz'] !== 'bat'){
wp_redirect( add_query_arg( array( 'post' => $data['ID'], 'action' => 'edit', 'message' => 11 ), admin_url( 'post.php' ) ) );
exit;
}
return $data;
@PeteMall
PeteMall / wp-honeybadger.php
Created January 21, 2012 01:50
This is just the beginning
<?php
add_action( 'init', 'wp_honeybadger_it' );
function wp_honeybadger_it() {
remove_filter( 'the_content', 'capital_P_dangit', 11 );
remove_filter( 'the_title', 'capital_P_dangit', 11 );
remove_filter( 'comment_text', 'capital_P_dangit', 31 );
// more to come...
@Viper007Bond
Viper007Bond / add-another-category-to-posts.php
Created February 16, 2012 08:24
WordPress: Add Another Category To Posts
<?php
/**
* Takes posts that are in category A and also adds them to category B
*/
// Uncomment this to proceed
exit( "You need to edit the file and enter the hostname and category IDs.\n" );
// What blog? Asking for both for safety reasons.
@staylor
staylor / comment-count.php
Created April 20, 2012 19:09
Get the actual number of comments + replies per page, WP comments_per_page is really top-level comments only: allows you to identify 1-12 of 13, etc for comments count UI instead of mistakenly labeling page 1 as 1-10
<?php
function get_cpage_comment_count() {
$counter = $start = 0;
wp_list_comments( array( 'callback' => function ( $comment ) use ( &$counter, &$start ) {
global $wpdb;
if ( 0 === $counter ) {
$sql = $wpdb->prepare(
"SELECT COUNT(comment_ID) FROM {$wpdb->comments}
WHERE comment_approved = 1 AND
@Rarst
Rarst / wordpress.less
Created April 26, 2012 20:04
WordPress colors vars in LESS
// Logo
// http://wordpress.org/about/logos/
@wp_logo_blue: #21759B;
@wp_logo_orange: #D54E21;
@wp_logo_grey: #464646;
// Admin
// http://dotorgstyleguide.wordpress.com/outline/colors/
@evansolomon
evansolomon / gist:3568555
Created September 1, 2012 09:53
Bash helpers for navigating WordPress code
# Alias ST2's command line tool for a shorter (easier-to-remember) name
alias st="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
# Search for an open Sublime Text to a function definition
function fx() {
ack "function &?$1\(" | awk {'print $1'} | sed 's/:$//g' | xargs st
}
# Example usage from the root of a WordPress repository
@nacin
nacin / Modific.sublime-settings.js
Created September 25, 2012 06:52
My config for Modific. Disables --internal-diff (didn't work on Mac OSX 10.8 with svn 1.6.18 client). Reprograms a few key bindings I'll actually use.
// Modific default settings
{
// Name of a region icon
// Valid icon names are dot, circle, bookmark and cross
"region_icon": "circle",
// You can use your commands instead of plain "git" or "svn"
// e.g. "/usr/bin/git" or "C:\bin\git.exe"
"vcs": [
["svn", "/usr/bin/svn"],
@kurtpayne
kurtpayne / rarst.php
Created December 3, 2013 15:00
Super subtle troll
<?php
/**
* Plugin Name: Rarst's favorite plugin
* Description: SHUT UP
* Version: INF
* Author: The unholy army of trolls
* License: GPLv2 or MIT (they're equivalent, right?)
*/
add_action( 'all', function() {
global $wp_filter;
@markjaquith
markjaquith / gist:2312948
Last active March 13, 2017 20:32
How to get PHP Unit working for WordPress Unit Tests using MAMP Pro

WordPress Unit Tests using MAMP Pro

Note: Work in progress document.

Note: Change the PHP version number as appropriate to your MAMP Pro install.

  1. Add the following you your PATH, making sure that it is first: /Applications/MAMP/bin/php/php5\.3\.6/bin:/Applications/MAMP/bin/apache2/bin:/Applications/MAMP/bin
  2. mv /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf.bak
  3. source ~/.profile (or where ever you made your PATH changes)
  4. sudo pear update-channels &amp;&amp; sudo pear upgrade pear
@rmccue
rmccue / gist:ec6a7d79349ea7e9b206
Last active March 28, 2017 21:22
WordPress test server - front controller for testing WP. *****NEVER USE THIS ON PRODUCTION******
<?php
/**
* WordPress Test Server
*
* This serves up a full WordPress site via the PHP test server (`php -S`), and
* is intended purely for serving WP for UI testing. Please do not ever use this
* in production.
*/
// Path to WP install