コード例 #1
0
function rcp_filter_restricted_content($content)
{
    global $post, $user_ID, $rcp_options;
    $message = $rcp_options['paid_message'];
    // message shown for premium content
    $free_message = $rcp_options['free_message'];
    // message shown for free content
    $subscription_levels = rcp_get_content_subscription_levels($post->ID);
    $access_level = get_post_meta($post->ID, 'rcp_access_level', true);
    if (rcp_is_paid_content($post->ID)) {
        // this conent is for paid users only
        if (!rcp_is_paid_user($user_ID) || !rcp_user_has_access($user_ID, $access_level) && $access_level > 0) {
            return rcp_format_teaser($message);
        } else {
            if ($subscription_levels) {
                if ($access_level > 0) {
                    $has_access = rcp_user_has_access($user_ID, $access_level);
                } else {
                    $has_access = true;
                    // no access level restriction
                }
                if ((!in_array(rcp_get_subscription_id($user_ID), $subscription_levels) || !$has_access) && !current_user_can('manage_options')) {
                    return rcp_format_teaser($message);
                }
            }
            return $content;
        }
    } elseif ($subscription_levels) {
        // this content is restricted to a subscription level, but is free
        if ($access_level > 0) {
            $has_access = rcp_user_has_access($user_ID, $access_level);
        } else {
            $has_access = true;
            // no access level restriction
        }
        if (in_array(rcp_get_subscription_id($user_ID), $subscription_levels) && $has_access) {
            return $content;
        } else {
            return rcp_format_teaser($free_message);
        }
    } elseif ($access_level > 0) {
        if (rcp_user_has_access($user_ID, $access_level)) {
            return $content;
        } else {
            return rcp_format_teaser($free_message);
        }
    } else {
        return $content;
    }
}
コード例 #2
0
 /**
  * Determines if the member can access current content
  *
  * @access  public
  * @since   2.1
  */
 public function can_access($post_id = 0)
 {
     $subscription_levels = rcp_get_content_subscription_levels($post_id);
     $access_level = get_post_meta($post_id, 'rcp_access_level', true);
     $sub_id = $this->get_subscription_id();
     // Assume the user can until proven false
     $ret = true;
     if (rcp_is_paid_content($post_id) && $this->is_expired()) {
         $ret = false;
     }
     if (!empty($subscription_levels)) {
         if (is_string($subscription_levels)) {
             switch ($subscription_levels) {
                 case 'any':
                     $ret = !empty($sub_id) && !$this->is_expired();
                     break;
                 case 'any-paid':
                     $ret = $this->is_active();
                     break;
             }
         } else {
             if (in_array($sub_id, $subscription_levels)) {
                 $needs_paid = false;
                 foreach ($subscription_levels as $level) {
                     $price = rcp_get_subscription_price($level);
                     if (!empty($price) && $price > 0) {
                         $needs_paid = true;
                     }
                 }
                 if ($needs_paid) {
                     $ret = $this->is_active();
                 } else {
                     $ret = true;
                 }
             } else {
                 $ret = false;
             }
         }
     }
     if (!rcp_user_has_access($this->ID, $access_level) && $access_level > 0) {
         $ret = false;
     }
     if (user_can($this->ID, 'manage_options')) {
         $ret = true;
     }
     return apply_filters('rcp_member_can_access', $ret, $this->ID, $post_id, $this);
 }
コード例 #3
0
 /**
  * Determines if the member can access current content
  *
  * @access  public
  * @since   2.1
  */
 public function can_access($post_id = 0)
 {
     $subscription_levels = rcp_get_content_subscription_levels($post_id);
     $access_level = get_post_meta($post_id, 'rcp_access_level', true);
     // Assume the user can until proven false
     $ret = true;
     if (rcp_is_paid_content($post_id) && !$this->is_active()) {
         $ret = false;
     }
     if (!rcp_user_has_access($this->ID, $access_level) && $access_level > 0) {
         $ret = false;
     }
     if (!empty($subscription_levels)) {
         if (!in_array($this->get_subscription_id(), $subscription_levels) && !user_can($this->ID, 'manage_options')) {
             $ret = false;
         }
     }
     return apply_filters('rcp_member_can_access', $ret, $this->ID, $post_id, $this);
 }
コード例 #4
0
/**
 * Checks to see if content is restricted in any way.
 *
 * @since  2.5
 * @param  int $post_id The post ID to check for restrictions.
 * @return bool True if the content is restricted, false if not.
 */
function rcp_is_restricted_content($post_id)
{
    if (empty($post_id) || !is_numeric($post_id)) {
        return false;
    }
    $restricted = false;
    $post_id = absint($post_id);
    if (!$restricted && rcp_is_paid_content($post_id)) {
        $restricted = true;
    }
    if (!$restricted && rcp_get_content_subscription_levels($post_id)) {
        $restricted = true;
    }
    if (!$restricted) {
        $rcp_user_level = get_post_meta($post_id, 'rcp_user_level', true);
        if (!empty($rcp_user_level) && 'All' !== $rcp_user_level) {
            $restricted = true;
        }
    }
    if (!$restricted) {
        $rcp_access_level = get_post_meta($post_id, 'rcp_access_level', true);
        if (!empty($rcp_access_level) && 'None' !== $rcp_access_level) {
            $restricted = true;
        }
    }
    return apply_filters('rcp_is_restricted_content', $restricted, $post_id);
}