/**
 * Filter restricted content based on category restrictions
 *
 * @access      public
 * @since       2.0
 * @return      $content
 */
function rcp_filter_restricted_category_content($content)
{
    global $post, $user_ID, $rcp_options;
    $has_access = true;
    $categories = get_the_category($post->ID);
    if (empty($categories)) {
        return $content;
    }
    // Loop through the categories and determine if one has restriction options
    foreach ($categories as $category) {
        $term_meta = get_option("rcp_category_meta_{$category->term_id}");
        if (!empty($term_meta)) {
            /**
             * Check that the user has a paid subscription
             */
            $paid_only = !empty($term_meta['paid_only']);
            if ($paid_only && !rcp_is_paid_user()) {
                $has_access = false;
            }
            /**
             * If restricted to one or more subscription levels, make sure that the user is a member of one of the levls
             */
            $subscriptions = !empty($term_meta['subscriptions']) ? array_map('absint', $term_meta['subscriptions']) : false;
            if ($subscriptions && !in_array(rcp_get_subscription_id(), $subscriptions)) {
                $has_access = false;
            }
            /**
             * If restricted to one or more access levels, make sure that the user is a member of one of the levls
             */
            $access_level = !empty($term_meta['access_level']) ? absint($term_meta['access_level']) : 0;
            if ($access_level > 0 && !rcp_user_has_access($user_ID, $access_level)) {
                $has_access = false;
            }
        }
    }
    if (!$has_access) {
        $message = !empty($rcp_options['paid_message']) ? $rcp_options['paid_message'] : __('You need to have an active subscription to view this content.', 'rcp');
        return rcp_format_teaser($message);
    }
    return $content;
}
Ejemplo n.º 2
0
/**
 * Check the provided taxonomy along with the given post id to see if any restrictions are found
 *
 * @since      2.5
 * @param      $post_id
 * @param      $taxonomy
 * @param null $user_id
 *
 * @return int|bool true if tax is restricted, false if user can access, -1 if unrestricted or invalid
 */
function rcp_is_post_taxonomy_restricted($post_id, $taxonomy, $user_id = null)
{
    $restricted = -1;
    if (current_user_can('edit_post', $post_id)) {
        return $restricted;
    }
    // make sure this post supports the supplied taxonomy
    $post_taxonomies = get_post_taxonomies($post_id);
    if (!in_array($taxonomy, (array) $post_taxonomies)) {
        return $restricted;
    }
    $terms = get_the_terms($post_id, $taxonomy);
    if (empty($terms) || is_wp_error($terms)) {
        return $restricted;
    }
    if (!$user_id) {
        $user_id = get_current_user_id();
    }
    // Loop through the categories and determine if one has restriction options
    foreach ($terms as $term) {
        $term_meta = rcp_get_term_restrictions($term->term_id);
        if (empty($term_meta['paid_only']) && empty($term_meta['subscriptions']) && (empty($term_meta['access_level']) || 'None' == $term_meta['access_level'])) {
            continue;
        }
        $restricted = false;
        /** Check that the user has a paid subscription ****************************************************************/
        $paid_only = !empty($term_meta['paid_only']);
        if ($paid_only && !rcp_is_paid_user($user_id)) {
            $restricted = true;
        }
        /** If restricted to one or more subscription levels, make sure that the user is a member of one of the levels */
        $subscriptions = !empty($term_meta['subscriptions']) ? array_map('absint', $term_meta['subscriptions']) : false;
        if ($subscriptions && !in_array(rcp_get_subscription_id($user_id), $subscriptions)) {
            $restricted = true;
        }
        /** If restricted to one or more access levels, make sure that the user is a member of one of the levls ********/
        $access_level = !empty($term_meta['access_level']) ? absint($term_meta['access_level']) : 0;
        if ($access_level > 0 && !rcp_user_has_access($user_id, $access_level)) {
            $restricted = true;
        }
        $match_all = apply_filters('rcp_restricted_taxonomy_term_match_all', false, $post_id, $taxonomy, $user_id);
        // if we are matching all terms then it only takes one restricted term to restrict the taxonomy
        if ($restricted && $match_all) {
            break;
        }
        // if we are matching any term, then we only need the user to have access to one
        if (!$match_all && !$restricted) {
            break;
        }
    }
    return apply_filters('rcp_is_post_taxonomy_restricted', $restricted, $taxonomy, $post_id, $user_id);
}
Ejemplo n.º 3
0
/**
 * Display Subscribe/Login button on restricted pages.
 *
 * @return void
 */
function stag_rcp_locked_options($atts)
{
    if (!stag_is_rcp_active()) {
        return;
    }
    $args = shortcode_atts(array('button' => ''), $atts, 'locked_options');
    global $user_ID, $rcp_options;
    $is_displayed = $show_login_button = false;
    $registration_page = $rcp_options['registration_page'];
    if (!is_user_logged_in()) {
        $show_login_button = true;
    }
    $has_access = !rcp_is_paid_user($user_ID) && isset($registration_page) && $registration_page != '' ? true : false;
    if (isset($args['button']) && $args['button'] != '') {
        $button_color = $args['button'];
    } else {
        $background_color = stag_get_post_meta('settings', get_the_ID(), 'post-background-color');
        $button_color = $background_color === '' && !has_post_thumbnail() ? 'black' : 'white';
        if (is_single()) {
            $button_color = 'black';
        }
    }
    ob_start();
    ?>

	<div class="locked-options<?php 
    echo $has_access ? ' no-access' : ' has-access';
    ?>
 <?php 
    echo $button_color;
    ?>
-buttons">
		<?php 
    if ($has_access) {
        ?>
			<a href="<?php 
        echo get_permalink($registration_page);
        ?>
" class="stag-button stag-button--stroke stag-button--<?php 
        echo esc_attr($button_color);
        ?>
"><?php 
        _e('Subscribe', 'stag');
        ?>
</a>
			<?php 
        $is_displayed = true;
        ?>
		<?php 
    }
    ?>
		<?php 
    if ($show_login_button) {
        ?>
			<?php 
        if ($is_displayed) {
            echo '<span class="form-divider"></span>';
        }
        ?>
			<a href="<?php 
        echo wp_login_url();
        ?>
" class="stag-button stag-button--stroke stag-button--<?php 
        echo esc_attr($button_color);
        ?>
"><?php 
        _e('Login', 'stag');
        ?>
</a>
		<?php 
    }
    ?>
	</div>

	<?php 
    return ob_get_clean();
}