Skip to content

Instantly share code, notes, and snippets.

View cartpauj's full-sized avatar

Paul cartpauj

View GitHub Profile
@cartpauj
cartpauj / mepr-show-account-nav-shortcode.php
Last active February 29, 2024 02:27
Shortcode to show MemberPress Account page navigation menu on any page
<?php
//
// PASTE SHORTCODE [mepr-account-nav-menu] after adding this snippet to your site
// Use Code Snippets plugin (run snippet only on front end)
// https://wordpress.org/plugins/code-snippets/
//
function mepr_show_nav_menu() {
if(!class_exists('MeprAccountCtrl')) { return; }
$mepr_options = MeprOptions::fetch();
@cartpauj
cartpauj / replace-admin-email-password-changed-email-memberpress.php
Created November 10, 2020 20:16
Replace admin email in password change email - MemberPress
<?php
// Replace admin email in password changed email
// We can replace all message or other params like
// ###USERNAME### or ###SITENAME### this way
add_filter('password_change_email', 'replace_admin_email_in_pass_email', 10, 3);
function replace_admin_email_in_pass_email($pass_change_email, $user, $userdata) {
$pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', '[email protected]', $pass_change_email['message'] );
return $pass_change_email;
}
@cartpauj
cartpauj / mepr-validate-adult-age.php
Created November 10, 2020 20:13
Validate age (18+) with MemberPress registration forms
<?php
// Validate if user is over 18 years old
add_filter('mepr-validate-signup', 'validate_birthday_input');
function validate_birthday_input($errors) {
$slug = 'mepr_birthday'; // CHANGE THIS TO MATCH THE SLUG OF YOUR BIRTHDAY FIELD
if(is_user_logged_in()) { return $errors; }
$then = strtotime($_POST[$slug]);
@cartpauj
cartpauj / change-courses-per-page-memberpress-courses.php
Created November 10, 2020 18:43
Change number of courses per page on Classroom page
<?php
// Change number of courses per page on Classroom page
function num_posts_course_archive($query){
if ($query->is_archive('mpcs_course')) {
$query->set('posts_per_page', 10);
}
return $query;
}
add_filter('pre_get_posts', 'num_posts_course_archive');
@cartpauj
cartpauj / mepr-membership-price-shortcode.php
Last active December 17, 2025 16:49
Add shortcode for displaying membership price
<?php
// Add shortcode for displaying membership price. We can use it like this: [membership_price id="123"] where id is membership ID
function display_membership_price($atts, $content) {
if(!isset($atts['id'])) { return; }
$mepr_options = MeprOptions::fetch();
return $mepr_options->currency_code_str . get_post_meta($atts['id'], '_mepr_product_price', true);
}
add_shortcode('membership_price', 'display_membership_price');
@cartpauj
cartpauj / mepr-stop-23-59-59-utc-expires-at.php
Last active July 30, 2024 22:50
Stop MemberPress from setting transaction expires dates to 23:59:59 UTC+0
<?php
// This will set the expires at hour, minute, second to the same hour, minute, second when the user joined.
function update_txn_expires_at($txn, $old_txn = false) {
global $wpdb;
if(!isset($txn->id) || (int)$txn->id <=0 || $txn->expires_at == '0000-00-00 00:00:00') { return; }
$expires_at_ts = strtotime($txn->expires_at);
$created_at_ts = strtotime($txn->created_at);
@cartpauj
cartpauj / mepr-capture-payments.php
Created October 6, 2020 15:37
Payments and Refunds in MemberPress
<?php
function capture_mepr_payments($txn) {
if($txn->status == MeprTransaction::$confirmed_str) {
$sub = $txn->subscription(); // Get subscription object (if any) MeprSubscription
if(isset($sub->id) && $sub->id > 0) {
if($sub->trial && $sub->trial_amount <= 0.00) {
// Subscription has a free trial period defined by $sub->trial_days
}
else {
@cartpauj
cartpauj / mepr-mandatory-coupon.php
Created September 29, 2020 13:39
Mandatory Coupon Field in MemberPress
<?php
//Copy lines below this, and paste into a "Run Everywhere" Snippet type in the Code Snippets plugin.
function make_coupon_mandatory($errors) {
if(!isset($_POST['mepr_coupon_code']) || $_POST['mepr_coupon_code'] === '') {
$errors[] = 'Sorry, coupon code is mandatory field.';
}
return $errors;
}
add_filter('mepr-validate-signup', 'make_coupon_mandatory');
@cartpauj
cartpauj / omit-mepr-courses-lessons-from-wp-search.php
Created September 29, 2020 13:38
Omit MemberPress Courses/Lessons From Search Results
<?php
//Copy lines below this, and paste into a "Run Everywhere" Snippet type in the Code Snippets plugin.
function update_course_custom_type() {
global $wp_post_types;
if ( post_type_exists( 'mpcs-course' ) ) {
// exclude from search results
$wp_post_types['mpcs-course']->exclude_from_search = true;
$wp_post_types['mpcs-lesson']->exclude_from_search = true;
}
}
@cartpauj
cartpauj / restore_default_roles_members.txt
Created June 26, 2020 15:10
Members Plugin - Restore Default Roles
If you lock yourself out of your own dashboard via the Members plugin.
Open your wp_options table in PHPMyAdmin and search for the wp_user_roles row.
Set the following as wp_user_roles value to restore default WP Roles and Caps
a:5:{s:13:"administrator";a:2:{s:4:"name";s:13:"Administrator";s:12:"capabilities";a:61:{s:13:"switch_themes";b:1;s:11:"edit_themes";b:1;s:16:"activate_plugins";b:1;s:12:"edit_plugins";b:1;s:10:"edit_users";b:1;s:10:"edit_files";b:1;s:14:"manage_options";b:1;s:17:"moderate_comments";b:1;s:17:"manage_categories";b:1;s:12:"manage_links";b:1;s:12:"upload_files";b:1;s:6:"import";b:1;s:15:"unfiltered_html";b:1;s:10:"edit_posts";b:1;s:17:"edit_others_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:10:"edit_pages";b:1;s:4:"read";b:1;s:8:"level_10";b:1;s:7:"level_9";b:1;s:7:"level_8";b:1;s:7:"level_7";b:1;s:7:"level_6";b:1;s:7:"level_5";b:1;s:7:"level_4";b:1;s:7:"level_3";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:17:"edit_others_pages";b:1;s:20:"edit_