Exemplo n.º 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;
}
/**
 * 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);
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
/**
 * Filter restricted content
 *
 * @since       1.0.0
 * @param       string $content The content to filter
 * @param       array $restricted The items to which this is restricted
 * @param       string $message The message to display to users
 * @param       int $post_id The ID of the current post/page
 * @param       string $class Additional classes for the displayed error
 * @global      int $user_ID The ID of the current user
 * @return      string $content The content to display to the user
 */
function edd_cr_filter_restricted_content($content = '', $restricted = false, $message = null, $post_id = 0, $class = '')
{
    global $user_ID;
    // If the current user can edit this post, it can't be restricted!
    if (!current_user_can('edit_post', $post_id) && $restricted) {
        $has_access = edd_cr_user_can_access($user_ID, $restricted, $post_id);
        if ($has_access['status'] == false) {
            if (!empty($message)) {
                $has_access['message'] = $message;
            }
            $content = '<div class="edd_cr_message ' . $class . '">' . $has_access['message'] . '</div>';
        }
    }
    return do_shortcode($content);
}