Skip to content

Instantly share code, notes, and snippets.

@DumahX
DumahX / mpcs-breadcrumbs-classroom.php
Created July 26, 2022 13:00
Add breadcrumbs to Courses with Classroom Mode enabled
<?php
function add_course_breadcrumbs($content) {
global $post;
if(is_single()) {
if(isset($post) && is_a($post, 'WP_Post') && in_array($post->post_type, memberpress\courses\models\Lesson::lesson_cpts())) {
$current_lesson = new memberpress\courses\models\Lesson($post->ID);
$current_section = $current_lesson->section();
if($current_section !== false) {
@DumahX
DumahX / remove-duplicate-corp-accounts.php
Created July 25, 2022 13:50
Remove duplicate corporate accounts from the mpca_corporate_accounts table.
<?php
add_action('init', function() {
$users = MeprUser::all();
$ca_obj_ids = array();
$duplicates = array();
foreach($users as $user) {
$corporate_accounts = MPCA_Corporate_Account::get_all_by_user_id($user->ID);
@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
/*
INSTRUCTIONS FOR THIS CODE:
On your RSS URL in Aweber add &allow_aweber=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 Aweber through the content blocks.
*/
function allow_aweber_through($block, $post, $uri) {
if(isset($_GET['allow_aweber'])) {
<?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;
}