Skip to content

Instantly share code, notes, and snippets.

View supercleanse's full-sized avatar

Blair Williams supercleanse

View GitHub Profile
@supercleanse
supercleanse / expired_members_per_membership.sql
Created March 8, 2019 23:54
Retrieves a list of members who are expired on a given membership. Make sure to set the correct @membership_id on line 1
SET @membership_id = 10379;
SELECT um_first_name.meta_value AS first_name,
um_last_name.meta_value AS last_name,
u.user_email AS email,
l.lifetime_count,
t.expires_at AS expires_at
FROM wp_users AS u
LEFT JOIN wp_usermeta AS um_first_name
ON um_first_name.user_id = u.ID
AND um_first_name.meta_key = 'first_name'
@supercleanse
supercleanse / latest_expired_transaction.php
Created September 27, 2018 18:52
Find Latest Expired Transaction in MemberPress
<?php
function get_expired_subscription_urls_for_current_user() {
$expired_subscription_urls = array();
if(MeprUtils::is_user_logged_in()) {
$current_user = MeprUtils::get_currentuserinfo();
$all_subscriptions = $current_user->active_product_subscriptions('transactions', true, false);
if(!empty($all_subscriptions)) {
<?php
require './wp-load.php'; // only necessary if you run this script on the command line
$membership_id = 8888; // Change this to whatever your membership_id is
$m = new MeprProduct($membership_id);
$subscription_table = 'wp_mepr_subscriptions'; // change this to whatever your subscriptions table is named
$q = $wpdb->prepare("
SELECT s.id
@supercleanse
supercleanse / sub_account_manage_links.php
Created February 4, 2017 06:52
List Sub Account Management Links
@supercleanse
supercleanse / reset_password_link_gen.php
Created June 29, 2016 16:25
Generate a Reset Password Link with MemberPress
@supercleanse
supercleanse / email_template.php
Created August 19, 2015 19:57
The default email template for MemberPress
<html style="font: 13px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana, sans-serif; padding: 20px; position: relative; text-align: center; background-color: #efefef;">
<head>
<meta http-equiv="Content-Type" content="text/html;UTF-8" />
</head>
<body style="background-color: #efefef;">
<div id="header-pad" style="width: 680px; height: 5px; padding 0; margin: 0 auto; text-align: left;">
</div>
<?php echo $body; ?>
<div id="footer-pad" style="width: 680px; height: 50px; padding 0; margin: 0 auto; text-align: left;">
</div>
@supercleanse
supercleanse / create_my_pretty_link.php
Last active August 29, 2015 14:23
Creates a pretty link from a target url. Returns a pretty link url on success and false on failure.
@supercleanse
supercleanse / dynamic_trial_subscription.php
Created June 4, 2015 00:40
Dynamic Trial Subscription
<?php
/* This will alter the subscription so that the trial days will changed based on the date
* - it only works if a trial is enabled on the product/membership for the subscription
* but it will alter the number of days in the trial.
*/
$my_product_id = 4519;
$fixed_date = strtotime('2017-12-03 00:00:00');
add_filter('mepr-set-model-attribute-trial_days', 'override_trial_days');
function override_trial_days($value, $obj) {
@supercleanse
supercleanse / list_active_memberships.php
Created June 3, 2015 23:04
List Active Memberships
<h3>Active Subscriptions</h3>
<ul>
<?php
if($user = MeprUtils::get_currentuserinfo()) {
$active_products = $user->active_product_subscriptions('products');
foreach($active_products as $active_product) {
?>
<li><?php echo $active_product->post_title; ?></li>
<?php
@supercleanse
supercleanse / memberpress_count_by_user_and_product.php
Last active August 29, 2015 14:10
MemberPress Transaction Count for a given user & product
<?php
$mpdb = new MeprDb();
$count = $mpdb->get_count($mpdb->transactions, array(
'user_id'=>$txn->user_id,
'product_id'=>$txn->product_id,
'status'=>'complete'));