示例#1
0
function pc_pvt_content_shortcode($atts, $content = null)
{
    extract(shortcode_atts(array('allow' => 'all', 'block' => '', 'warning' => '1', 'message' => ''), $atts));
    $custom_message = $message;
    // if nothing is specified, return the content
    if (trim($allow) == '') {
        return do_shortcode($content);
    }
    include_once PC_DIR . '/functions.php';
    // MESSAGES
    // print something only if warning is active
    if ($warning == '1') {
        // switch for js login system
        $js_login = !get_option('pg_js_inline_login') ? '' : ' - <span class="pc_login_trig pc_trigger">' . __('login', 'pc_ml') . '</span>';
        // prepare the message if user is not logged
        $message = '<div class="pc_login_block"><p>' . pc_get_message('pc_default_nl_mex', $message) . $js_login . '</p></div>';
        // prepare message if user has not the right category
        $not_has_level_err = '<div class="pc_login_block"><p>' . pc_get_message('pc_default_uca_mex', $message) . '</p></div>';
    } else {
        $message = '';
        $not_has_level_err = '';
    }
    $response = pc_user_check($allow, $block, $wp_user_pass = true);
    if ($response === 1) {
        return do_shortcode($content);
    } elseif ($response === 2) {
        return $not_has_level_err;
    } else {
        // if has to be show to unlogged users return only custom message
        if ($allow == 'unlogged') {
            return !empty($custom_message) ? '<div class="pc_login_block"><p>' . $custom_message . '</p></div>' : '';
        }
        $login_form = isset($js_login) && $js_login ? '<div class="pc_inl_login_wrap" style="display: none;">' . pc_login_form() . '</div>' : '';
        return $message . $login_form;
    }
}
function pc_menu_filter($items)
{
    $new_items = array();
    // full website lock
    if (get_option('pg_complete_lock') && pc_user_check('all', '', true) !== 1) {
        return $new_items;
    }
    foreach ($items as $item) {
        if (isset($item->menu_item_parent) && $item->menu_item_parent) {
            $parent_check = pc_single_menu_check($items, $item->menu_item_parent);
        } else {
            $parent_check = true;
        }
        if ($parent_check) {
            // if allowed users array exist
            if (isset($item->pc_hide_item) && is_array($item->pc_hide_item)) {
                $allowed = implode(',', $item->pc_hide_item);
                if (pc_user_check($allowed, '', true) === 1) {
                    $new_items[] = $item;
                }
            } else {
                $new_items[] = $item;
            }
        }
    }
    return $new_items;
}
function pc_do_widget_restriction($sidebars_widgets)
{
    $filtered_widgets = $sidebars_widgets;
    // in frontend and only if WP user functions are registered
    if (!is_admin() && defined('PC_WP_USER_PASS')) {
        if (!isset($GLOBALS['pc_widget_control_opts'])) {
            $GLOBALS['pc_widget_control_opts'] = array();
        }
        $stored = $GLOBALS['pc_widget_control_opts'];
        foreach ($sidebars_widgets as $widget_area => $widget_list) {
            if ($widget_area == 'wp_inactive_widgets' || empty($widget_list)) {
                continue;
            }
            foreach ($widget_list as $pos => $widget_id) {
                if (isset($stored[$widget_id])) {
                    $opt = $stored[$widget_id];
                } else {
                    $opt = get_option('pg_widget_control_' . $widget_id);
                    $GLOBALS['pc_widget_control_opts'][$widget_id] = $opt;
                }
                if ($opt) {
                    if (isset($opt['allow']) && is_array($opt['allow']) && count($opt['allow'])) {
                        $val = implode(',', $opt['allow']);
                        if (pc_user_check($val, $blocked = '', $wp_user_pass = true) !== 1) {
                            unset($filtered_widgets[$widget_area][$pos]);
                        }
                    }
                }
            }
        }
    }
    return $filtered_widgets;
}
示例#4
0
function pg_user_check($allowed = 'all', $blocked = '')
{
    return pc_user_check($allowed, $blocked);
}