Skip to content

Instantly share code, notes, and snippets.

View butlerblog's full-sized avatar

Chad Butler butlerblog

View GitHub Profile
@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 / functions.php
Last active March 28, 2024 02:09
SMTP using wp-config.php for settings #smtp #wp_mail
<?php // Don't use this line.
/*
* Add the script below to wherever you store custom code snippets
* in your site, whether that's your child theme's functions.php,
* a custom plugin file, or through a code snippet plugin.
*/
/**
* This function will connect wp_mail to your authenticated
@butlerblog
butlerblog / wp_config.php
Last active February 1, 2024 09:00
Configure WordPress #wp_mail function to send through #SMTP server https://b.utler.co/Y3
<?php
/*
* Set the following constants in wp-config.php.
* These should be added somewhere BEFORE the constant ABSPATH is defined.
*
* Author: Chad Butler
* Author URI: https://butlerblog.com
*
* For more information and instructions, see: https://b.utler.co/Y3
@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 / 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 / my_get_plugin_info.php
Last active September 20, 2022 20:05
#utility to get plugin info
<?php // no need to use this line.
/**
* Utility to get information on installed plugins.
*
* Returns an array of all installed plugins and indicates which are
* plugin are active and which are not. Array is keyed by the plugin's
* folder/slug.php (which is how WP looks at them) and includes the
* name, version, and true/false whether it is active or not.
*
@butlerblog
butlerblog / wpmem_add_custom_email.php
Last active November 24, 2021 18:39
WP-Members #API functions
<?php
add_action( 'wpmem_after_admin_init', 'my_add_custom_wpmembers_email' );
function my_add_custom_wpmembers_email() {
// Required arguments for wpmem_add_custom_email()
$tag = 'my_unique_msg_tag';
$heading = 'Heading to display input in Emails tab';
$subject_input = 'my_unique_subj_tag';
$message_input = 'my_unique_body_tag';