Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / my_get_rh_option_label.php
Created April 5, 2021 19:24
Look up the label of an option for a PMPro Register Helper field.
<?php
/**
* Look up the label of an option for a Register Helper field.
* @param $field_name The name of the field (user meta key)
* @param $option_key The key of the option in the fields options array.
* @returns The label for the field or "N/A" if none found.
*/
function my_get_rh_option_label( $field_name, $option_key ) {
global $pmprorh_registration_fields;
@ideadude
ideadude / my_sort_bp_members_list.php
Created April 5, 2021 15:24
Sort BuddyPress members by PMPro membership level.
/**
* Sort BuddyPress members by PMPro membership level.
* Add this code as a code snippet or in a custom plugin.
* https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
*/
function my_sort_bp_members_list( $query ) {
global $wpdb;
$query->uid_clauses['select'] .= " LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.user_id = mu.user_id AND mu.status = 'active' ";
$query->uid_clauses['orderby'] = str_replace( 'ORDER BY', 'ORDER BY mu.membership_id DESC, ', $query->uid_clauses['orderby'] );
}
@ideadude
ideadude / my_fix_billing_amount.php
Created April 2, 2021 17:21
Fix the billing amount shown on a user's account with Paid Memberships Pro
<?php
/**
* Change the billing amount and cycle number/period for a user's active membership.
* This is useful if the number is out of alignment with the gateway.
* Change the variables under "change this stuff"
* Then visit /wp-admin/?my_fix_billing_amount=1 as an admin.
* Deactivate this snippet after running.
*/
function my_fix_billing_amount() {
global $wpdb;
@ideadude
ideadude / my_keep_free_members_in_old_members_list.php
Created March 30, 2021 20:29
Keep "old" members who expired or cancelled in the old members lists even if they have a free level now. Paid Memberships Pro.
<?php
/**
* When PMPro users cancel or expire, they are shown on the
* cancelled, expired, and "old" members lists.
* However, if an old user is given a default/free level later,
* then they are not considered old, cancelled, or expired anymore.
*
* You may still want to see those users on the old users lists
* so you can follow up to get them back into paid accounts.
* This code does that.
@ideadude
ideadude / pmpro_roles_exclude_other_pmpro_roles.php
Created March 23, 2021 15:02
Allow admins to set multiple PMPro level roles to one level when using PMPro and the PMPro Roles Add On.
add_filter( 'pmpro_roles_exclude_other_pmpro_roles', '__return_false' );
@ideadude
ideadude / my_pmpro_email_confirmation_text.php
Created March 23, 2021 14:04
Change the confirmation text when using PMPro and the Email Confirmation Add On.
/**
* Change the "IMPORTANT!" confirmation text when using PMPro and the Email Confirmation Add On.
* Add this code into a custom plugin or code snippet.
* Be sure to change the translated lines below to the language and words you want.
* https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
*/
function my_pmpro_email_confirmation_text( $translated_text, $text, $domain ) {
// Ignore strings for other plugins.
if ( $domain != 'pmpro-email-confirmation' ) {
return $translated_text;
@ideadude
ideadude / my_pmpro_page_templates.php
Created March 22, 2021 19:20
Load your own templates for Paid Memberships Pro using a custom plugin.
/**
* Include this code in your custom WordPress plugin
* to load your own versions of the PMPro page templates.
* To override the cancel.php template, place your own
* cancel.php template in a folder like this:
* ../plugins/yourpluginslug/templates/cancel.php
*
* Using priority 100 will make sure this runs after
* other code using the smae hook. For example,
* it will run later than the Reason for Cancelling Add On
@ideadude
ideadude / init_test_braintree_webhook.php
Created March 5, 2021 16:36
Testing the PMPro Braintree using the signature and payload from a webhook log.
<?php
/**
* Add this function into a customizations plugin
* and then visit yoursite.com/wp-admin/?test_braintree_webhook=1 from a browser.
*/
function init_test_braintree_webhook() {
if(!empty($_REQUEST['test_braintree_webhook'])) {
define('PMPRO_BRAINTREE_WEBHOOK_DEBUG', true);
$_POST['bt_signature'] = 'putthesignaturefromthewebhookloghere';
@ideadude
ideadude / pmpro-australia-gst.php
Last active January 19, 2023 09:27 — forked from strangerstudios/pmpro-australia-gst.php
Paid Memberships Pro - Australia GST
<?php
/*
Plugin Name: Paid Memberships Pro - Australia GST
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-australia-gst/
Description: Apply Australia GST to Checkouts with PMPro
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
/*
@ideadude
ideadude / my_show_member_badge_in_bbpress_replies.php
Created January 19, 2021 21:17
Display a member's badge in bbPress replies when using Paid Memberships Pro and the Member Badges Add On.
<?php
/**
* Display a member's badge on replies.
* Requires the Member Badge Add On https://www.paidmembershipspro.com/add-ons/member-badges/
* Add this code to a Code Snippet or custom plugin.
* https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
*/
function my_show_member_badge_in_bbpress_replies() {
// Make sure pmpro and bbpress are active.
if ( ! defined( 'PMPRO_VERSION' ) || ! class_exists( 'bbPress' ) ) {