/** * Verify access to the current content. * * This rule will return NULL (not relevant), because the media-item is * protected via the download URL and not by protecting the current page. * * @since 1.0.0 * * @param string $id The content id to verify access. * @return bool|null True if has access, false otherwise. * Null means: Rule not relevant for current page. */ public function has_access($id, $admin_has_access = true) { if (MS_Model_Addon::is_enabled(MS_Addon_Mediafiles::ID) && 'attachment' == get_post_type($id)) { return parent::has_access($id, $admin_has_access); } else { return null; } }
/** * Verify access to the current content. * * @since 1.0.0 * * @param int $id The content post ID to verify access. * @return bool|null True if has access, false otherwise. * Null means: Rule not relevant for current page. */ public function has_access($id, $admin_has_access = true) { global $wp_query; $has_access = null; if (empty($id)) { $id = $this->get_current_post_id(); } if (!empty($id)) { $post_type = get_post_type($id); if (in_array($post_type, self::get_bb_cpt())) { $has_access = false; // Only verify permission if addon is enabled. if (MS_Addon_Bbpress::is_active()) { switch ($post_type) { case self::CPT_BB_FORUM: $has_access = parent::has_access($id, $admin_has_access); break; case self::CPT_BB_TOPIC: if (function_exists('bbp_get_topic_forum_id')) { $forum_id = bbp_get_topic_forum_id($id); $has_access = parent::has_access($forum_id, $admin_has_access); } break; case self::CPT_BB_REPLY: if (function_exists('bbp_get_reply_forum_id')) { $forum_id = bbp_get_reply_forum_id($id); $has_access = parent::has_access($forum_id, $admin_has_access); } break; } } else { $has_access = true; } } } else { /* * If post type is forum and no post_id, it is the forum list page, give access. * @todo Find another way to verify if the current page is the forum list page. */ if (self::CPT_BB_FORUM === $wp_query->get('post_type')) { $has_access = true; } } return apply_filters('ms_addon_bbpress_model_rule_has_access', $has_access, $id, $this); }
/** * Set initial protection. * * Add [ms-protect-content] shortcode to protect membership content inside post. * * @since 1.0.0 */ public function protect_content() { parent::protect_content(); self::$membership_ids[] = $this->membership_id; add_shortcode(self::PROTECT_CONTENT_SHORTCODE, array(__CLASS__, 'protect_content_shortcode')); if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_SHORTCODE)) { global $shortcode_tags; $exclude = MS_Helper_Shortcode::get_membership_shortcodes(); foreach ($shortcode_tags as $shortcode => $callback_funciton) { if (in_array($shortcode, $exclude)) { continue; } if (!parent::has_access($shortcode)) { $shortcode_tags[$shortcode] = array(&$this, 'do_protected_shortcode'); } } } }
/** * Verify access to the current category or post belonging to a catogory. * * @since 1.0.0 * * @param int $id The current post_id. * @return bool|null True if has access, false otherwise. * Null means: Rule not relevant for current page. */ public function has_access($id, $admin_has_access = true) { $has_access = null; $taxonomies = get_object_taxonomies(get_post_type()); // Verify post access accordingly to category rules. if (!empty($id) || is_single() && in_array('category', $taxonomies)) { if (empty($id)) { $id = get_the_ID(); } $categories = wp_get_post_categories($id); foreach ($categories as $category_id) { $has_access = parent::has_access($category_id, $admin_has_access); if ($has_access) { break; } } } elseif (is_category()) { // Category page. $category = get_queried_object_id(); $has_access = parent::has_access($category, $admin_has_access); } return apply_filters('ms_rule_category_model_has_access', $has_access, $id, $this); }
/** * Verify access to the current content. * * @since 1.0.0 * * @param string $id The content id to verify access. * @return bool|null True if has access, false otherwise. * Null means: Rule not relevant for current page. */ public function has_access($id, $admin_has_access = true) { $has_access = null; // Only verify permission if NOT ruled by cpt post by post. if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_CPT_POST_BY_POST)) { return $has_access; } if (!empty($id)) { $post = get_post($id); } else { $post = get_queried_object(); } $post_type = !empty($post->post_type) ? $post->post_type : ''; if (empty($post_type) && !empty($post->query_var)) { $post_type = $post->query_var; } if (in_array($post_type, self::get_ms_post_types())) { // Always allow access to Membership2 pages. $has_access = true; } elseif (in_array($post_type, self::get_custom_post_types())) { // Custom post type $has_access = parent::has_access($post_type, $admin_has_access); } else { // WordPress core pages are ignored by this rule. $has_access = null; } return apply_filters('ms_rule_cptgroup_model_has_access', $has_access, $id, $this); }
/** * Verify access to the current page. * * @since 1.0.0 * * @param int $id The page_id to verify access. * @return bool|null True if has access, false otherwise. * Null means: Rule not relevant for current page. */ public function has_access($id, $admin_has_access = true) { $has_access = null; if (empty($id)) { $id = $this->get_current_post_id(); } else { $post = get_post($id); if (!is_a($post, 'WP_Post') || !empty($post->post_type) && 'post' != $post->post_type) { $id = 0; } } if (!empty($id)) { $has_access = parent::has_access($id, $admin_has_access); } return apply_filters('ms_rule_post_model_has_access', $has_access, $id, $this); }
/** * Verify access to the current content. * * @since 1.0.0 * * @param string $id The content id to verify access. * @return bool|null True if has access, false otherwise. * Null means: Rule not relevant for current page. */ public function has_access($id, $admin_has_access = true) { $has_access = null; // Only verify permission if ruled by cpt post by post. if (MS_Model_Addon::is_enabled(MS_Model_Addon::ADDON_CPT_POST_BY_POST)) { if (empty($id)) { $id = $this->get_current_post_id(); } if (!empty($id)) { $post_type = get_post_type($id); $mspt = MS_Rule_CptGroup_Model::get_ms_post_types(); $cpt = MS_Rule_CptGroup_Model::get_custom_post_types(); if (in_array($post_type, $mspt)) { // Always allow access to Membership2 pages. $has_access = true; } elseif (in_array($post_type, $cpt)) { // Custom post type $has_access = parent::has_access($id, $admin_has_access); } else { // WordPress core pages are ignored by this rule. $has_access = null; } } } return apply_filters('ms_rule_custom_post_type_has_access', $has_access, $id, $this); }
/** * Set initial protection. * * @since 1.0.0 */ public function protect_content() { parent::protect_content(); // ********* COMMENTS ********** // No comments on special pages (signup, account, ...) $this->add_filter('the_content', 'check_special_page'); /* * We find the public comment access once. * This is the access ganted to guests or memberships that do not define * an explicit comment access rule. */ if (null === self::$comment_public) { $base_rule = MS_Model_Membership::get_base()->get_rule($this->rule_type); if (null === $base_rule->get_rule_value(self::COMMENT_WRITE)) { self::$comment_public = self::COMMENT_WRITE; } elseif (null === $base_rule->get_rule_value(self::COMMENT_READ)) { self::$comment_public = self::COMMENT_READ; } else { self::$comment_public = self::COMMENT_NO_ACCESS; } } // Find the most generous comment access rule. $has_full = $this->get_rule_value(self::COMMENT_WRITE); $has_read = $this->get_rule_value(self::COMMENT_READ); $has_none = $this->get_rule_value(self::COMMENT_NO_ACCESS); if (true === $has_full) { // Membership allows full comment access. self::$comment_access = self::COMMENT_WRITE; } elseif (true === $has_read) { // Membership allows read-only access. if (self::$comment_access == self::COMMENT_NO_ACCESS) { self::$comment_access = self::COMMENT_READ; } } elseif (true === $has_none) { // Membership does not allow any comment access. // (no change, this is the default access level) } else { // This membership does not define a comment access: Use public access! self::$comment_access = self::$comment_public; } $this->add_action('ms_setup_protection_done', 'protect_comments'); // ********** READ MORE ********** $this->protection_message = MS_Plugin::instance()->settings->get_protection_message(MS_Model_Settings::PROTECTION_MSG_MORE_TAG, $this->membership_id); if (!parent::has_access(self::MORE_LIMIT)) { $this->add_filter('the_content_more_link', 'show_moretag_protection', 99, 2); $this->add_filter('the_content', 'replace_more_tag_content', 1); $this->add_filter('the_content_feed', 'replace_more_tag_content', 1); } }
/** * Checks the ability to create groups. * * Related Action Hooks: * - bp_user_can_create_groups * * @since 1.0.0 * * @param string $can_create The initial access. * @return string The initial template if current user can create groups, otherwise blocking message. */ public function protect_create_bp_group($can_create) { $can_create = false; if (parent::has_access(MS_Addon_BuddyPress_Rule::PROTECT_GROUP_CREATION)) { $can_create = true; } return apply_filters('ms_rule_buddypress_protect_create_bp_group', $can_create, $this); }
/** * Verify access to the current page. * * @since 1.0.0 * * @param int $id The page_id to verify access. * @return bool|null True if has access, false otherwise. * Null means: Rule not relevant for current page. */ public function has_access($id, $admin_has_access = true) { $has_access = null; if (empty($id)) { $id = $this->get_current_page_id(); } else { $post = get_post($id); if (!is_a($post, 'WP_Post') || 'page' != $post->post_type) { $id = 0; } } if (!empty($id)) { $has_access = false; // Membership special pages has access if (MS_Model_Pages::is_membership_page($id)) { $has_access = true; } else { $has_access = parent::has_access($id, $admin_has_access); } } return apply_filters('ms_rule_page_model_has_access', $has_access, $id, $this); }
/** * Checks if the specified menu-ID is allowed by this rule. * * @since 1.0.0 * * @param object $item The menu item object. * @return bool */ protected function can_access_menu($item, $admin_has_access = true) { $result = false; if (parent::has_access($item->ID, $admin_has_access)) { $result = true; } return $result; }