Skip to content

Instantly share code, notes, and snippets.

View butlerblog's full-sized avatar

Chad Butler butlerblog

View GitHub Profile
@butlerblog
butlerblog / json_manifest.py
Created December 9, 2023 14:58
Prints a json manifest of an archive.org book
import requests
import argparse
import json
my_parser = argparse.ArgumentParser()
my_parser.add_argument('-id', '--id', help='ID of the book (https://archive.org/details/XXXX).', type=str)
args = my_parser.parse_args()
book_id = args.id
url = "https://archive.org/details/"+book_id
@butlerblog
butlerblog / mkpdf.py
Created May 24, 2023 15:17
Python script to create a PDF from a directory of sequentially named images
import img2pdf
import argparse
import os
def process_images(min_range, max_range, img_path, prefix, suffix, out_file):
images = []
for i in range(min_range,max_range):
fname = img_path + prefix + '%0.3d' % i + '.' + suffix
print("adding img: " + fname)
images.append(fname)
@butlerblog
butlerblog / search_all_w_meta.php
Created January 10, 2023 18:01
Add meta data to WordPress default search
<?php
add_action( 'pre_get_posts', array( $this, 'search_metadata' ), 9 );
function search_metadata() {
if ( ! is_main_query() || ! is_search() ) {
return;
}
add_filter( 'posts_join', function( $join ) {
global $wpdb;
@butlerblog
butlerblog / find_callback.php
Last active November 24, 2022 10:10
#utility for finding callback functions hooked to a specific hook
<?php // do not use this line. Add below to functions.php
add_action( 'wp_footer', 'list_hooked_filters_and_actions' );
add_action( 'login_footer', 'list_hooked_filters_and_actions' );
add_action( 'admin_footer', 'list_hooked_filters_and_actions' );
function list_hooked_filters_and_actions() {
global $wp_filter;
@butlerblog
butlerblog / woocommerce-settings-tab-demo.php
Last active March 29, 2024 09:15 — forked from BFTrick/woocommerce-settings-tab-demo.php
A plugin demonstrating how to add a #WooCommerce settings tab.
<?php
/**
* Plugin Name: WooCommerce Settings Tab Demo
* Plugin URI: https://gist.github.com/BFTrick/b5e3afa6f4f83ba2e54a
* Description: A plugin demonstrating how to add a WooCommerce settings tab.
* Author: Patrick Rauland
* Author URI: http://speakinginbytes.com/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
@butlerblog
butlerblog / wp_mail_bcc.php
Last active July 19, 2021 17:29
#wp_mail add bcc based on contents of subject line
<?php // DO NOT include this line. Add below to your theme functions.php
/**
* Add bcc address to email based on contents
* of the email subject line.
*
* Set email address and content of the subject
* line for the email being filtered.
*/
add_filter( 'wp_mail', 'custom_mails' );
@butlerblog
butlerblog / custom-queries.php
Created November 22, 2018 14:13 — forked from carlodaniele/custom-queries.php
An example plugin showing how to add custom query vars, rewrite tags and rewrite rules to WordPress
<?php
/**
* @package Custom_queries
* @version 1.0
*/
/*
Plugin Name: Custom queries
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin
Author: Carlo Daniele
@butlerblog
butlerblog / columns.css
Created November 14, 2018 13:29 — forked from studiopress/columns.css
Genesis column classes.
/* Column Classes
Link: http://twitter.github.io/bootstrap/assets/css/bootstrap-responsive.css
--------------------------------------------- */
.five-sixths,
.four-sixths,
.one-fourth,
.one-half,
.one-sixth,
.one-third,
@butlerblog
butlerblog / 0.php
Last active November 12, 2018 13:17
How to use anonymous functions for simple filters
<?php
/**
* This gist is example code that goes with an article on how (and why/when) to use
* PHP anonymous functions. To view the entire post, go to:
* https://rocketgeek.com/basics/using-anonymous-functions-for-filters-and-actions/
*/
@butlerblog
butlerblog / mc_put_req.php
Last active November 24, 2021 18:36
#Mailchimp list subscribe "put" request
<?php
/**
* Utility function to subscribe a user to a MailChimp
* list using the MC API 3.0
*
* @param array $args {
* Array of settings.
*
* @type string $api_key Your MailChimp API key.