Skip to content

Instantly share code, notes, and snippets.

View LMNTL's full-sized avatar

Jessica Thomas LMNTL

  • Chicago, IL
View GitHub Profile
@LMNTL
LMNTL / pmpro-member-directory-page-number-in-title
Last active September 6, 2019 17:44
Add page numbers to page titles in Member Directory Add On for Paid Memberships Pro
<?php
/*
*/
function my_pmpro_add_directory_page_numbers($title){
global $post, $pmpro_pages;
$pn = 0;
if( isset($_REQUEST['pn'] ) )
{
$pn = sanitize_text_field( $_REQUEST['pn'] );
}
@LMNTL
LMNTL / pmpromh_modified_login_redirect.php
Last active September 4, 2019 22:17
preserve requested redirect with PMPro Member Homepages
// preserve requested redirect with PMPro Member Homepages
// forked from @greathmaster
function pmpromh_modified_login_redirect($redirect_to, $request, $user)
{
if(isset($request) && $redirect_to != admin_url())
return $request;
//check level
if(!empty($user) && !empty($user->ID) && function_exists('pmpro_getMembershipLevelForUser')) {
$level = pmpro_getMembershipLevelForUser($user->ID);
@LMNTL
LMNTL / custom_stylesheet.css
Created September 4, 2019 17:18
don't require the "State" field at checkout and hide it
.pmpro_checkout-field-bstate {
display: none;
}
@LMNTL
LMNTL / pmprozapier_email_after_change_level.php
Last active August 27, 2019 07:41
Send WP new user email and PMPro admin change email after registering a member through a PMPro Zapier zap
// send WP new user email and PMPro admin change email after registering a member through a PMPro Zapier zap
// requires Paid Memberships Pro and PMPro Zapier add on
function my_pmpro_zapier_email_after_change_level( $level_id, $user_id ){
if( isset( $_SERVER["REQUEST_URI"] ) && ( strpos( $_SERVER["REQUEST_URI"], "pmpro_zapier_webhook" ) !== false ) ){
$user = get_userdata( $user_id );
$pmpro_email = new PMProEmail();
$pmpro_email->sendAdminChangeEmail( $user );
wp_new_user_notification( $user_id, null, 'both' );
}
@LMNTL
LMNTL / my_pmpro_woocommerce_on_hold_keep_membership.php
Created August 23, 2019 00:02
don't cancel memberships when woocommerce orders go on hold
// don't cancel memberships when woocommerce orders go on hold
function my_pmpro_woocommerce_on_hold_keep_membership()
{
remove_action( 'woocommerce_subscription_status_on-hold', 'pmprowoo_cancelled_subscription', 10, 1 );
remove_action( 'woocommerce_subscription_status_on-hold_to_active', 'pmprowoo_activated_subscription', 10, 1 );
}
add_action('init', 'my_pmpro_woocommerce_on_hold_keep_membership');
@LMNTL
LMNTL / my_pmprowoo_on_hold_keep_startdate.php
Last active August 15, 2019 23:39
preserve start date when PMPro WooCommerce subscriptions go into "on hold" status
function my_pmprowoo_active_preserve_startdate( $level_id, $user_id )
{
global $wpdb;
if( $level_id != 0 && did_action( "woocommerce_subscription_status_active" ) )
{
$startdate = get_user_meta( $user_id, "pmprowoo_startdate_$level_id", true );
if( !empty($startdate) )
{
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->pmpro_memberships_users SET startdate = %s WHERE user_id = %d AND status = 'active'", $startdate, $user_id ) );
}
@LMNTL
LMNTL / my_pmpro_before_change_membership_level_customization.php
Created August 13, 2019 20:18
Change cancellation to set expiration date for next payment instead of cancelling immediately. (updated 8/13/19)
/*
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.
*** Updated 2018-11-16 to also check for calls from PayFlow Recurring Orders Add On
*/
//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_customization($level_id, $user_id) {
global $pmpro_pages, $wpdb, $pmpro_stripe_event, $pmpro_next_payment_timestamp, $cancelling;
// Is this being called from the PayFlow Recurring Orders Add On?
@LMNTL
LMNTL / my_pmproship_remove_email_filter.php
Created August 12, 2019 17:41
Remove shipping address from PMPro-generated emails when using Shipping Add On
// Remove shipping address from PMPro-generated emails when using Shipping Add On
function my_pmproship_remove_email_filter()
{
remove_filter( "pmpro_email_body", "pmproship_pmpro_email_body", 10, 2 );
}
add_action( "init", "my_pmproship_remove_email_filter");
@LMNTL
LMNTL / pay-by-check-no-access.php
Last active July 26, 2019 20:52 — forked from andrewlimaza/pay-by-check-no-access.php
Force users with pending orders from Pay By Check Add On and PMPro to not have access to any member content.
<?php
/**
* This checks to see if the user has a 'pending' check order and will deny access whever member content is called.
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function pmpro_deny_if_user_is_pending( $hasaccess, $post, $user, $levels ) {
$order = new MemberOrder();
$order->getLastMemberOrder( $user->ID, array( 'pending', '', 'check' ) );
@LMNTL
LMNTL / my_pmpromd_profile_preheader.php
Created July 22, 2019 18:44
show a 404 page when trying to access a profile page for members with "Hide from Directory?" checked and/or don't have a specific level
//show a 404 page when trying to access a profile page for members with "Hide from Directory?" checked and/or don't have a specific level
function my_pmpromd_profile_preheader()
{
// -------- Edit this line to determine which levels get profile pages ---------- //
$directory_levels = array(1, 2, 3);
global $post, $pmpro_pages, $current_user, $wp_query;
if(!empty($post->ID) && $post->ID == $pmpro_pages['profile'])
{
//Get the profile user