Skip to content

Instantly share code, notes, and snippets.

@JPry
JPry / action-scheduler-create-action-page.php
Last active January 26, 2022 03:25
This plugin drops into the /wp-content/mu-plugins/ folder to add a page that creates a scheduled action for Action Scheduler.
<?php
/**
* Plugin Name: Add "Create Scheduled Action" page
* Plugin URI: https://gist.github.com/JPry/357ee26a46e3d8e2b68d1690f5bbbf75
* Description: Add a page to the Tools menu that allows for the manual creation of scheduled actions with Action
* Scheduler. Version: 1.0.0
* Author: Jeremy Pry
* Author URI: https://jeremypry.com/
* License: MIT
*/
@JPry
JPry / example-plugin.php
Created January 10, 2022 21:27
An example for including a JavaScript file into WordPress
<?php
/**
* Plugin Name: Example including a JS file into WordPress.
*/
add_action( 'wp_enqueue_scripts', 'jpry_example_include_scripts' );
function jpry_example_include_scripts() {
wp_enqueue_script(
'jpry-example-script', // This is an arbitrary name to reference this particular script
@JPry
JPry / jpry.php
Last active September 14, 2020 09:24
<?php
/**
* Plugin Name: JPry local tweaks.
* Plugin URI: https://gist.github.com/JPry/623fbbff1d008f783f2406711e4a6813
* Description: Local development tweaks. Place this in the mu-plugins directory.
* Version: 1.0
* Author: Jeremy Pry
* Author URI: http://jeremypry.com/
* License: MIT
*
@JPry
JPry / no_login_order_payment.php
Created June 20, 2019 23:47
Code snippet to allow customers to pay for an order without logging in.
<?php
/**
* Allow orders created by an admin to be paid without the user logging in.
*
* @param array $allcaps All capabilities of the user.
* @param array $caps Capabilities requested.
* @param array $args Extra Arguments.
*
@JPry
JPry / recurse-sync.sh
Created March 21, 2019 13:54
Look for any git repos in the current directory, and run `hub sync` in each one.
#!/usr/bin/env bash
set -e
# Ensure we have the `hub` command available.
if ! [[ -x "$(command -v hub)" ]]; then
echo "Error: 'hub' is required"
exit 1
fi
@JPry
JPry / wc-send-coupons-by-email.php
Last active February 1, 2019 15:38 — forked from woogists/wc-send-coupons-by-email.php
Send coupons used in an order by email
<?php
/**
* Send an email each time an order with coupon(s) is completed
*
* The email contains coupon(s) used during checkout process
*
* @param int $order_id The ID of the order.
*/
function jp_email_order_coupons( $order_id ) {
<?php
namespace JPry;
use JPry\Exception\InvalidField;
class Example {
/**
* Generate the sub-field objects for this field.
@JPry
JPry / limit_retries.php
Last active January 26, 2023 07:49
Limit WooCommerce Subscriptions to only 3 payment retries
<?php
add_filter( 'wcs_default_retry_rules', 'jpry_limit_3_retries' );
/**
* Limit the WooCommerce Subscriptions retry system to only 3 retries.
*
* This keeps the existing retry rules, but only the first 3. Everything thereafter
* is discarded.
*
<?php
add_action( 'woocommerce_customer_changed_subscription_to_cancelled', 'customer_skip_pending_cancellation' );
/**
* Change 'pending-cancel' status directly to 'cancelled'.
*
* @param WC_Subscription $subscription
*/
function customer_skip_pending_cancellation( $subscription ) {
@JPry
JPry / LocalValetDriver.php
Last active December 19, 2018 15:08
The purpose of these files is explained here: http://jeremypry.com/plugin-theme-development-wordpress-trunk/
<?php
// PR #237 broke Valet+ custom drivers, this is a workaround.
if ( ! class_exists( 'WordPressValetDriver' ) ) {
$driverPath = realpath( $_SERVER['HOME'] ) . '/.composer/vendor/weprovide/valet-plus/cli/drivers/WordPressValetDriver.php';
if ( ! is_readable( $driverPath ) ) {
throw new Exception( 'Unable to load the WordPress Valet Driver.' );
}
require_once $driverPath;