Ejemplo n.º 1
0
function ihc_filter_content($content)
{
    //GETTING POST META
    global $post;
    if ($post == FALSE || !isset($post->ID)) {
        return do_shortcode($content);
    }
    $meta_arr = ihc_post_metas($post->ID);
    if ($meta_arr['ihc_mb_block_type'] == 'redirect') {
        return do_shortcode($content);
    }
    ///this extra check it's for ihc_list_posts_filter(),
    ///GETTING USER TYPE
    $current_user = ihc_get_user_type();
    if ($current_user == 'admin') {
        return do_shortcode($content);
    }
    //show always for admin
    // who can access the content
    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);
    }
    // REPLACE CONTENT
    if (isset($meta_arr['ihc_replace_content'])) {
        $meta_arr['ihc_replace_content'] = stripslashes($meta_arr['ihc_replace_content']);
        $meta_arr['ihc_replace_content'] = htmlspecialchars_decode($meta_arr['ihc_replace_content']);
        $meta_arr['ihc_replace_content'] = ihc_format_str_like_wp($meta_arr['ihc_replace_content']);
        return do_shortcode($meta_arr['ihc_replace_content']);
    }
    //IF SOMEHOW IT CAME UP HERE, RETURN CONTENT
    return do_shortcode($content);
}
<?php

//return html meta boxes for admin section
global $post;
$meta_arr = ihc_post_metas($post->ID);
?>
<div class="ihc-class ihc-padding">
	<select class="ihc-fullwidth ihc-select" name="ihc_mb_type">
		<option value="show" <?php 
if ($meta_arr['ihc_mb_type'] == 'show') {
    echo 'selected';
}
?>
 ><?php 
_e('Show Page Only', 'ihc');
?>
</option>
		<option value="block" <?php 
if ($meta_arr['ihc_mb_type'] == 'block') {
    echo 'selected';
}
?>
 ><?php 
_e('Block Page Only', 'ihc');
?>
</option>
	</select>
</div>

<div style="margin:4px 0;">
	<div  class="ihc-padding"  style="text-align:right; margin-bottom:10px;">
Ejemplo n.º 3
0
function ihc_save_post_meta($post_id)
{
    $meta_arr = ihc_post_metas($post_id, true);
    foreach ($meta_arr as $k => $v) {
        if (isset($_REQUEST[$k])) {
            update_post_meta($post_id, $k, $_REQUEST[$k]);
        }
    }
    //default pages
    if (isset($_REQUEST['ihc_set_page_as_default_something']) && $_REQUEST['ihc_set_page_as_default_something'] != -1 && isset($_REQUEST['ihc_post_id'])) {
        $meta_name = $_REQUEST['ihc_set_page_as_default_something'];
        if (get_option($meta_name) !== FALSE) {
            update_option($meta_name, $_REQUEST['ihc_post_id']);
        } else {
            add_option($meta_name, $_REQUEST['ihc_post_id']);
        }
    }
}
Ejemplo n.º 4
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;
                    }