Skip to content

Instantly share code, notes, and snippets.

@DumahX
DumahX / bbpress-role.php
Created April 19, 2022 18:13
Add custom bbPress role
<?php
function add_custom_role( $bbp_roles ) {
$bbp_roles['basic_member_role'] = array(
'name' => 'Basic Member',
'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() ) // the same capabilities as participants
);
return $bbp_roles;
}
@DumahX
DumahX / avada-builder-workaround.php
Last active April 15, 2022 19:34
Workaround for protecting posts using Avada Builder
<?php
add_action('avada_after_content', function() {
global $post;
if(class_exists('MeprRule') && MeprRule::is_locked($post)) {
$unauth_message = (class_exists('MeprRulesCtrl') ? MeprRulesCtrl::unauthorized_message($post) : '');
echo do_shortcode($unauth_message);
?>
<script>
<?php
function add_optin_status($user) {
if(isset($_POST['meprconvertkit_opt_in'])) {
update_user_meta($user->ID, 'mepr_convertkit_optin_status', true);
} else {
update_user_meta($user->ID, 'mepr_convertkit_optin_status', false);
}
}
add_action('mepr-signup-user-loaded', 'add_optin_status', 11);
<?php
function mepr_validate_emails_signup($errors) {
$allowed_words = array('university'); // ADD ALLOWED WORDS HERE SEPARATED BY COMMAS.
$email = isset($_POST['user_email']) ? trim($_POST['user_email']) : '';
$is_allowed = false;
// If email is empty for some reason or the membership shouldn't be validated, then just don't do anything.
if($_POST['mepr_product_id'] != 123 || empty($email)) {
return $errors;
<?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 December 23, 2021 17:17
Check the member's username length.
<?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;
}
<?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"');
<?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();
<?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;
}
<?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) ): ?>