Skip to content

Instantly share code, notes, and snippets.

View thenbrent's full-sized avatar

Brent Shepherd thenbrent

View GitHub Profile
@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:1075369
Created July 11, 2011 06:09
PayPal Recurring Payment NVP API Request Parameters
As found here: http://sandbox.angelleye.com/temp/sample-set.php
SetExpressCheckout Request
[USER] => xxxx
[PWD] => xxx
[SIGNATURE] => xxx
[VERSION] => 57.0
[BUTTONSOURCE] => AngellFreeInc_USBSwiper_EC_US
[METHOD] => SetExpressCheckout
@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:1625033
Created January 17, 2012 05:43
WordPress Custom Post Type Message
/**
* Replaces "Post" in the update messages for custom post types on the "Edit" post screen.
*
* For example, for a "Product" custom post type, "Post updated. View Post." becomes "Product updated. View Product".
*
* @param array $messages The default WordPress messages.
*/
function pico_custom_update_messages( $messages ) {
global $post, $post_ID;
@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 / debug_backtrace.php
Last active September 14, 2016 15:07
PHP Stacktrace to `error_log()` using `debug_backtrace()`.
<?php
foreach ( debug_backtrace() as $key => $value ) {
$function = @$value['function'];
if( isset( $value['class'] ) )
$function = $value['class'] . '::' . $function;
//error_log( "** " . $key . ". " . $function . "( " . str_replace( array("\n","\t",' ','(',')'), '', print_r( $value['args'], true ) ) . " )" );
@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`
@thenbrent
thenbrent / example-paypal-ipn-payloads.txt
Last active February 8, 2023 07:04
PayPal Standard & Express Checkout Subscription Related IPN Messages (from Sandbox)
-------------------------------------
PayPal Standard Subscription Sign-up
-------------------------------------
[txn_type] => subscr_signup
[subscr_id] => I-NARPL1C0KAHA
[last_name] => User
[residence_country] => US
[mc_currency] => AUD
[item_name] => Digital Subscription