Skip to content

Instantly share code, notes, and snippets.

View thenbrent's full-sized avatar

Brent Shepherd thenbrent

View GitHub Profile
@thenbrent
thenbrent / gist:3244346
Created August 3, 2012 04:22
Regex to replace *_user_meta() API function calls with *_user_option() API function calls (to improve WordPress Network Compatability)
# For get_user_meta: replace the function name, argument order & make sure no default value (3rd parameter) is passed to the get_user_option function
# FIND:
get_user_meta\(\s?(.*?),\s?([^,\)\s]*)\s?(,(.*?))?\)
# REPLACE:
get_user_option( $2, $1 )
# For update_user_meta: replace the function name & don't carry over the 4th $prev_value argument
@thenbrent
thenbrent / WP_Rewrite_Object
Created August 7, 2012 23:45
Content of an unmodified WP_Rewrite_Object
WP_Rewrite Object (
[permalink_structure] => /%postname%/
[use_trailing_slashes] => 1
[author_base] => author
[search_base] => search
[comments_base] => comments
[pagination_base] => page
[feed_base] => feed
[comments_feed_structure] =>
[front] => /
@thenbrent
thenbrent / wp_rewrite_rules.log
Created August 7, 2012 23:46
Default WordPress Rewrite Rules
[rules] => Array (
[category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/page/?([0-9]{1,})/?$] => index.php?category_name=$matches[1]&paged=$matches[2]
[category/(.+?)/?$] => index.php?category_name=$matches[1]
[tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/page/?([0-9]{1,})/?$] => index.php?tag=$matches[1]&paged=$matches[2]
[tag/([^/]+)/?$] => index.php?tag=$matches[1]
[type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?post_format=$matches[1]&feed=$matches[2]
@thenbrent
thenbrent / gist:3357350
Created August 15, 2012 07:25
Set correct admin messages for all custom post type in WordPress
<?php
/**
* Customise the messsages for all custom post types in a WordPress install.
*
* @author Brent Shepherd <brent@findingsimple.com>
* @package eg
* @subpackage CPT
* @since 1.0
*/
function eg_cpt_update_messages( $messages ) {
@thenbrent
thenbrent / clean-slate.sh
Last active October 16, 2015 21:41
Sometimes, you just want to start with a clean slate
#! /bin/bash
# Drop the existing content of a database and replace it with a backup
DBUSER="root"
DBPASS="root"
DBNAME="INSERT-DB-NAME"
IMPORTFILE="$DBNAME.sql"
echo ".........................................."
echo -e " Enter the name of the DB backup (with extension): \c"
@thenbrent
thenbrent / gist:3838301
Created October 5, 2012 05:46
Subscription scheduled payment & cron lock logger
<?php
$subscription_keys = array( '285_139', '304_108' );
foreach ( $subscription_keys as $subscription_key ) {
$user_id = 2;
error_log('----');
@thenbrent
thenbrent / gist:3850317
Created October 8, 2012 01:51
In WooCommerce, don't slide payment field box up-and-down (useful when only accepting one payment method)
jQuery(document).ready(function($){
$('.payment_methods input.input-radio').die('click');
});
@thenbrent
thenbrent / test-plugin.php
Created October 8, 2012 08:36
Test plugin shell for Chae
<?php
/**
* Plugin Name: Test Plugin
* Description: Test plugins and themes.
* Author: Brent Shepherd
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@thenbrent
thenbrent / gist:4021225
Created November 5, 2012 23:53
Subscriptions 1.2 Changelog
WooCommerce Subscriptions version 1.2 changes:
* Support for sale prices on subscription products
* On the Manage Subscriptions page, store managers can now search for subscriptions by subscriber username, email, order ID, product ID or subscription item name (subscription product name at time of purchase)
* Any payment gateway with a WooCommerce extension can now be used to purchase and renew subscriptions via manual payments
* Subscribers can now use a different payment method for each recurring payment via manual payments
* Subscribers can now change the payment method on a subscription if an automatic payments fails
* A subscription's next payment date can now be changed if the payment gateways used to purchased it can change the date
* WooCommerce reports now include revenue from subscription's recurring payments
* Improved record keeping for recurring subscription payments with a renewal order created for each payment
* Improved shipping management for subscriptions with physical goods through
@thenbrent
thenbrent / gist:4082249
Created November 15, 2012 23:15
Fix WC Subscriptions coupon bug
Find line #192 of class-wc-subscriptions-coupon.php which is currently this:
if( ! 'recurring_fee' == $coupon->type || ! 'sign_up_fee' == $coupon->type )
and replace it with this:
if( ! in_array( $coupon->type, array( 'recurring_fee', 'sign_up_fee' ) ) )