This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function maybe_exclude_protected_posts($query) { | |
if(!$query->is_admin && $query->is_search && $query->is_main_query()) { | |
$posts_to_exclude = array(); | |
$posts = get_posts(array('numberposts' => -1)); | |
foreach($posts as $post) { | |
if(MeprRule::is_locked($post)) { | |
$posts_to_exclude[] = $post->ID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'])) { |