• Resolved Dane Morgan

    (@dane-morgan)


    Hi. I needed to restrict access to a custom post type page in a plugin that was using quite a bit of custom meta to display various parts of the page, so simply filtering the content wasn’t getting it done.

    I modified the user_specific_content_filter() to create a bausp_user_is_allowed() conditional check. I went wrong somewhere because the filter seems to allow for admin users to see the content, but this does not.

    I’d love to see this kind of conditional template tag rolled in to the plugin. What I added is as follows

    public function bausp_user_is_allowed() {
    		global $post;
    		global $user;
    		global $current_user;
    		$savedoptions = get_post_meta($post->ID, 'U_S_C_options',true);
    		$m = get_post_meta($post->ID, 'U_S_C_message',true);
    		if (isset($savedoptions) && !empty($savedoptions)){
    			// none logged only
    			if (isset($savedoptions['non_logged']) && $savedoptions['non_logged'] == 1){
    				if (is_user_logged_in()){
    					echo 'is_user_logged_in()';
    					return false;
    				}
    			}
    			//logged in users only
    			if (isset($savedoptions['logged']) && $savedoptions['logged'] == 1){
    				if (!is_user_logged_in()){
    					echo 'failed !is_user_logged_in()';
    					return false;
    				}
    			}
    		}
    		$savedroles = get_post_meta($post->ID, 'U_S_C_roles',true);
    		$run_check = 0;
    		$savedusers = get_post_meta($post->ID, 'U_S_C_users',true);
    		if (!count($savedusers) > 0 && !count($savedroles) > 0 ){
    			return true;
    			exit;
    		}
    		//by role
    		if (isset($savedroles) && !empty($savedroles)){
    			get_currentuserinfo();
    			$cu_r = $this->bausp_get_current_user_role();
    			if ($cu_r){
    				if (in_array($cu_r,$savedroles)){
    					return true;
    					exit;
    				}else{
    					$run_check = 1;
    				}
    			}else{
    				//failed role check
    				$run_check = 1;
    			}
    		}
    		//by user
    		if (isset($savedusers) && !empty($savedusers)){
    			get_currentuserinfo();
    			if (in_array($current_user->ID,$savedusers)){
    				return true;
    			}else{
    				$run_check = $run_check + 1;
    			}
    			//failed both checks
    			echo 'failed both checks';
    			return false;
    		}
    		if ($run_check > 0){
    			echo 'failed $run_check > 0';
    			return false;
    		}
    		return true;
    	}

    http://wordpress.org/plugins/user-specific-content/

Viewing 1 replies (of 1 total)
  • Plugin Author Bainternet

    (@bainternet)

    In the next update the plugin is registered as a global variable so you can use the user_specific_content_filter method with any content you would like, eg:

    ob_start();
    //your content
    //+ meta data
    //+ what ever you wish to limit for specific users or roles
    global $U_S_C_i;
    echo $U_S_C_i->user_specific_content_filter(ob_get_clean());

Viewing 1 replies (of 1 total)
  • The topic ‘Add Conditional check function’ is closed to new replies.