Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
strangerstudios / gist:3100680
Created July 12, 2012 20:18
Hidden Levels for Paid Memberships Pro
<?php
/*
Plugin Name: PMPro Hidden Levels
Plugin URI: http://www.paidmembershipspro.com/pmpro-hidden-levels/
Description: With this plugin, select levels are removed from the levels page but still available for checkout if you visit the checkout URL directly.
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
@strangerstudios
strangerstudios / pmpro-disable-all-emails.php
Created September 7, 2012 16:24
Disable All PMPro Emails
<?php
/*
Plugin Name: PMPro Disable All Emails
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-disable-all-emails/
Description: Disable All PMPro Emails
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
Add this file to your /wp-content/plugins/ folder and then activate it from the Plugins page in your WP admin.
@strangerstudios
strangerstudios / gist:5573829
Last active April 16, 2021 23:43
Paid Memberships Pro customization to only let members of a certain level checkout if a discount code was used.
/*
Only let level 1 members sign up if they use a discount code.
Place this code in your active theme's functions.php or a custom plugin.
*/
function my_pmpro_registration_checks_require_code_to_register($pmpro_continue_registration)
{
//only bother if things are okay so far
if(!$pmpro_continue_registration)
return $pmpro_continue_registration;
@strangerstudios
strangerstudios / pmpro_cancelled_level.php
Last active May 12, 2021 22:05
Place a PMPro member in another level when they cancel.
/*
When users cancel (are changed to membership level 0) we give them another "cancelled" level. Can be used to downgrade someone to a free level when they cancel.
*/
function pmpro_after_change_membership_level_default_level($level_id, $user_id)
{
//if we see this global set, then another gist is planning to give the user their level back
global $pmpro_next_payment_timestamp;
if(!empty($pmpro_next_payment_timestamp))
return;
@strangerstudios
strangerstudios / pmpro_cancel_on_next_payments_date.php
Last active May 20, 2021 11:17
Change PMPro membership cancellation to set expiration date for next payment instead of cancelling immediately.
/*
Change cancellation to set expiration date for next payment instead of cancelling immediately.
Assumes orders are generated for each payment (i.e. your webhooks/etc are setup correctly).
Since 2015-09-21 and PMPro v1.8.5.6 contains code to look up next payment dates via Stripe and PayPal Express APIs.
*/
//before cancelling, save the next_payment_timestamp to a global for later use. (Requires PMPro 1.8.5.6 or higher.)
function my_pmpro_before_change_membership_level($level_id, $user_id) {
//are we on the cancel page?
@strangerstudios
strangerstudios / my_pmpro_checkout_level_extend_memberships.php
Last active October 12, 2022 11:39
By default PMPro will only "extend" a membership level if you checkout for the same level. This code will make it so PMPro extends any expiring level with any new expiring level. E.g. if you change from a annual plan to a monthly plan it will add 30 days to the end of your existing membership.
<?php
/*
If checking out for ANY level with an expiration, add remaining days to the enddate.
Pulled in from: https://gist.github.com/3678054
*/
function my_pmpro_checkout_level_extend_memberships($level)
{
global $pmpro_msg, $pmpro_msgt, $current_user;
//does this level expire? are they an existing members with an expiration date?
@strangerstudios
strangerstudios / my_pmpro_registration_checks.php
Created January 25, 2014 18:17
Don't let existing members downgrade example.
/*
Don't let exisisting members checkout for free level.
*/
function my_pmpro_registration_checks($okay)
{
//only check if things are okay so far
if($okay)
{
global $pmpro_level;
@strangerstudios
strangerstudios / my_pmpro_has_membership_access_filter.php
Created January 25, 2014 18:49
Filter pmpro_has_membership_access so paid members have access to all addon packages, but free members must pay the per post price. Edit the $my_paid_level_ids array to include an array of your paid level ids. Put this code in your active theme's functions.php or a custom WordPress plugin.
<?php
/*
Filter pmpro_has_membership_access based on paid membership access.
*/
function my_pmpro_has_membership_access_filter( $hasaccess, $mypost, $myuser, $post_membership_levels ) {
$my_paid_level_ids = array(5,6,7);
// Check if the user doesn't have access
if( ! $hasaccess ) {
// If this post has membership levels associated with it and is supposed to be locked by the Addon Plugin
@strangerstudios
strangerstudios / pmpro_after_change_membership_level_default_level.php
Last active April 7, 2022 20:32
Place a PMPro member in another level when they cancel... unless they are cancelling from that level.
/*
When users cancel (are changed to membership level 0) we give them another "cancelled" level.
Can be used to downgrade someone to a free level when they cancel.
Will allow members to the "cancel level" to cancel from that though.
*/
function my_pmpro_after_change_membership_level_default_level($level_id, $user_id)
{
//set this to the id of the level you want to give members when they cancel
$cancel_level_id = 1;
@strangerstudios
strangerstudios / pmprobuddy_update_user_meta.php
Last active October 18, 2022 20:48
Sync WordPress user meta fields (e.g. those added by PMPro Register Helper) with BuddyPress profile fields.
/*
Sync PMPro fields to BuddyPress profile fields.
*/
function pmprobuddy_update_user_meta($meta_id, $object_id, $meta_key, $meta_value)
{
//make sure buddypress is loaded
do_action('bp_init');
//array of user meta to mirror
$um = array(