Skip to content

Instantly share code, notes, and snippets.

@cartpauj
cartpauj / nua-bypass-by-membership.php
Created June 13, 2023 14:07
Bypass New User Approve if certain Membership(s) is purchased in MemberPress
<?php
function nua_allow_user_if_membership($errors) {
$allowed_memberships = array(123,321,789,987); // CHANGE THIS
if(!is_user_logged_in()) {
if(in_array((int)$_POST['mepr_product_id'], $allowed_memberships)) {
$_REQUEST['action'] = 'createuser'; //Set this so "New User Approve" plugin will not limit the subscriber
}
}
@cartpauj
cartpauj / mp-elementor-html-alterations.php
Created May 17, 2023 15:35
Disable MP Elementor protection HTML alterations
<?php
// Copy lines 4-6 below into a plugin like Code Snippets (run on front-end only)
add_filter('mp_elementor_include_section_html', function() {
return false;
});
@cartpauj
cartpauj / prli-delay-message.php
Created August 9, 2022 20:25
Show a delay message when using Pretty Links Meta Refresh or Javascript redirect types with a delay
<?php
function plp_delay_message_code() {
?>
<p>Please wait... You will be redirected soon.</p>
<?php
}
add_action('prli-redirect-header', 'plp_delay_message_code');
@cartpauj
cartpauj / esaf-commission-user-joined-after-aff.php
Created May 14, 2021 13:04
Easy Affiliate - Pay higher commission if user signed up AFTER affiliate
<?php
add_filter('esaf_commission_percentages', function ($commission, $affiliate, $transaction) {
if($transaction) {
$user = get_user_by('email', $transaction->cust_email);
if($user && strtotime($user->user_registered) > strtotime($affiliate->user_registered)) {
$commission = array(30);
}
}
@cartpauj
cartpauj / mepr-hide-cancel-button-for-time.php
Created April 23, 2021 17:03
Hide cancel link in MP until user has been active for 3 months.
<?php
add_filter('mepr_custom_cancel_link', function($link, $sub) {
$time = strtotime($sub->created_at);
if(time() < strtotime("+3 months", $time)) {
return '';
}
return $link;
}, 10, 2);
@cartpauj
cartpauj / disable-math-on-login.php
Created February 9, 2021 16:30
Disable Math Captcha on Login Page - MemberPress
<?php
// Disables math captcha on login page
function kill_math_on_login() {
remove_all_actions('mepr-forgot-password-form');
remove_all_actions('mepr-login-form-before-submit');
remove_all_filters('mepr-validate-forgot-password');
remove_all_filters('mepr-validate-login');
}
add_action('plugins_loaded', 'kill_math_on_login');
@cartpauj
cartpauj / mepr-force-vat-type-business.php
Created February 5, 2021 15:29
Force MemberPress user VAT type to business
<?php
function force_business_vat_type($user) {
update_user_meta($user->ID, 'mepr_vat_customer_type', 'business');
}
add_action('mepr-signup-user-loaded', 'force_business_vat_type');
@cartpauj
cartpauj / mepr-disable-password-lost-changed-email.php
Last active August 25, 2021 15:14
Disable MemberPress Password Lost/Changed email
<?php
// Copy the lines below this one into a plugin like Code Snippets (run everywhere type)
function disable_admin_pw_changed_email_memberpress($recipients, $subject, $message, $headers) {
if(strpos($subject, 'Password Lost/Changed') !== false) {
$recipients = array(); // no recipients
}
return $recipients;
}
add_filter('mepr-wp-mail-recipients', 'disable_admin_pw_changed_email_memberpress', 11, 4);
@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;
}