This page contains some tweaks that our users submitted to us. The following sample tweaks have not been tested by us.
These tweaks are meant for developers only (you have to be a developer to be able to read the code and understand what it does and then maybe use it for a particular project).
You can find some more tweaks on our PHP Tweaks documentation.
Auto Downgrade Membership Level Instead of Expiry
The following code will auto downgrade membership type of Gold to membership type of Silver on membership expiry
function auto_downgrade_membership_type(){ // Is a user logged in? if(SwpmMemberUtils::is_member_logged_in() == true){ // Yes. A user is logged in. // Get the user's member id. We will use this later.* $mId = SwpmMemberUtils::get_logged_in_members_id(); // Get the user's current membership account state. We will use this later.** $auth = SwpmAuth::get_instance(); $account_state = $auth->get('account_state'); // Is their current membership level Gold? if(SwpmMemberUtils::get_logged_in_members_level_name() == "Gold"){ // Yes. The user's membership type is Gold. // Is their Gold Membership expired? $user = SwpmMemberUtils::get_user_by_id($mId); if(SwpmUtils::is_subscription_expired($user) == true){ // Yes. The user's Gold membership has expired. // Downgrade the Gold membership to Silver membership - using the user's id variable above* and the id of the desired membership level. SwpmMemberUtils::update_membership_level($mId, 2); // Change the new membership (Silver) account state to "active" because the membership (Gold) account state still thinks it's expired. SwpmMemberUtils::update_account_state($mId, $new_status = 'active'); // If an admin manually changed a member's account state to expired (for some reason...) but the membership expire date hasn't been reached. // Check the user's current membership account state.** }elseif($account_state == 'expired'){ // Downgrade the Gold membership to Silver membership type - using the user's id variable above* and the id of the desired membership level. SwpmMemberUtils::update_membership_level($mId, 2); // Change the new membership (Silver) account state to "active" because the membership (Gold) account state still thinks it's expired. SwpmMemberUtils::update_account_state($mId, $new_status = 'active'); }else{ // No. The user still has Gold privileges. } }else{ // No. The user's current membership type is Silver. } }else{ // No. There is no user logged in. } } add_action('init', 'auto_downgrade_membership_type');
Switch Login and Join-us URL by Site Language
Modification of the “get_login_link()” function in the classes/class.swpm-utils-misc.php file.
public static function get_login_link() { $login_url = SwpmSettings::get_instance()->get_value('login-page-url'); $joinus_url = SwpmSettings::get_instance()->get_value('join-us-page-url'); if (empty($login_url) || empty($joinus_url)) { return '<span style="color:red;">Simple Membership is not configured correctly. The login page or the join us page URL is missing in the settings configuration. ' . 'Please contact <a href="mailto:' . get_option('admin_email') . '">Admin</a>'; } /*** Start modification ***/ $access_url = $_SERVER['REQUEST_URI']; $en_login_url = 'https://example.com/en/members-login/'; $en_joinus_url = 'https://example.com/en/membership-join-en/'; $jp_login_url = 'https://example.com/membership-login/'; $jp_joinus_url = 'https://example.com/membership-join/'; $ru_login_url = 'https://example.com/ru/members-login-ru/'; $ru_joinus_url = 'https://example.com/ru/membership-join-ru/'; switch ($access_url){ case '/en/my-protected-post-en/': $login_url = $en_login_url; $joinus_url = $en_joinus_url; break; case '/my-protected-page/': $login_url = $jp_login_url; $joinus_url = $jp_joinus_url; break; case '/ru/my-page-ru/': $login_url = $ru_login_url; $joinus_url = $ru_joinus_url; break; case '/ru/members-login-ru/': $login_url = $ru_login_url; $joinus_url = $ru_joinus_url; break; default: } /*** End modification ***/ //Create the login/protection message $filtered_login_url = apply_filters('swpm_get_login_link_url', $login_url); //Addons can override the login URL value using this filter. $login_msg = ''; $login_msg .= SwpmUtils::_('Please') . ' <a class="swpm-login-link" href="' . $filtered_login_url . '">' . SwpmUtils::_('Login') . '</a>. '; $login_msg .= SwpmUtils::_('Not a Member?') . ' <a href="' . $joinus_url . '">' . SwpmUtils::_('Join Us') . '</a>'; return $login_msg; }
Display a Key Icon Before Protected Post Title
The following tweak shows a lock icon before a protected post and a key icon before an unprotected post.
function my_custom_post_title($title, $id) { $protected = SwpmProtection::get_instance(); $auth = SwpmAuth::get_instance(); if ($auth->is_logged_in() && $protected->is_protected($id)) { //Member is logged-in and the post is protected return '' . $title; } elseif ($protected->is_protected($id) && !$auth->is_logged_in()) { //Member is not logged-in and the post is protected return '' . $title; } else { //No protection to the post return '' . $title; } } add_filter('the_title', 'my_custom_post_title', 10, 2);
Custom Messages Addon – Redirect to Previous Page
See this support topic on wordpress.org site for a potential solution that was submitted by one of our users.