Skip to content

Instantly share code, notes, and snippets.

<?php
/*
Plugin Name: MemberPress Account Page Nav
Plugin URI: http://www.memberpress.com/
Description: Allows developers to add more nav menu links/pages to their members account page
Version: 1.0.0
Author: Caseproof, LLC
Author URI: http://caseproof.com/
Copyright: 2004-2013, Caseproof, LLC
*/
@cartpauj
cartpauj / mepr-upme-activate.php
Last active March 15, 2018 00:59
MemberPress + UPME integration
<?php
/*
Plugin Name: MemberPress + UPME
Plugin URI: https://memberpress.com
Description: Activates UPME profiles when a user signs up via MemberPress.
Version: 1.0
Author: Caseproof, LLC
Author URI: http://caseproof.com/
Copyright: 2004-2014, Caseproof, LLC
*/
@cartpauj
cartpauj / memberpress-hide-password-fields.php
Last active March 23, 2020 14:24
Unset the password fields errors from MemberPress and auto-generate the user pass instead
<?php
//This file only unsets the errors
//You'll still need to override the app/views/checkout/form.php file to remove the password fields HTML
//You can find instructions on overriding template files here: https://www.memberpress.com/1.1.7
function unset_password_validation_errors($errors) {
if(empty($errors)) { return $errors; } //Should never happen if the password fields are hidden
//Unset the password field errors
// IF YOU'VE TRANSLATED THE PLUGIN - YOU MAY NEED TO CHANGE THESE ENGLISH TEXTS TO YOUR LANGUAGE
foreach($errors as $i => $v) {
@cartpauj
cartpauj / memberpress-display-name.php
Created November 16, 2015 17:59
Adds display name settings to MemberPress
<?php
/*
Plugin Name: MemberPress Display Name
Plugin URI: https://memberpress.com
Description: Adds a Display Name field to MemberPress signup and account pages
Version: 1.0
Author: Caseproof, LLC
Author URI: http://caseproof.com/
Copyright: 2004-2014, Caseproof, LLC
*/
@cartpauj
cartpauj / mepr-sub-actions.php
Created December 15, 2015 17:44
MemberPress Subscription Actions
<?php
// 1) User purchases and payment is complete
function capture_completed_transaction($txn) {
//It's possible this could be a recurring transaction for a product the user is already subscribed to so probably use a user meta field described below
$user = new MeprUser($txn->user_id); //A MeprUser object
$membership = new MeprProduct($txn->product_id); //A MeprProduct object
$users_memberships = $user->active_product_subscriptions('ids'); //An array of membership CPT ID's
//Here you may want to grab a user meta field of your own creating and check to see if the user is already subscribed to this membership or not
//If not, then push them to your 3rd party application and update the user meta field
@cartpauj
cartpauj / mepr-limit-signup-by-email-domain.php
Created December 21, 2015 18:43
Limit signups on a particular Membership by email domain
<?php
function ends_with($haystack, $needle = '.ac.uk') {
return (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
}
function check_email_domain($errors) {
$membership_id = 123; //Change this to reflect your Membership ID
if($membership_id != $_POST['mepr_product_id']) {
return $errors;
@cartpauj
cartpauj / website-field.php
Created February 5, 2016 18:58
Collect a website URL from users at signup in MemberPress. Allows you to store a different website URL with each user's subscription.
<?php
/*
Plugin Name: MemberPress Website Fields
Version: 1.0.0
Author: Caseproof, LLC
Author URI: http://caseproof.com
Description: Allow users to enter their website URL for each subscription they purchase
*/
//Signup form functions
@cartpauj
cartpauj / mepr-nua-approve-by-email-domain.php
Last active June 18, 2019 18:11
Using the New User Approve Plugin + MemberPress to allow filtered domains through
<?php
/*
Plugin Name: MemberPress + New User Approve
Version: 1.0.0
Author: Caseproof, LLC
Author URI: http://caseproof.com
Description: Helps the flow of signups from approved/unapproved domains between the MemberPress and New User Approve plugins
*/
function mepr_get_approved_domains() {
@cartpauj
cartpauj / mepr-custom-mailchimp-data.php
Created April 1, 2016 16:04
Custom code which can be used to send custom meta data to MailChimp
<?php //This code can be placed in a plugin like My Custom Functions (just omit this top line when copying)
function add_additional_mailchimp_usermeta($args, $contact, $list_id) {
$date = get_user_meta($contact->ID, 'mepr_some_date_field', true); //mepr_some_date_field SHOULD BE REPLACED WITH YOUR date field's slug
$args['merge_vars']['MMERGE_77'] = $date; //MMERGE_77 SHOULD BE REPLACED WITH YOUR SPECIFIC MERGE FIELD NAME
return $args;
}
add_filter('mepr-mailchimp-add-subscriber-args', 'add_additional_mailchimp_usermeta', 11, 3);
@cartpauj
cartpauj / mepr-limit-signups.php
Last active April 28, 2023 09:08
Limit # of signups on MemberPress memberships
<?php
//Sample code showing how to limit the total # of signups allowed on two different memberships
//Also some code at the bottom to show a custom message on the signup page when limit is reached
//Used to check if a signup limit has been reached for a particular membership
function has_reached_limit($membership_id, $limit) {
global $wpdb;
$query = "SELECT count(DISTINCT user_id)
FROM {$wpdb->prefix}mepr_transactions