Skip to content

Instantly share code, notes, and snippets.

💭
Coding

Brent Shepherd thenbrent

💭
Coding
Block or report user

Report or block thenbrent

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@thenbrent
thenbrent / create-test-scheduled-actions.php
Last active Jul 18, 2019
Snippet to create scheduled actions with Action Scheduler via $_GET params.
View create-test-scheduled-actions.php
<?php
/**
* Check for $_GET params on admin pages and use them to create corresponding actions.
*
* Example URL string to append to any admin page: &as_add_actions=single&hook=my_action&time=1563420973
*/
function as_test_schedule_async_action() {
if ( ! isset( $_GET['as_add_actions'] ) ) {
return;
}
@thenbrent
thenbrent / wc-queue-docs.md
Last active Oct 10, 2018
WooCommerce 3.5 introduced a new scalable, traceable job queue. This queue can be leveraged by extensions for processing large sets of jobs in the background. The default handler can also be replaced for custom requirements.
View wc-queue-docs.md

Job Queue API

WooCommerce 3.5 introduced a new scalable, traceable job queue. This queue can be used by extensions and custom code to process large sets of jobs in the background, and track the lifecycle of those jobs. The default handler can also be replaced.

This guide explains how to use the queue APIs for adding jobs, and how to replace the default queue handler.

Jobs are Actions

For flexibility and simplicity, each job is defined by an action hook.

@thenbrent
thenbrent / enable-debug.php
Last active Sep 4, 2018
Mini-plugin to enable WP_DEBUG, WP_DEBUG_DISPLAY, & WP_DEBUG_LOG on a site where not FTP/SFTP access is available.
View enable-debug.php
<?php
/**
* Plugin Name: Enable WP_DEBUG
* Plugin URI: https://gist.github.com/thenbrent/d319cd9eaa88faea5cb69d296ea8ccc1
* Description: Enable WP_DEBUG, WP_DEBUG_DISPLAY, & WP_DEBUG_LOG on a site where not FTP/SFTP access is available.
* Author: Prospress Inc.
* Version: 1.0
* Author URI: http://prospress.com
*
* Copyright 2017 Prospress, Inc. (email : freedoms@prospress.com)
@thenbrent
thenbrent / test-date-default-timezone-set.php
Created Dec 7, 2016
Demonstrate impact of date_default_timezone_set()
View test-date-default-timezone-set.php
<?php
$date_string = '2015-11-13 09:59:00';
// Normal WordPress Way
date_default_timezone_set( 'UTC' );
$date_utc = new DateTime( $date_string );
// Rare Occassions
date_default_timezone_set( 'America/Los_Angeles' );
@thenbrent
thenbrent / wcs-mod-display.php
Created Oct 5, 2016
Prepend "With Failure" to subscriptions with the "on-hold" status and the last renewal order with the "failed" status.
View wcs-mod-display.php
<?php
/**
* Plugin Name: WooCommerce Subscriptions - Display Failed Status
* Plugin URI:
* Description: Prepend "With Failure" to subscriptions with the "on-hold" status and the last renewal order with the "failed" status.
* Author: Prospress Inc.
* Author URI: http://prospress.com/
* Version: 1.0
*
* Copyright 2016 Prospress, Inc. (email : freedoms@prospress.com)
@thenbrent
thenbrent / wcs-calculate-next-payment-from-last-payment.md
Last active Nov 16, 2016
By default, WooCommerce Subscriptions will calculate the next payment date for a subscription from the time of the last payment. This plugin changes that to preserve the original schedule and calculate the next payment date from the scheduled payment date, not the time the payment was actually processed. For example, without this plugin, the due…
View wcs-calculate-next-payment-from-last-payment.md

This gist has been migrated to a repo here.

@thenbrent
thenbrent / subscription-renewal-process.md
Created Aug 8, 2016
Brief developer's guide to the application flow during the subscription renewal process within WooCommerce Subscriptions
View subscription-renewal-process.md

WoCommerce Subscriptions processes automatic renewal payments via the following flow:

  1. its scheduling system, Action Scheduler, will run every minute and find any woocommerce_scheduled_subscription_payment actions scheduled to run now or within the last minute
  2. if there are woocommerce_scheduled_subscription_payment actions scheduled for anytime before now, Action Scheduler will grab a batch of those actions and begin processing them (which just means triggering do_action( 'scheduled_subscription_payment', $subscription_id ) for any 3rd party code to handle)
  3. Subscriptions attaches two important functions as callbacks on the 'woocommerce_scheduled_subscription_payment' hook to process renewal for that subscription when it is called:
    1. WC_Subscriptions_Manager::prepare_renewal(), which is responsible for
@thenbrent
thenbrent / bs-debugging-helpers.php
Last active Jun 7, 2017
A few handy functions for debugging PHP script execution in WordPress/WooCommerce.
View bs-debugging-helpers.php
<?php
/**
* Plugin Name: Brent's Debugging Helpers
* Plugin URI:
* Description: bs_backtrace() etc.
* Version: 8.13.21
* Author:
* Author URI:
*/
@thenbrent
thenbrent / _subscriptions.md
Last active Jun 29, 2018 — forked from mattallan/_subscriptions.md
WooCommerce Subscriptions REST API Endpoint Documentation (fork of https://gist.github.com/mattallan/fd52629eae293540c6d8)
View _subscriptions.md

Subscriptions

This section lists all API that can be used to create, edit or otherwise manipulate subscriptions.

Subscription Properties

Attribute Type Description
id integer Subscription ID (post ID) read-only
order_number integer Order number read-only
@thenbrent
thenbrent / wcs-test-retry-rules.php
Last active Jun 14, 2017
WooCommerce Subscriptions Failed Payment Retry Rules for Testing: Replace the default WooCommerce Subscriptions failed payment retry rules with rules that run every few minutes (not days) and always send dunning emails to help with testing.
View wcs-test-retry-rules.php
<?php
/**
* Plugin Name: WooCommerce Subscriptions Failed Payment Retry Rules for Testing
* Plugin URI:
* Description: Replace the default WooCommerce Subscriptions failed payment retry rules with rules that run every few minutes (not days) and always send dunning emails to help with testing.
* Author: Prospress Inc.
* Author URI: http://prospress.com/
* Version: 1.0
*
* Copyright 2016 Prospress, Inc. (email : freedoms@prospress.com)
You can’t perform that action at this time.