Ejemplo n.º 1
0
 /**
  * Setup the rule.
  *
  * @since  1.0.0
  */
 public function prepare_obj()
 {
     if (MS_Rule_Content_Model::is_active()) {
         MS_Model_Rule::register_rule(self::RULE_ID, __CLASS__, __('Comments & More Tag', MS_TEXT_DOMAIN), 80);
     }
     $this->add_filter('ms_view_protectedcontent_define-' . self::RULE_ID, 'handle_render_callback', 10, 2);
     $this->add_filter('ms_rule_listtable-' . self::RULE_ID, 'return_listtable');
 }
 /**
  * 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);
     }
 }