Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Davis chrisguitarguy

View GitHub Profile
@chrisguitarguy
chrisguitarguy / default-author.php
Created Jul 2, 2012
Set a default author for posts on your WordPress site.
View default-author.php
<?php
/*
Plugin Name: Default Author
Plugin URI: http://pmg.co
Description: Set a default author for all posts and pages
Version: 1.0
Text Domain: default-author
Author: Christopher Davis
Author URI: http://christopherdavis.me
License: GPL2
@chrisguitarguy
chrisguitarguy / 23268.diff
Last active Mar 23, 2021
WP_Query `NOT EXISTS` examples
View 23268.diff
diff --git wp-includes/meta.php wp-includes/meta.php
index 8a9dad9..d3e4f82 100644
--- wp-includes/meta.php
+++ wp-includes/meta.php
@@ -708,7 +708,7 @@ class WP_Meta_Query {
// Split out the meta_key only queries (we can only do this for OR)
if ( 'OR' == $this->relation ) {
foreach ( $this->queries as $k => $q ) {
- if ( ! isset( $q['value'] ) && ! empty( $q['key'] ) )
+ if ( ( empty( $q['compare'] ) || 'NOT EXISTS' != $q['compare'] ) && ! isset( $q['value'] ) && ! empty( $q['key'] ) )
@chrisguitarguy
chrisguitarguy / evident_io_terraform.tf
Last active Feb 17, 2021
Terraform configuration for an Evident.io IAM Role
View evident_io_terraform.tf
variable "evident_account" {
type = "string"
}
variable "evident_id" {
type = "string"
}
data "aws_iam_policy_document" "evident" {
statement {
@chrisguitarguy
chrisguitarguy / wp-registration-keys.php
Created Aug 30, 2011
Only lets users with an invite code register for a WordPress site.
View wp-registration-keys.php
<?php
/*
Plugin Name: WP Invite Codes
Plugin URI: http://pmg.co/
Description: Makes wordpress an invite only community.
Version: n/a
Author: Christopher Davis
Author URI: http://pmg.co/people/chris
*/
@chrisguitarguy
chrisguitarguy / commandbus.py
Last active Feb 11, 2021
Command bus pattern in Python.
View commandbus.py
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Playing Around with the Command Bus Pattern in Python
"""
import inspect
import collections
@chrisguitarguy
chrisguitarguy / pmg-rewrite.php
Created Feb 11, 2012
WordPress rewrite tutorial
View pmg-rewrite.php
<?php
/*
Plugin Name: Rewrite Rule Tutorials
*/
add_action( 'init', 'pmg_rewrite_add_rewrites' );
function pmg_rewrite_add_rewrites()
{
add_rewrite_endpoint( 'json', EP_PERMALINK );
add_rewrite_rule(
@chrisguitarguy
chrisguitarguy / fields-to-tags.php
Created Dec 2, 2011
Custom fields to post tages
View fields-to-tags.php
<?php
/*
Plugin Name: Custom Field to Tag
Author: Christopher Davis
Author URI: http://www.christopherguitar.net/
*/
/**
* CHANGE THIS! what is your custom field's name?
*/
@chrisguitarguy
chrisguitarguy / no_bom.php
Last active Dec 16, 2020
Remove BOM from a string
View no_bom.php
<?php
$file = new \SplFileObject('some_file_with_bom.csv');
// http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8
$bom = pack('CCC', 0xEF, 0xBB, 0xBF);
$first = true;
foreach ($file as $line) {
if ($first && substr($line, 0, 3) === $bom) {
$line = substr($line, 3);
@chrisguitarguy
chrisguitarguy / proxy-auth.py
Created Dec 17, 2011
Add proxy authorization to requests
View proxy-auth.py
import requests
from base64 import b64encode
proxy = {
'http': 'http://173.208.208.74:60099'
}
class HTTPProxyAuth(requests.auth.HTTPBasicAuth):
"""Like requests.auth.HTTPBasicAuth, but adds a Proxy-Authorization header"""
def __call__(self, r):
@chrisguitarguy
chrisguitarguy / server.py
Created Oct 24, 2011
Super simple python socket server and HTTP request class.
View server.py
import socket, traceback
HOST = ''
PORT = 51235
CLRF = '\r\n'
class InvalidRequest(Exception):
pass
class Request(object):