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);
$user_level = get_post_meta($post_id, 'rcp_user_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 ($ret && !empty($user_level) && 'All' != $user_level) {
if (!user_can($this->ID, strtolower($user_level))) {
$ret = false;
}
}
if (user_can($this->ID, 'manage_options')) {
$ret = true;
}
return apply_filters('rcp_member_can_access', $ret, $this->ID, $post_id, $this);
}