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 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 __construct() { $this->isLoggedIn = false; $this->userData = null; $this->protected = SwpmProtection::get_instance(); }
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; }