Пример #1
0
function edd_cr_hide_menu_items($items, $args)
{
    if (edd_get_option('edd_content_restriction_hide_menu_items', false)) {
        foreach ($items as $item_id => $item_data) {
            $restricted = edd_cr_is_restricted($item_data->object_id);
            $has_access = edd_cr_user_can_access(get_current_user_id(), $restricted, $item_data->object_id);
            if ($has_access['status'] == false) {
                unset($items[$item_id]);
            }
        }
    }
    return $items;
}
Пример #2
0
/**
 * Plugin Name: Easy Digital Downloads - Content Restriction - Show login form for logged out users
 * Description: Shows the [edd_login] form on restricted content for logged out users.
 * Author: John Parris
 */
function jp_cr_login_form($content)
{
    if (!function_exists('edd_cr_is_restricted')) {
        return $content;
    }
    global $post;
    if (!is_object($post)) {
        return $content;
    }
    if (edd_cr_is_restricted($post->ID) && !is_user_logged_in()) {
        $content .= do_shortcode('[edd_login]');
    }
    return $content;
}
 /**
  * Check if user has access to content
  *
  * @since  1.0
  * @return bool
  */
 public function restrict($is_restricted = false, $post_id = 0, $download_id = 0, $user_id = 0, $price_id = null)
 {
     if (!edd_cr_is_restricted($post_id)) {
         return $is_restricted;
     }
     if (!get_post_meta($post_id, '_edd_cr_active_only', true)) {
         return $is_restricted;
     }
     // Leave untouched
     if (!EDD_Recurring_Customer::is_customer_active($user_id)) {
         return true;
     }
     return $is_restricted;
 }
/**
 * Determine if a user has permission to view the currently viewed URL
 *
 * Mainly for use in template files
 * @since  2.1
 * @param int $user_id The User ID to check (defaults to logged in user)
 * @param int $post_id The Post ID to check access for (defaults to current post)
 * @return bool If the current user has permission to view the current URL
 */
function edd_cr_user_has_access($user_id = 0, $post_id = 0)
{
    global $post;
    $user_id = empty($user_id) ? get_current_user_id() : $user_id;
    $post_id = empty($post_id) && is_object($post) ? $post->ID : $post_id;
    $has_access = true;
    if (!empty($post_id)) {
        $is_post_restricted = edd_cr_is_restricted($post_id);
        if ($is_post_restricted) {
            $user_has_access = edd_cr_user_can_access($user_id, $is_post_restricted, $post_id);
            $has_access = $user_has_access['status'] == false ? false : true;
        }
    }
    return apply_filters('ecc_cr_user_has_access', $has_access);
}
Пример #5
0
/**
 * Hides the new reply form
 *
 * @param       bool $retval The current state of this permission check
 * @global      int $user_ID The ID of the current user
 * @return      mixed $return
 */
function edd_cr_hide_new_replies_form($retval)
{
    global $user_ID;
    if (!current_user_can('moderate') && bbp_current_user_can_publish_replies()) {
        $restricted_to = edd_cr_is_restricted(bbp_get_topic_id());
        $restricted_id = bbp_get_topic_id();
        if (!$restricted_to) {
            $restricted_to = edd_cr_is_restricted(bbp_get_forum_id());
            // check for parent forum restriction
            $restricted_id = bbp_get_forum_id();
            if (!$restricted_to) {
                $ancestors = array_reverse((array) get_post_ancestors(bbp_get_forum_id()));
                if (!empty($ancestors)) {
                    // Loop through parents
                    foreach ((array) $ancestors as $parent_id) {
                        $restricted_to = edd_cr_is_restricted($parent_id);
                        if ($restricted_to) {
                            break;
                        }
                    }
                }
            }
        }
        $has_access = edd_cr_user_can_access($user_ID, $restricted_to);
        if ($has_access['status']) {
            $retval = true;
        }
    }
    return $retval;
}
Пример #6
0
/**
 * Filter content to handle restricted posts/pages
 *
 * @since       1.0.0
 * @param       string $content The content to filter
 * @global      object $post The post we are editing
 * @return      string $content The filtered content
 */
function edd_cr_filter_content($content)
{
    global $post;
    // If $post isn't an object, we aren't handling it!
    if (!is_object($post)) {
        return $content;
    }
    $restricted = edd_cr_is_restricted($post->ID);
    if ($restricted) {
        $content = edd_cr_filter_restricted_content($content, $restricted, null, $post->ID);
    }
    return $content;
}