Skip to content

Instantly share code, notes, and snippets.

View ideadude's full-sized avatar

Jason Coleman ideadude

View GitHub Profile
@ideadude
ideadude / pmpro_nginx_restrict_docs.conf
Last active April 17, 2021 00:16
Locking down only PDF,DOC,DOCX,PPT,ZIP files with Paid Memberships Pro using NGINX
rewrite ^\/wp-content\/uploads\/(.*[\.pdf|\.doc|\.docx|\.ppt|\.zip])$ /wp-content/plugins/paid-memberships-pro/services/getfile.php last;
@ideadude
ideadude / pmpro_nginx.conf
Last active January 9, 2025 11:15
NGINX rule to lock down files with Paid Memberships Pro
rewrite ^/wp-content/uploads/(.*)$ /wp-content/plugins/paid-memberships-pro/services/getfile.php last;
@ideadude
ideadude / my_redirect_buddypress_registration_to_pmpro_levels.php
Created January 8, 2021 11:53
Redirect BuddyPress registration to the PMPro levels page.
<?php
/**
* Redirect BuddyPress registration to the PMPro levels page.
* Add this code into a Code Snippet or custom plugin.
* https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/
* Note that this gist will redirect users to the level pages.
* You can adjust it to link to checkout for a specific level
* or, if you have only one level, adjust it to link to the
* checkout page, which will default to the first available level.
*/
@ideadude
ideadude / pmpro-cancel-on-billing-failure.php
Last active February 2, 2021 11:20 — forked from strangerstudios/pmpro-cancel-on-billing-failure.php
Cancel PMPro subscriptions when a recurring payment fails.
<?php
/**
* Cancel subscriptions when a recurring payment fails.
* You should also use the PMPro Email Templates Add On to edit the
* default billing_failure.html email to mention that users are cancelled upon failure.
*/
function my_cancel_subscriptions_on_any_failed_payment( $order ) {
pmpro_cancelMembershipLevel( $order->membership_id, $order->user_id );
}
add_action( 'pmpro_subscription_payment_failed', 'my_cancel_subscriptions_on_any_failed_payment' );
@ideadude
ideadude / my_original_sub_order_col.php
Created October 26, 2020 18:57
Add a column to the PMPro orders table that shows the original subscription order.
<?php
/**
* Add a column to the PMPro orders table that shows the original subscription order.
* Requires PMPro 2.5+
* Add this code to a Code Snippet or custom plugin.
*/
function my_original_sub_order_col_header($order_ids) {
?>
<th>Original Order</th>
<?php
@ideadude
ideadude / my_redirect_away_from_docs.php
Last active October 27, 2020 23:49
Hide BuddyPress docs from members of some levels when using Paid Memberships Pro.
/**
* Hide docs from some levels.
* Make sure to adjust the pmpro_hasMembershipLevel check below
* to use the IDs of your levels which SHOULD have access to view members.
* Everyone else will be redirected to the restricted access or levels page.
*
* Copy this code into a custom plugin or Code Snippet.
*/
function my_redirect_away_from_docs() {
// Bail if PMPro and BuddyPress aren't active.
@ideadude
ideadude / my_redirect_away_from_member_pages.php
Created October 12, 2020 21:20
Hide individual BuddyPress member pages from members of some levels when using Paid Memberships Pro.
/**
* Hide individual member pages from some levels.
* Make sure to adjust the pmpro_hasMembershipLevel check below
* to use the IDs of your levels which SHOULD have access to view members.
* Everyone else will be redirected to the restricted access or levels page.
*
* Copy this code into a custom plugin or Code Snippet.
*/
function my_redirect_away_from_member_pages() {
// Bail if PMPro and BuddyPress aren't active.
@ideadude
ideadude / my_bp_activity_filter.php
Created October 12, 2020 20:31
Only let certain members post BuddyPress activity when using PMPro and PMPro BuddyPress.
/**
* Only let certain members post BuddyPress activity.
* This code works with BuddyPress and BuddyBoss.
* This code only filters the main activity page.
* Posting to groups you are a member of still works.
*
* Make sure BuddyPress (or BuddyBoss), PMPro, and PMPro BuddyPress are all active.
* Copy this code into a custom plugin or Code Snippet.
*/
@ideadude
ideadude / pmpro_ad_code.php
Created October 2, 2020 19:43
Some examples of showing AdSense code for certain members only.
<?php
// show ads to non-members and level 3
if( pmpro_hasMembershipLevel( array(0,3) ) ) {
?>
<script>//...</script>
<?php
}
// use the pmpro_displayAds function
// https://www.paidmembershipspro.com/documentation/content-controls/hide-ads/
@ideadude
ideadude / my_update_pmpro_stripe_statement_descriptor.php
Last active November 27, 2023 12:37
Change the statement descriptor for Stripe charges and subscriptions.
<?php
/**
* Change the statement descriptor for Stripe charges and subscriptions.
* This is the message shown on the customer's credit card statement.
* Must contain at least one letter, 22 characters max.
*
* Requires PMPro 2.4.1+
*
* Note: If your descriptor includes invalid characters or
* more than 22 chacters, checkout will fail.