Skip to content

Instantly share code, notes, and snippets.

View thenbrent's full-sized avatar

Brent Shepherd thenbrent

View GitHub Profile
<?php
/**
* Plugin Name: WCS 1.4 Upgrade Fix
* Plugin URI:
* Description: Custom plugin to fix a database that fell out of sync with Subscriptions 1.4's database structure.
* Author: Brent Shepherd
* Author URI:
* Version: 1.0
*/
(function( window, undefined ) {
'use strict';
function WP_API() {
this.models = {};
this.collections = {};
this.views = {};
}
@thenbrent
thenbrent / error-log-setup.php
Last active August 29, 2015 14:05
Set PHP error log from `wp-config.php`
<?php
if ( ! defined( 'WP_DEBUG' ) ) {
define('WP_DEBUG', true);
}
if ( ! defined( 'WP_DEBUG_DISPLAY' ) ) {
define('WP_DEBUG_DISPLAY', false);
}
if ( ! defined( 'WP_DEBUG_LOG' ) ) {
define('WP_DEBUG_LOG', true);
@thenbrent
thenbrent / wcs-remove-zero-recurring.php
Last active August 29, 2015 14:06
Remove $0.00 recurring discount coupon amount
<?php
/*
Plugin Name: WooCommerce Subscriptions Remove $0.00 Recurring Discount
Plugin URI:
Description: Do not include a $0.00 recurring discount amount when a coupon is displaying it. For example, instead of display a coupon discount as "$10.00 now then $0.00 / month", display it as "$10.00".
Author:
Author URI:
Version: 0.1
*/
@thenbrent
thenbrent / Custom_Post_Type_Capabiltiies_Test.php
Created June 1, 2010 12:10
Custom post type caps experiment
<?php
/*
Plugin Name: Custom Post Type Capabiltiies Test
Plugin URI: http://wordpress.org/
Description: Testing to see if a subscriber without edit_others capability can edit posts.
Author: Brent
Version: 1
*/
function ppt_register_post_type() {
@thenbrent
thenbrent / gist:1294615
Created October 18, 2011 04:29
Unobtrusively get the IDs of ALL posts in a WordPress query, not just the posts on the current page
/**
* Unobtrusively gets the IDs of all posts in the current query, not just the posts shown on the current page.
*
* @author Brent Shepherd <brent@findingsimple.com>
* @since 1.0
*/
function eg_get_all_posts_in_query() {
global $wp_query;
// Turn paging off & specify that we only want post IDs
@thenbrent
thenbrent / gist:1686148
Created January 27, 2012 00:34
PCRE Regex to match HTML tags & capture the tag & its contents
/(\<[^\>]+\>)([^\<]+)(\<\/[^\>]+\>)?/
@thenbrent
thenbrent / gist:1686151
Created January 27, 2012 00:35
Regex to match a given term only when it does not appear within certain HTML tags (ie. a) or WP shortcodes
$pattern = '/([^a-zA-Z0-9-_>\[])(' . preg_quote( $given_term ) . ')([^a-zA-Z0-9-_<\]])(?!([^<]*)(\>|\<\/a|\]|<\/h\d\>))/i'
@thenbrent
thenbrent / gist:2396366
Created April 16, 2012 04:43
Regex to match WordPress i18Nn function with no text domain specified
(_e\(\s*'[^']*')(\s*)(?=\))(\))
(__\(\s*'[^']*')(\s*)(?=\))(\))
Or do them in both, also account for strings using "" instead of just '':
(_[e|_]\(\s*['|"][^,'"]*['|"])(\s?)(?=\))(\){1})
@thenbrent
thenbrent / gist:2832609
Created May 30, 2012 01:56
Count all words in all the posts of a WordPress site via MySQL
SELECT SUM(LENGTH(`post_content`) - LENGTH(REPLACE(`post_content`,' ',''))+1)
FROM `wp_posts`