Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / membership_shortcode_examples.txt
Created January 16, 2019 20:16
Examples of the PMPro [membership] shortcode.
[membership level="0"]
<!--this is shown to non-members and non-logged in visitors-->
[pmpro_advanced_levels levels="1,2,3" layout="3col"]
[/membership]
[membership level="1,2"]
[pmpro_advanced_levels levels="2,3" layout="2col"]
<!--this is shown to Level 1 and 2 Members-->
[/membership]
[membership level="3"]
[pmpro_advanced_levels levels="4"]
@ideadude
ideadude / my_add_select2_to_discount_code_filter_on_orders_page.php
Last active January 16, 2019 16:18
Turn Discount Code dropdown on the PMPro orders list to a select2 field.
/**
* Turn Discount Code dropdown on orders list to a select2 field.
* Add this code to a custom plugin. https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_add_select2_to_discount_code_filter_on_orders_page() {
if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'pmpro-orders' ) {
wp_enqueue_style( 'select2', plugins_url( 'css/select2.css', __FILE__ ), '', '4.0.6', 'screen' );
wp_enqueue_script( 'select2', plugins_url( 'js/select2.js', __FILE__ ), array( 'jquery' ), '4.0.6' );
function my_add_select2_inline_script() {
@ideadude
ideadude / discount_code_search_for_pmpro_members_list.php
Created January 16, 2019 15:59
Update PMPro member and order searches to also search by discount code.
/**
* Update member and order searches to also search by discount code.
*
* I'm not recommending anyone actually use this, but sharing as an example.
*
* This is a little hacky how the members list SQL is edited.
* You get odd results if you change the level or other parameters
* on the members list table and also search for an order.
* Can also act wonky if you have overlaps between your discount code names
* and cities, user names, names, or anything else that would normally
@ideadude
ideadude / update_pmpro_db_decimals.sql
Last active January 9, 2019 11:44
Update decimal fields in the PMPro database tables to support more decimals, e.g. Bitcoin
# Avoid errors in MySQL 5.7
UPDATE wp_pmpro_memberships_users SET enddate = NULL WHERE CAST(enddate AS CHAR(20)) = '0000-00-00 00:00:00';
# Fix membership_levels table
ALTER TABLE `wp_pmpro_membership_levels` MODIFY `initial_payment` decimal(18,8);
ALTER TABLE `wp_pmpro_membership_levels` MODIFY `billing_amount` decimal(18,8);
ALTER TABLE `wp_pmpro_membership_levels` MODIFY `trial_amount` decimal(18,8);
# Fix memberships_users table
ALTER TABLE `wp_pmpro_memberships_users` MODIFY `initial_payment` decimal(18,8);
@ideadude
ideadude / test_braintree_webhook.php
Last active March 5, 2021 16:37
Testing the Braintree Webhook with PMPro v2.0+
<?php
/**
* Add this function into a customizations plugin
* and then visit /?test_braintree_webhook from a browser.
*/
function init_test_braintree_webhook() {
if(!empty($_REQUEST['test_braintree_webhook'])) {
define('PMPRO_BRAINTREE_WEBHOOK_DEBUG', true);
$gateway = new PMProGateway_braintree();
@ideadude
ideadude / test_set_expiration_dates.php
Last active February 22, 2023 18:56
Testing the pmprosed_fixDate() function of PMPro Set Expiration Dates
/**
* Testing the pmprosed_fixDate function.
* 1. Make sure PMPro and PMPro Set Expiration Dates is active.
* 2. Add this code to a custom plugin.
* 3. Visit ?test_date_functions=1 to a URL
* 4. Remember to remove the code when done.
*/
function test_set_expiration_dates() {
if( empty( $_REQUEST['test_date_functions'] ) ) {
return;
@ideadude
ideadude / my_disable_stripe_api_next_payment_date.php
Created December 12, 2018 17:22
Keep pmpro_next_payment_date() from using the Stripe API.
/**
* Keep pmpro_next_payment_date() from using the Stripe API.
* Instead, the next payment date will be calculated based on
* the date of the last order in PMPro.
* This will be inaccurate in some cases with regards to trials,
* but avoids issues where Stripe is giving the wrong "next payment"
* date when payments fail.
*/
function my_disable_stripe_api_next_payment_date( $next_payment_date ) {
// remove this filter which may run later
@ideadude
ideadude / pmpro-register-helper-fields.php
Last active April 7, 2021 03:53
Who referred you to our site? field for PMPro Register Helper
<?php
/*
Plugin Name: Paid Memberships Pro - Custom Register Helper Fields
Plugin URI: https://www.paidmembershipspro.com/documentation/register-helper-documentation/code-examples/
Description: Register Helper Fields
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
//we have to put everything in a function called on init, so we are sure Register Helper is loaded
@ideadude
ideadude / pmpro_check_for_deprecated_plugins.php
Created December 6, 2018 21:46
A general purpose check for deprecated add ons.
/**
* Check for merged plugins that should be deactivated.
*/
function pmpro_check_for_deprecated_plugins() {
$pmpro_deprecated_plugins = array(
'pmpro-better-logins-report/pmpro-better-logins-report.php' => 'Better Logins Report',
);
$plugins_to_deactivate = array();
foreach( $pmpro_deprecated_plugins as $plugin_path => $plugin_name ) {
@ideadude
ideadude / override_pricing_fields_on_sitewide_sales_pages.php
Last active November 5, 2018 12:32
Hide the PMPro pricing box at checkout using the new pmpro_include_pricing_fields filter.
/**
* Hide the PMPro pricing box at checkout
* and replace with our own.
*
* Require PMPro v1.9.5.6+ and PMPro Sitewide Sales v1.0+
* Add this into a custom plugin.
*/
function override_pricing_fields_on_sitewide_sales_pages( $include_pricing_fields ) {
global $wpdb, $pmpro_level;