/**
 * Filter restricted content based on category restrictions
 *
 * @access      public
 * @since       2.0
 * @return      $content
 */
function rcp_filter_restricted_category_content($content)
{
    global $post, $rcp_options;
    $restrictions = array();
    foreach (rcp_get_restricted_taxonomies() as $taxonomy) {
        $restriction = rcp_is_post_taxonomy_restricted($post->ID, $taxonomy);
        // -1 means that the taxonomy terms are unrestricted
        if (-1 === $restriction) {
            continue;
        }
        // true or false. Whether or not the user has access to the restricted taxonomy terms
        $restrictions[] = $restriction;
    }
    if (empty($restrictions)) {
        return $content;
    }
    $restricted = apply_filters('rcp_restricted_taxonomy_match_all', false) ? false !== array_search(true, $restrictions) : false === array_search(false, $restrictions);
    if ($restricted) {
        $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;
}
Esempio n. 2
0
/**
 * Save our custom category meta
 *
 * @access      public
 * @since       2.0
 * @return      void
 */
function rcp_save_category_meta($term_id, $tt_id, $taxonomy)
{
    if (empty($_POST['rcp_edit_category']) || !wp_verify_nonce($_POST['rcp_edit_category'], 'rcp_edit_category')) {
        return;
    }
    $restricted_taxonomies = rcp_get_restricted_taxonomies();
    if (!in_array($taxonomy, $restricted_taxonomies)) {
        return;
    }
    $fields = !empty($_POST['rcp_category_meta']) ? $_POST['rcp_category_meta'] : array();
    if (!empty($_POST['rcp_category_meta']['subscriptions'])) {
        $fields['subscriptions'] = array_map('absint', array_keys($_POST['rcp_category_meta']['subscriptions']));
    }
    if (function_exists('update_term_meta') && update_term_meta($term_id, 'rcp_restricted_meta', $fields)) {
        // remove deprecated data
        delete_option("rcp_category_meta_{$term_id}");
    } else {
        // fallback to older method of handling term meta
        update_option("rcp_category_meta_{$term_id}", $fields);
    }
}