Support

Account

Home Forums Backend Issues (wp-admin) Groups not showing for non-admin users Reply To: Groups not showing for non-admin users

  • Hi John,
    thank you very much for your efforts, here is the hole part, hope you can help 🙂

    /* CUSTOM CITYGUIDE FUNCTIONS */
    function isCityguideUser($wp_roles = array()){
    	$result = false;
    	if(count($wp_roles) == 0){
    		$wp_user = wp_get_current_user();
    		$wp_roles = $wp_user->roles;
    	}
    	foreach ($wp_roles as $index => $role) {
    		if(strpos($role, 'cityguide_') !== false){
    			$result = true;
    		}
    	}
    	return $result;
    }
    
    /*****************************************************************************/
    /****** PLEASE KEEP HERE ONLY CODE WHICH IS COMON FOR ALL GUIDE THEMES *******/
    /******** CUSTOM pre_get_posts FILTERS ARE IN ait-custom-functions.php ********/
    /*****************************************************************************/
    function altered_search($query) {
    	if($query->is_admin) {
    		// hotfix - wordpress consider all ajax calls as is_admin call
    		// on fronend logged users could see only their items/events
    		// TODO: replace by filter where I can register all custom ajax actions/handlers
    		if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'get-items:getHeaderMapMarkers') {
    			return $query;
    		}
    
    		if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'get-items:retrieve') {
    			return $query;
    		}
    
    		/* Display posts in admin for current user only */
    		$wp_user = wp_get_current_user();
    		if(isCityguideUser($wp_user->roles)){
    			$query->set('author', $wp_user->data->ID);
    		}
    		
    	} else {
    		if($query->is_main_query()){
    			if (isset($_GET['s']) && empty($_GET['s'])){
    				$query->is_search = true;
    			
    			}
    
    			// is woocommerce search
    			if(isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'product'){
    			
    				return $query;
    			}
    			
    		
    			$query = apply_filters( 'ait_alter_search_query', $query );
    			
    			
    		}
    	}
    	return $query;
    }
    add_filter('pre_get_posts', 'altered_search');