protected function send_reg_email() { global $wpdb; if (empty($this->member_info)) { return false; } $member_info = $this->member_info; $settings = SwpmSettings::get_instance(); $subject = $settings->get_value('reg-complete-mail-subject'); $body = $settings->get_value('reg-complete-mail-body'); $from_address = $settings->get_value('email-from'); $login_link = $settings->get_value('login-page-url'); $headers = 'From: ' . $from_address . "\r\n"; $member_info['membership_level_name'] = SwpmPermission::get_instance($member_info['membership_level'])->get('alias'); $member_info['password'] = $member_info['plain_password']; $member_info['login_link'] = $login_link; $values = array_values($member_info); $keys = array_map('swpm_enclose_var', array_keys($member_info)); $body = html_entity_decode($body); $body = str_replace($keys, $values, $body); $email = sanitize_email(filter_input(INPUT_POST, 'email', FILTER_UNSAFE_RAW)); wp_mail(trim($email), $subject, $body, $headers); SwpmLog::log_simple_debug('Member notification email sent to: ' . $email, true); if ($settings->get_value('enable-admin-notification-after-reg')) { $to_email_address = $settings->get_value('admin-notification-email'); $headers = 'From: ' . $from_address . "\r\n"; $subject = "Notification of New Member Registration"; $body = "A new member has registered. The following email was sent to the member." . "\n\n-------Member Email----------\n" . $body . "\n\n------End------\n"; $admin_notification = empty($to_email_address) ? $from_address : $to_email_address; wp_mail(trim($admin_notification), $subject, $body, $headers); SwpmLog::log_simple_debug('Admin notification email sent to: ' . $admin_notification, true); } return true; }
public function load($level_ids = array()) { if (empty($level_ids)) { global $wpdb; $level_ids = $wpdb->get_col("SELECT id FROM {$wpdb->prefix}swpm_membership_tbl WHERE id != 1"); } foreach ($level_ids as $id) { $this->permissions[] = SwpmPermission::get_instance($id); } }
public function regigstration_ui($level) { //Trigger the filter to override the registration form (the form builder addon uses this filter) $form = apply_filters('swpm_registration_form_override', '', $level); //The $level value could be empty also so the code handling the filter need to check for it. if (!empty($form)) { //An addon has overridden the registration form. So use that one. return $form; } $settings_configs = SwpmSettings::get_instance(); $joinuspage_url = $settings_configs->get_value('join-us-page-url'); $membership_level = ''; global $wpdb; if (SwpmUtils::is_paid_registration()) { //Lets check if this is a registration for paid membership $member = SwpmUtils::get_paid_member_info(); if (empty($member)) { SwpmUtils::e('Error! Invalid Request. Could not find a match for the given security code and the user ID.'); } else { $membership_level = $member->membership_level; } } else { if (!empty($level)) { //Membership level is specified in the shortcode (level specific registration form). $member = SwpmTransfer::$default_fields; $membership_level = absint($level); } } //Check if free membership registration is disalbed on the site if (empty($membership_level)) { $joinuspage_link = '<a href="' . $joinuspage_url . '">Join us</a>'; $free_rego_disabled_msg = '<p>'; $free_rego_disabled_msg .= SwpmUtils::_('Free membership is disabled on this site. Please make a payment from the ' . $joinuspage_link . ' page to pay for a premium membership.'); $free_rego_disabled_msg .= '</p><p>'; $free_rego_disabled_msg .= SwpmUtils::_('You will receive a unique link via email after the payment. You will be able to use that link to complete the premium membership registration.'); $free_rego_disabled_msg .= '</p>'; return $free_rego_disabled_msg; } //Handle the registration form in core plugin $mebership_info = SwpmPermission::get_instance($membership_level); $membership_level = $mebership_info->get('id'); if (empty($membership_level)) { return "Error! Failed to retrieve membership level ID from the membership info object."; } $level_identifier = md5($membership_level); $membership_level_alias = $mebership_info->get('alias'); $swpm_registration_submit = filter_input(INPUT_POST, 'swpm_registration_submit'); if (!empty($swpm_registration_submit)) { $member = array_map('sanitize_text_field', $_POST); } ob_start(); extract((array) $member, EXTR_SKIP); include SIMPLE_WP_MEMBERSHIP_PATH . 'views/add.php'; return ob_get_clean(); }
public function regigstration_ui($level) { $form = apply_filters('swpm_registration_form_override', '', $level); if (!empty($form)) { return $form; } $settings_configs = SwpmSettings::get_instance(); $joinuspage_url = $settings_configs->get_value('join-us-page-url'); $membership_level = ''; global $wpdb; if (SwpmUtils::is_paid_registration()) { //Lets check if this is a registration for paid membership $member = SwpmUtils::get_paid_member_info(); if (empty($member)) { SwpmUtils::e('Error! Invalid Request. Could not find a match for the given security code and the user ID.'); } else { $membership_level = $member->membership_level; } } else { if (!empty($level)) { $member = SwpmTransfer::$default_fields; $membership_level = absint($level); } } if (empty($membership_level)) { $joinuspage_link = '<a href="' . $joinuspage_url . '">Join us</a>'; echo '<p>'; SwpmUtils::e('Free membership is disabled on this site. Please make a payment from the ' . $joinuspage_link . ' page to pay for a premium membership.'); echo '</p><p>'; SwpmUtils::e('You will receive a unique link via email after the payment. You will be able to use that link to complete the premium membership registration.'); echo '</p>'; return; } $mebership_info = SwpmPermission::get_instance($membership_level); $membership_level = $mebership_info->get('id'); if (empty($membership_level)) { return "Membership Level Not Found."; } $level_identifier = md5($membership_level); $membership_level_alias = $mebership_info->get('alias'); $swpm_registration_submit = filter_input(INPUT_POST, 'swpm_registration_submit'); if (!empty($swpm_registration_submit)) { $member = $_POST; } ob_start(); extract((array) $member, EXTR_SKIP); include SIMPLE_WP_MEMBERSHIP_PATH . 'views/add.php'; return ob_get_clean(); }
protected function send_reg_email() { global $wpdb; if (empty($this->member_info)) { return false; } $member_info = $this->member_info; $settings = SwpmSettings::get_instance(); $subject = $settings->get_value('reg-complete-mail-subject'); $body = $settings->get_value('reg-complete-mail-body'); $from_address = $settings->get_value('email-from'); $login_link = $settings->get_value('login-page-url'); $headers = 'From: ' . $from_address . "\r\n"; $member_info['membership_level_name'] = SwpmPermission::get_instance($member_info['membership_level'])->get('alias'); $member_info['password'] = $member_info['plain_password']; $member_info['login_link'] = $login_link; $values = array_values($member_info); $keys = array_map('swpm_enclose_var', array_keys($member_info)); $body = html_entity_decode($body); $body = str_replace($keys, $values, $body); $swpm_user = SwpmMemberUtils::get_user_by_user_name($member_info['user_name']); $member_id = $swpm_user->member_id; $body = SwpmMiscUtils::replace_dynamic_tags($body, $member_id); //Do the standard merge var replacement. $email = sanitize_email(filter_input(INPUT_POST, 'email', FILTER_UNSAFE_RAW)); //Send notification email to the member wp_mail(trim($email), $subject, $body, $headers); SwpmLog::log_simple_debug('Member notification email sent to: ' . $email, true); if ($settings->get_value('enable-admin-notification-after-reg')) { //Send notification email to the site admin $admin_notification = $settings->get_value('admin-notification-email'); $admin_notification = empty($admin_notification) ? $from_address : $admin_notification; $notify_emails_array = explode(",", $admin_notification); $headers = 'From: ' . $from_address . "\r\n"; $subject = "Notification of New Member Registration"; $admin_notify_body = $settings->get_value('reg-complete-mail-body-admin'); if (empty($admin_notify_body)) { $admin_notify_body = "A new member has completed the registration.\n\n" . "Username: {user_name}\n" . "Email: {email}\n\n" . "Please login to the admin dashboard to view details of this user.\n\n" . "You can customize this email message from the Email Settings menu of the plugin.\n\n" . "Thank You"; } $admin_notify_body = SwpmMiscUtils::replace_dynamic_tags($admin_notify_body, $member_id); //Do the standard merge var replacement. foreach ($notify_emails_array as $to_email) { $to_email = trim($to_email); wp_mail($to_email, $subject, $admin_notify_body, $headers); SwpmLog::log_simple_debug('Admin notification email sent to: ' . $to_email, true); } } return true; }
public static function update_category_list() { $selected = filter_input(INPUT_POST, 'membership_level_id'); $selected_level_id = empty($selected) ? 1 : $selected; $category = $selected_level_id == 1 ? SwpmProtection::get_instance() : SwpmPermission::get_instance($selected_level_id); $args = array('ids' => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY)); $filtered = filter_input_array(INPUT_POST, $args); $ids = $filtered['ids']; $args = array('ids_in_page' => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY)); $filtered = filter_input_array(INPUT_POST, $args); $ids_in_page = $filtered['ids_in_page']; $category->remove($ids_in_page, 'category')->apply($ids, 'category')->save(); $message = array('succeeded' => true, 'message' => '<p>' . SwpmUtils::_('Category protection updated!') . '</p>'); SwpmTransfer::get_instance()->set('status', $message); }
public function can_i_read_comment($id) { $this->lastError = ''; $protected = SwpmProtection::get_instance(); if (!$protected->is_protected_comment($id)) { return true; } $auth = SwpmAuth::get_instance(); if (!$auth->is_logged_in()) { $this->lastError = apply_filters('swpm_not_logged_in_comment_msg', SwpmUtils::_("You need to login to view this content. ") . SwpmSettings::get_instance()->get_login_link()); return false; } if ($auth->is_expired_account()) { $error_msg = '<div class="swpm-account-expired-msg swpm-yellow-box">' . SwpmUtils::_('Your account has expired. Please renew your account to gain access to this content.') . '</div>'; $this->lastError = apply_filters('swpm_account_expired_msg', $error_msg); return false; } $perms = SwpmPermission::get_instance($auth->get('membership_level')); if ($perms->is_permitted_comment($id)) { return true; } $this->lastError = apply_filters('swpm_restricted_comment_msg', '<div class="swpm-no-access-msg">' . SwpmUtils::_("This content is not permitted for your membership level.") . '</div>'); return false; }
public static function get_free_level() { $encrypted = filter_input(INPUT_POST, 'level_identifier'); global $wpdb; if (!empty($encrypted)) { return SwpmPermission::get_instance($encrypted)->get('id'); } $is_free = SwpmSettings::get_instance()->get_value('enable-free-membership'); $free_level = absint(SwpmSettings::get_instance()->get_value('free-membership-id')); return $is_free ? $free_level : null; }
public function save_postdata($post_id) { global $wpdb; $post_type = filter_input(INPUT_POST, 'post_type'); $swpm_protect_post = filter_input(INPUT_POST, 'swpm_protect_post'); $swpm_noncename = filter_input(INPUT_POST, 'swpm_noncename'); if (wp_is_post_revision($post_id)) { return; } if (!wp_verify_nonce($swpm_noncename, plugin_basename(__FILE__))) { return $post_id; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } if ('page' == $post_type) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } if (empty($swpm_protect_post)) { return; } // OK, we're authenticated: we need to find and save the data $isprotected = $swpm_protect_post == 2; $args = array('swpm_protection_level' => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY)); $swpm_protection_level = filter_input_array(INPUT_POST, $args); $swpm_protection_level = $swpm_protection_level['swpm_protection_level']; if (!empty($post_type)) { if ($isprotected) { SwpmProtection::get_instance()->apply(array($post_id), $post_type); } else { SwpmProtection::get_instance()->remove(array($post_id), $post_type); } SwpmProtection::get_instance()->save(); $query = "SELECT id FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 "; $level_ids = $wpdb->get_col($query); foreach ($level_ids as $level) { if (isset($swpm_protection_level[$level])) { SwpmPermission::get_instance($level)->apply(array($post_id), $post_type)->save(); } else { SwpmPermission::get_instance($level)->remove(array($post_id), $post_type)->save(); } } } $enable_protection = array(); $enable_protection['protect'] = $swpm_protect_post; $enable_protection['level'] = $swpm_protection_level; return $enable_protection; }
private function check_constraints() { if (empty($this->userData)) { return false; } $enable_expired_login = SwpmSettings::get_instance()->get_value('enable-expired-account-login', ''); $can_login = true; if ($this->userData->account_state == 'inactive') { $this->lastStatusMsg = SwpmUtils::_('Account is inactive.'); $can_login = false; } else { if ($this->userData->account_state == 'pending') { $this->lastStatusMsg = SwpmUtils::_('Account is pending.'); $can_login = false; } else { if ($this->userData->account_state == 'expired' && empty($enable_expired_login)) { $this->lastStatusMsg = SwpmUtils::_('Account has expired.'); $can_login = false; } } } if (!$can_login) { $this->isLoggedIn = false; $this->userData = null; return false; } if (SwpmUtils::is_subscription_expired($this->userData)) { if ($this->userData->account_state == 'active') { global $wpdb; $wpdb->update($wpdb->prefix . 'swpm_members_tbl', array('account_state' => 'expired'), array('member_id' => $this->userData->member_id), array('%s'), array('%d')); } if (empty($enable_expired_login)) { $this->lastStatusMsg = SwpmUtils::_('Account has expired.'); $this->isLoggedIn = false; $this->userData = null; return false; } } $this->permitted = SwpmPermission::get_instance($this->userData->membership_level); $this->lastStatusMsg = SwpmUtils::_("You are logged in as:") . $this->userData->user_name; $this->isLoggedIn = true; return true; }
public function can_i_read_comment($comment) { if (!is_a($comment, 'WP_Comment')) { //This is not a valid WP_Comment object. So we don't want to handle it in our plugin. return true; } $id = $comment->comment_ID; $post_id = $comment->comment_post_ID; $post = get_post($post_id); $this->lastError = ''; $auth = SwpmAuth::get_instance(); //Check if everything protected settings is on. //$protect_everything = SwpmSettings::get_instance()->get_value('protect-everything'); //if(!empty($protect_everything)){ //Everything is protected by default. //TODO - This feature is currently not implemented. //} //Check if the post (that this comment belongs to) is protected. $protected = SwpmProtection::get_instance(); if (!$protected->is_protected($post_id)) { //The post of this comment is not protected. So this is an unprotected comment. Show it to everyone. return true; } /*** At this point, we have a protected comment. So we need to check if this user can view this comment. ***/ //Check if the user is logged-in as a member. if (!$auth->is_logged_in()) { //User is not logged-in. Not allowed to see this protected comment. $error_msg = '<div class="swpm-comment-not-logged-in">' . SwpmUtils::_("You need to login to view this content. ") . '</div>'; $this->lastError = apply_filters('swpm_not_logged_in_comment_msg', $error_msg); return false; } //Check if member account is expired. if ($auth->is_expired_account()) { //This user's account is expired. Not allowed to see this comment. Show account expiry notice also. $text = SwpmUtils::_('Your account has expired. ') . SwpmMiscUtils::get_renewal_link(); $error_msg = '<div class="swpm-comment-account-expired-msg swpm-yellow-box">' . $text . '</div>'; $this->lastError = apply_filters('swpm_account_expired_msg', $error_msg); return false; } //Check if older post protection addon is active and protection according to it's settings. $protect_older_posts = apply_filters('swpm_should_protect_older_post', false, $post_id); if ($protect_older_posts) { //This comment is protected due to the older post protection addon settings configuration. $text = SwpmUtils::_('This content can only be viewed by members who joined on or before ' . SwpmUtils::get_formatted_date_according_to_wp_settings($post->post_date)); $error_msg = '<div class="swpm-comment-older-post-msg">' . $text . '</div>'; $this->lastError = apply_filters('swpm_restricted_comment_older_post', $error_msg); return false; } //Check if this member can view this comment based on his membership level $permission = SwpmPermission::get_instance($auth->get('membership_level')); if (!$permission->is_permitted($post_id)) { //This member's membership level doesn't have access to this comment's post. Not allowed to see this comment. $error_msg = '<div class="swpm-comment-no-access-msg">' . SwpmUtils::_('This content is not permitted for your membership level.') . '</div>'; $this->lastError = apply_filters('swpm_restricted_comment_msg', $error_msg); return false; } //All checks have passed at this stage. Show this comment to this user. return true; }
private function check_constraints() { if (empty($this->userData)) { return false; } global $wpdb; $enable_expired_login = SwpmSettings::get_instance()->get_value('enable-expired-account-login', ''); //Update the last accessed date and IP address for this login attempt. $wpdb->update(table, data, where, format, where format) $last_accessed_date = current_time('mysql'); $last_accessed_ip = SwpmUtils::get_user_ip_address(); $wpdb->update($wpdb->prefix . 'swpm_members_tbl', array('last_accessed' => $last_accessed_date, 'last_accessed_from_ip' => $last_accessed_ip), array('member_id' => $this->userData->member_id), array('%s', '%s'), array('%d')); //Check the member's account status. $can_login = true; if ($this->userData->account_state == 'inactive' && empty($enable_expired_login)) { $this->lastStatusMsg = SwpmUtils::_('Account is inactive.'); $can_login = false; } else { if ($this->userData->account_state == 'expired' && empty($enable_expired_login)) { $this->lastStatusMsg = SwpmUtils::_('Account has expired.'); $can_login = false; } else { if ($this->userData->account_state == 'pending') { $this->lastStatusMsg = SwpmUtils::_('Account is pending.'); $can_login = false; } } } if (!$can_login) { $this->isLoggedIn = false; $this->userData = null; return false; } if (SwpmUtils::is_subscription_expired($this->userData)) { if ($this->userData->account_state == 'active') { $wpdb->update($wpdb->prefix . 'swpm_members_tbl', array('account_state' => 'expired'), array('member_id' => $this->userData->member_id), array('%s'), array('%d')); } if (empty($enable_expired_login)) { $this->lastStatusMsg = SwpmUtils::_('Account has expired.'); $this->isLoggedIn = false; $this->userData = null; return false; } } $this->permitted = SwpmPermission::get_instance($this->userData->membership_level); $this->lastStatusMsg = SwpmUtils::_("You are logged in as:") . $this->userData->user_name; $this->isLoggedIn = true; return true; }