Skip to content

Instantly share code, notes, and snippets.

@cartpauj
cartpauj / mepr-force-first-name-display-name.php
Created April 3, 2017 18:34
Force a user's first name to be their WordPress display name (for MemberPress Users)
<?php
// ---------------------------------------------
// FORCE THE DISPLAY_NAME USER VARIABLE TO BE THEIR FIRST NAME
// ---------------------------------------------
function rol_set_display_name( $display_name ) {
// New user via WP Admin > Users > Add New
// Edit user's name via WP Admin > Users > edit user
// Edit user's name via WP Admin > MemberPress > Members > edit user
if ( isset( $_POST['first_name'] ) ) {
@cartpauj
cartpauj / mepr-plus-invisible-recaptcha.php
Created April 4, 2017 16:19
MemberPress + Invisible Recaptcha plugin integration (untested)
<?php
//Integrates MemberPress with https://wordpress.org/plugins/invisible-recaptcha/
//This is untested code ATM
function add_invisible_recaptcha_mepr_signup($membership_ID) {
?>
<div class="mp-form-row mepr_invisible_recaptcha">
<?php do_action('google_invre_render_widget_action'); ?>
</div>
<?php
}
@cartpauj
cartpauj / affiliate-royale-memberpress-tracking-on-separate-domains.php
Created August 9, 2017 18:35
How to track commissions from MemberPress when Affiliate Royale is on a separate domain then MemberPress.
<?php // Set up a custom page template in your theme, and choose that template for your MemberPress thank-you page. The following should be in that template.
if(isset($_GET['trans_num']) && ($txn = MeprTransaction::get_one_by_trans_num($_GET['trans_num']))):
?>
<img src="http://AFFILIATE-SITE.com/index.php?plugin=wafp&controller=transactions&action=track&amount=<?php echo $txn->amount; ?>&order_id=<?php echo $txn->id; ?>&prod_id=<?php echo $txn->product_id; ?>" width="1px" height="1px" style="display: none;" />
<?php endif; ?>
@cartpauj
cartpauj / pretty-link-stats-by-group.sql
Created August 9, 2017 21:45
Pretty Link stats by Groups - QUERY
@cartpauj
cartpauj / mepr-user-pro-profile-visibility.php
Last active June 21, 2019 17:23
UserPro hide or show profile based on subscription status
<?php
function mepr_sync_user_pro_visibility($txn, $status = false) {
global $userpro;
if(class_exists('MeprUser')) {
$user = new MeprUser($txn->user_id);
//Make sure it's a valid user still
if(!isset($user->ID) || !$user->ID) { return; }
@cartpauj
cartpauj / override_gateway_desc.php
Created December 18, 2017 22:42
Override Offline Gateway Description in MemberPress
<?php
//PASTE THE CODE BELOW THIS LINE INTO A PLUGIN LIKE My Custom Functions
function update_offline_desc($desc, $obj, $first) {
if(strpos($desc, 'offline')) {
//Use double quotes in your message, do not use any single quotes in your message.
$desc = 'PUT YOUR OWN MESSAGE IN HERE';
}
return $desc;
}
@cartpauj
cartpauj / disable-sub-account-reminders.php
Created December 20, 2017 21:42
Disable Reminder Emails for Sub Accounts in MemberPress Corporate Accounts
<?php
function disable_reminders_for_sub_accounts($disable_email, $reminder, $usr, $prd) {
global $wpdb;
$q = "SELECT COUNT(*) FROM {$wpdb->prefix}mepr_corporate_accounts WHERE user_id = {$usr->ID}";
$count = $wpdb->get_var($q);
if(!$count) {
$disable_email = true;
}
@cartpauj
cartpauj / ajax-request-memberpress-developer-tools-rest-api-json.html
Created March 6, 2018 20:06
Sample jQuery JSON REST API - MemberPress Developer Tools - Basic Authentication
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Access</title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
var settings = {
async: true,
@cartpauj
cartpauj / mepr-active-memberships.php
Created March 7, 2018 15:51
Get a list of the current user's active MemberPress Subscriptions
<?php
if(class_exists('MeprUtils')) {
$user = MeprUtils::get_currentuserinfo();
if($user !== false && isset($user->ID)) {
//Returns an array of Membership ID's that the current user is active on
//Can also use 'products' or 'transactions' as the argument type
$active_prodcuts = $user->active_product_subscriptions('ids');
if(!empty($active_prodcuts)) {
@cartpauj
cartpauj / memberpress-hooks.php
Last active July 20, 2023 17:46
Various Subscription and Transaction status hooks for MemberPress with some helpful comments
<?php
//Capture a new member signup. Only ever triggers once for each new member.
//Does not trigger for exising members who have subscribed to a Membership before.
//
//The user may not be logged in when this is called
//as it is triggered when a user is added over the REST API,
//and also when a user is added from the dashboard (MemberPress -> Members -> Add New)
function mepr_capture_new_member_signup_completed($event) {
$user = $event->get_data();
$txn_data = json_decode($event->args);