Skip to content

Instantly share code, notes, and snippets.

@DumahX
DumahX / mepr-restrict-email-addresses.php
Created July 6, 2022 14:05
Restrict MemberPress signups by a member's email address.
<?php
add_filter('mepr-validate-signup', function($errors) {
/* Edit this to add or remove email addresses you'd like to block from registering.
For example, if you'd like to block members with the following email addresses:
- member@email.com
- anothermember@google.com
Then the code would look something like this: $email_addresses_to_block = ['member@email.com', 'anothermember@google.com'];
*/
$email_addresses_to_block = ['member@email.com'];
<?php
function check_duplicate_address_fields($errors) {
$mepr_options = MeprOptions::fetch();
$address_fields = array(
$_POST['mepr-address-one'],
$_POST['mepr-address-two'],
$_POST['mepr-address-city'],
$_POST['mepr-address-zip'],
<?php
add_shortcode('mepr-list-unsubscribed-memberships', function() {
$content = '';
$user = MeprUtils::get_currentuserinfo();
$memberships = MeprProduct::get_all();
$unsubscribed_memberships = array();
if(!$user) {
return $content;
<?php
add_shortcode('mpcs-unenrolled-courses', function() {
$unenrolled_courses = array();
$current_user = MeprUtils::get_currentuserinfo();
$mepr_user = new MeprUser($current_user->ID);
$courses = get_posts(array('post_type' => 'mpcs-course', 'post_status' => 'publish', 'posts_per_page' => '-1', 'orderby'=> 'title', 'order' => 'ASC'));
if(false == MeprUtils::is_logged_in_and_an_admin()) {
<?php
if(!defined('ABSPATH')) {die('You are not allowed to call this page directly.');}
/*
Integration of User Roles into MemberPress
*/
class MeprUserRoles {
public function __construct() {
add_action('mepr-txn-store', array($this, 'process_status_changes'));
add_action('mepr-txn-expired', array($this, 'process_status_changes'), 10, 2);
add_action('mepr_post_delete_transaction', array($this, 'process_destroy_txn'), 10, 3);
<?php
// Paste this into functions.php or a plugin like Code Snippets
function add_stripe_payment_args($args, $txn = false, $sub = false) {
if($txn) {
$user = $txn->user();
$args['metadata']['mepr_fatturazione_elettronica'] = get_user_meta($user->ID, 'mepr_fatturazione_elettronica', true);
}
return $args;
}
@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);