• Hi.

    I have a problem with category visibility.
    I setup following structure:

    A – public category (no restrictions)
    B – for logged users only

    I’m posting to:

    Cat. A – everybody can see it OK!
    Cat. B – only logged users can see it OK!
    Cat. A & B – only logged users can see it WHY?

    I thought everybody would be able to see posts that were posted to ‘public’ category regardless the fact they were marked for other ones (even protected). I would like to be able to post some posts for my logged users (to cat. B) and others for both. They should be visible for all visitors using cat. A & cat. B. I don’t want to force logged users to follow two categories.

    I’ve been using WP for last two weeks than maybe my question is stupid however I want to ask if there is any way I can achieve such behaviour?

    Ty in advance for all help.

    Best regards.
    Micha?

    https://www.ads-software.com/plugins/contexture-page-security/

Viewing 1 replies (of 1 total)
  • Thread Starter mkupis

    (@mkupis)

    Hi.

    Sorry for answering my own post but maybe somebody will make a use of it.

    I managed to change this behaviour myself. It seems to work fine. It requires only few changes in core\queries.php:

    /**
         * Checks whether a post is using a protected term.
         *
         * @param int $post_id The pos to check.
         * @return bool Returns true if post contains a protected term.
         */
        public static function check_post_term_protection($post_id){
    
            //initialize variables
            $terms = self::get_post_terms($post_id);
    
    		//return false if no terms assigned
    		if(empty($terms)) {
    			return false;
    		}
    
            //wp_die(print_r($terms,true)); //TEST
    
            //$ancestor_protected = false; //DISABLED
    
            foreach($terms as $term){
    
                if(!get_metadata('term',$term->term_id,'ctx_ps_security')){
                    return false;
                }else{
                    if( $term->parent!=0 ){
                        if(!self::check_term_protection($term->parent))
                            //$ancestor_protected = true;  //DISABLED
                            return false;
                    }
                }
            }
    
            //If any ancestor terms are protected, return true
            //if($ancestor_protected)  //DISABLED
            //    return true;  //DISABLED
    
            //If no protection flags were triggered, return false
            return true;
        }

    and:

    /**
         * Recursively checks security for this term and it's ancestors. Returns true
         * if any of them are protected or false if none of them are protected.
         *
         * @global wpdb $wpdb
         * @param int $term_id The id of the term to check security for.
         * @param string $taxonomy The name of the taxonomy the term belongs to.
         * @param bool $recursive Set to false to disable the checking of ancestors. (Default: true)
         *
         * @return bool If this page or it's ancestors has the "protected page" flag
         */
        public static function check_term_protection($term_id,$taxonomy=null,$recursive=true){
            global $wpdb;
    
            if(!get_metadata('term',$term_id,'ctx_ps_security')){
                return false;
            } else if($recursive) {
                //If taxonomy isnt set and we're using term id, try to get it
                if(empty($taxonomy) && is_numeric($term_id))
                    $taxonomy = self::get_term_taxonomy($term_id);
    
                //If term has no protection, check parents
                $parent_id = get_term($term_id,$taxonomy);
                $parent_id = $parent_id->parent;
                if ($parent_id != 0)
                    return self::check_term_protection($parent_id,$taxonomy);
                else
                    return true;
            }else{
                //Recursive is false and no protection
                return true;
            }
        }

    It’s opposite to original behaviour. As long as any of category is available for reading user can see content.

    Would You consider including a switch that can be used, to define expected behaviour? Ty in advance.

    Regards.
    Micha?

Viewing 1 replies (of 1 total)
  • The topic ‘Empty 'public' category.’ is closed to new replies.