示例#1
0
function ihc_hide_content_shortcode($meta_arr = false, $content = '')
{
    ///GETTING USER TYPE
    $current_user = ihc_get_user_type();
    if ($current_user == 'admin') {
        return $content;
    }
    //admin can view anything
    if (isset($meta_arr['ihc_mb_who'])) {
        if ($meta_arr['ihc_mb_who'] == -1) {
            $meta_arr['ihc_mb_who'] = '';
        }
        //-1 means no value selected
        $target_users = explode(',', $meta_arr['ihc_mb_who']);
    } else {
        return do_shortcode($content);
    }
    ////TESTING USER
    $block = ihc_test_if_must_block($meta_arr['ihc_mb_type'], $current_user, $target_users);
    //IF NOT BLOCKING, RETURN THE CONTENT
    if (!$block) {
        return do_shortcode($content);
    }
    //LOCKER HTML
    if (isset($meta_arr['ihc_mb_template'])) {
        include_once IHC_PATH . 'public/locker-layouts.php';
        return ihc_print_locker_template($meta_arr['ihc_mb_template']);
    }
    //IF SOMEHOW IT CAME UP HERE, RETURN CONTENT
    return do_shortcode($content);
}
示例#2
0
    return $str;
}
//////////LIST POSTS - FILTER REMOVE POSTS THAT HAS A REDIRECT BLOCK
add_filter('pre_get_posts', 'ihc_filter_query_list_posts', 999);
function ihc_filter_query_list_posts($query)
{
    if (!$query->is_single && !$query->is_page) {
        $current_user = ihc_get_user_type();
        if ($current_user == 'admin') {
            return $query;
        }
        //show all to admin
        ///
        global $wpdb;
        $post_list = $wpdb->get_results('SELECT DISTINCT post_id
											FROM ' . $wpdb->prefix . 'postmeta
											WHERE meta_key = "ihc_mb_block_type"
											AND meta_value = "redirect"
										;');
        if ($post_list && count($post_list)) {
            $exclude = array();
            foreach ($post_list as $obj) {
                if (isset($obj->post_id) && $obj->post_id) {
                    $result = $wpdb->get_results('
														SELECT * FROM ' . $wpdb->prefix . 'postmeta
														WHERE post_id = ' . $obj->post_id . '
														AND ( meta_key = "ihc_mb_type"
														OR meta_key = "ihc_mb_who") LIMIT 2
												;');
                    $for = false;
                    $type = false;
                    foreach ($result as $obj2) {
                        ///
                        if ($obj2->meta_key == 'ihc_mb_who') {
                            $for = $obj2->meta_value;
                        } elseif ($obj2->meta_key == 'ihc_mb_type') {
                            $type = $obj2->meta_value;
                        }
                    }
                    if ($for && $type) {
                        $for = explode(',', $for);
                        $block = ihc_test_if_must_block($type, $current_user, $for);
                        if ($block) {
                            $exclude[] = $obj->post_id;
示例#3
0
                $subscription_link = get_permalink($subscription_pid);
                if ($subscription_link) {
                    wp_redirect($subscription_link);
                    exit;
                }
            }
        }
    }
}
function ihc_block_page_content($postid, $url)
{
    /*  
	 * test if current post, page content must to blocked
	 */
    $meta_arr = ihc_post_metas($postid);
    if (isset($meta_arr['ihc_mb_block_type']) && $meta_arr['ihc_mb_block_type']) {
        if ($meta_arr['ihc_mb_block_type'] == 'redirect') {
            /////////////////////// REDIRECT
            if (isset($meta_arr['ihc_mb_who'])) {
                //getting current user type and target user types
                $current_user = ihc_get_user_type();
                if ($meta_arr['ihc_mb_who'] == -1) {
                    $meta_arr['ihc_mb_who'] = '';
                }
                //-1 means no value selected
                $target_users = explode(',', $meta_arr['ihc_mb_who']);
                //test if current user must be redirect
                if ($current_user == 'admin') {
                    return;
                }
                //show always for admin
                $redirect = ihc_test_if_must_block($meta_arr['ihc_mb_type'], $current_user, $target_users);
                if ($redirect) {
                    //getting default redirect id
                    $default_redirect_id = get_option('ihc_general_redirect_default_page');
                    //PREVENT INFINITE REDIRECT LOOP - if current page is default redirect page return
                    if ($default_redirect_id == $postid) {
                        return;
                    }
                    if (isset($meta_arr['ihc_mb_redirect_to']) && $meta_arr['ihc_mb_redirect_to'] != -1) {
                        $redirect_id = $meta_arr['ihc_mb_redirect_to'];
                        //redirect to value that was selected in meta box
                        //test if redirect page exists
                        if (get_post_status($redirect_id)) {
                            $redirect_link = get_permalink($redirect_id);
                        } else {
                            //if not exists go to homepage
                            $redirect_link = home_url();
                        }
                    } else {
                        if ($default_redirect_id && $default_redirect_id != -1) {
                            if (get_post_status($default_redirect_id)) {
                                $redirect_link = get_permalink($default_redirect_id);
                                //default redirect page, selected in general settings
                            } else {
                                $redirect_link = home_url();
                            }
                        } else {
                            $redirect_link = home_url();
                            //if default redirect page is not set, redirect to home
                        }
                    }
                    if ($url == $redirect_link) {
                        return;
                    }