Filter by category just for unlogged users (1 post)

  1. nutsmuggler
    Posted 9 years ago #

    I am building a plugin that uses a 'Confidential' category for the exchange of internal infos between logged users. Unlogged users are not supposed to see that the confidential posts exists. Conversely, logged users can access to confidential posts from the dashboard.
    Now, I have managed to prevent confidential posts from displaying.
    Here are the filtering functions:

    // Filter posts in the Confidential category
    function dbmod_filter_cp_join($join) {
    global $wpdb;
    if (strstr($join,"JOIN $wpdb->post2cat ON (is_posts.ID = is_post2cat.post_id)")) {
    return ($join);
    } else {
    return ($join." LEFT JOIN $wpdb->post2cat ON (is_posts.ID = is_post2cat.post_id)");
    function dbmod_filter_cp_where($where) {
    global $confidential_cat, $wpdb;
    return ($where." AND $wpdb->post2cat.category_id !='"."$confidential_cat"."'");
    /// Excludes confidential category from category lists
    function dbmod_exclude_cc_from_list($content, $category = null) {
    global $confidential_cat;
    if ($category->cat_ID == "$confidential_cat") {
    return ('');

    } else if ($category == null) {
    return $content;
    else {
    return $content;
    add_filter('posts_where', 'dbmod_filter_cp_where');
    add_filter('list_cats', 'dbmod_exclude_cc_from_list', 10, 2);

    There is a problem with these functions. Logged-in users can see the post titles (in my tweaked dashboard) but they can't see the pages. The filter prevents the post from displaying.
    I should add an if statement that disable the filtering if
    1) The user is logged-in
    2) the confidential post is being loaded IN A SINGLE PAGE
    How do I detect these points?
    Any suggestion is welcome.

Topic Closed

This topic has been closed to new replies.

About this Topic