Skip to content

Instantly share code, notes, and snippets.

View mepr-restrict-email-domains.php
<?php
function mepr_restrict_email_domains($errors) {
# Allowed email domains.
$allowed_email_domains = array('gmail.com', 'hotmail.com');
$email_address = isset($_POST['user_email']) ? trim($_POST['user_email']) : '';
# Don't bother validating if the email is empty.
if(empty($email_address)) {
@DumahX
DumahX / mepr_validate_username_length.php
Created Dec 23, 2021
Check the member's username length.
View mepr_validate_username_length.php
<?php
function mepr_validate_username_length($errors) {
$username = isset($_POST['user_login']) ? trim($_POST['user_login']) : '';
# Don't bother validating username if isn't present.
if(!$username) {
return $errors;
}
View cleanup-abandoned-signups.php
<?php
function cleanup_abandoned_signups($event) {
$txn = $event->get_data();
$user = $txn->user();
// Count complete transactions and non-complete transactions
$user_incomplete_txns = $user->transactions('`status` != "complete"');
$user_complete_txns = $user->transactions('`status` = "complete"');
View revoke-trial-access.php
<?php
function subscription_stopped_func($event) {
$sub = $event->get_data();
$latest_txn = $sub->latest_txn();
if ($sub->in_trial() && $latest_txn) {
// Set transaction's expiration date to yesterday. Effectively revokes their membership access.
$latest_txn->expires_at = MeprUtils::ts_to_mysql_date(time() - MeprUtils::days(1));
$latest_txn->store();
View mepr-stripe-customer-extended-args.php
<?php
// Attach a phone number custom field when creating a Stripe Customer object.
// Replace mepr_phone_number with the actual slug of the phone number custom field in MemberPress.
function mepr_stripe_customer_extended_args($args, $user) {
$phone_number = trim(get_user_meta($user->ID, 'mepr_phone_number', true));
if(!empty($phone_number)) {
$args['phone'] = $phone_number;
}
View hidden-email-account-page.php
<?php if(!defined('ABSPATH')) {die('You are not allowed to call this page directly.');} ?>
<div class="mp_wrapper">
<?php if(!empty($welcome_message)): ?>
<div id="mepr-account-welcome-message">
<?php echo MeprHooks::apply_filters('mepr-account-welcome-message', do_shortcode($welcome_message), $mepr_current_user); ?>
</div>
<?php endif; ?>
<?php if( !empty($mepr_current_user->user_message) ): ?>
View mepr-validate-username.php
<?php
function mepr_validate_username($errors) {
$username = isset($_POST['user_login']) ? trim($_POST['user_login']) : '';
$first_name = isset($_POST['user_first_name']) ? trim($_POST['user_first_name']) : '';
$last_name = isset($_POST['user_last_name']) ? trim($_POST['user_last_name']) : '';
// If username is empty, don't run any validations.
if(empty($username)) {
return $errors;
View block-member-by-name.php
<?php
function block_member_by_name($errors) {
$first_name = isset($_POST['user_first_name']) && !empty($_POST['user_first_name']) ? trim($_POST['user_first_name']) : '';
$last_name = isset($_POST['user_last_name']) && !empty($_POST['user_last_name']) ? trim($_POST['user_last_name']) : '';
// If first or last name is empty, just don't do anything.
if(empty($first_name) || empty($last_name)) {
return $errors;
}
View allow-feed-through.php
<?php
/*
INSTRUCTIONS FOR THIS CODE:
On your RSS URL add &allow_feed=true to the end of it.
Then copy the below code and paste it into a plugin like My Custom Functions or Code Snippets on your site.
This will allow other plugins/sites to view the feed without the content blocks.
*/
function allow_feed_through($block, $post, $uri) {
if(isset($_GET['allow_feed'])) {
View courses-single-course.php
<?php
use memberpress\courses\helpers as helpers;
use memberpress\courses\models as models;
use memberpress\courses\controllers as controllers;
use memberpress\courses as base;
// Load header
echo helpers\Courses::get_classroom_header();
// Start the Loop.
while ( have_posts() ) :