• Resolved knijia

    (@knijia)


    Hello,
    i’ve created a custom post type called “videos”. I’ve created a group called “family”, only allowed to see certain content of that custom post type. Other users not in this group have no access at all (hide page & hide post in uam parameters).
    When i’m in the archive page of that custom post, the admin can see all of the 9 posts per page i’ve set in the wordpress parameters. But another user who is in the “family restricted access group” can see only 2 or 3 of the 9 videos per page he’s allowed to see.
    My problem is that i wish i could have all the videos the user is allowed to see in the same pages and not as if it was only hiding it because it creates pages with only one video at page 1, 3 videos at page 2, no videos at page 3 and 4 videos at page 4, for example.
    I hope this is clear enough for someone to help me.
    Thanks !

    https://www.ads-software.com/extend/plugins/user-access-manager/

Viewing 5 replies - 1 through 5 (of 5 total)
  • davoron

    (@davoron)

    Hi,

    which version of the Plugin are you using?

    I have the same problem on the search page and it took my hours to figure out what the problem is.

    I have broke it down to the “the_posts” Filter and the “showPost” Callback.

    The Problem is that the Plugin, in Version 1.1.4 which I use. removes the posts AFTER doing the database query.

    And with pagination, the query limits the amount of posts returned from the database. So if we ask for 10 posts per page, but the plugin removes all of them because we do not have the right to see them, we get a plank Page.

    What the plugin SHOULD do is to check your access-groups and exclude all Posts from the Database query the current user has no rights to see before they are delivered.

    By doing that, we get ONLY the posts that are meant to be showed and the pagination and all should work fine.

    There are hooks for that AND the Plugin actually has a hook and a Filter in place to do something like that.

    The “showPostSql” Method of the UserAccessManager does check for Posts that should be excluded BUT the method it’s depending on to do it ‘getExcludedPosts’ does return nothing.

    arjenbreur

    (@arjenbreur)

    I had the same (or similar?) problem.
    After restricting content for users through User Access Manager, the pagination isn’t functioning correctly. While my frontpage is set to 10 posts per page, some users get to see less or even no posts.

    Davoron pinpointed the problem precisely: 10 posts are retrieved from the database, but before they are shown, the restricted posts are filtered out, leaving less or no posts to show.

    The main query should already leave out the restricted posts. I added a filter to achieve this.

    But that’s not all. There is also a problem with the method ‘getPostsForUser‘. It is only retrieving posts of the type ‘post’. That needs to be fixed too, in order to have pagination work with custom post types.
    Sidenote: Big thanks to Davonon, for pointing me in the right direction: ‘getExcludedPosts‘ isn’t returning any posts (at least not in the case of this issue), but that is because it relies on the faulty getPostsForUser.

    I fixed this problem by changing the plugins code in several places.

    Add this to class/UamAccessHandler.class.php:

    /**
         * MY FIX TO MAKE PAGINATION WORK WITH CUSTOM POST TYPES
         *
         * @param arrray $query The query object
         *
         * @return void, $query is passed by refecence
         */
    	function AB_pre_get_posts( $query ) {
    	    if ( is_admin() || ! $query->is_main_query() )
    	        return;
    
            $uamAccessHandler = &$this->getAccessHandler();
    
    		$usersPosts = $uamAccessHandler->getPostsForUser();
    		$query->query_vars['post__in'] = array_merge(
    			$query->query_vars['post__in'],
    			$usersPosts
    		);
    		return;
    	}

    Trigger this method by adding a hook in user-access-manager.php, around line 340:

    //MY FIX TO MAKE PAGINATION WORK WITH CUSTOM POST TYPES
            add_filter('pre_get_posts', array(&$userAccessManager, 'AB_pre_get_posts'));

    Now we only need to change the faulty getPostsForUser method by changing class/UamAccessHandler.class.php. Find the method (around line 530), and change the following code:

    // MY FIX TO MAKE PAGINATION WORK WITH CUSTOM POST TYPES
    // REMOVED:
    //         $postAssignedToUserSql = "
    //         	 SELECT igp.object_id
    //         	 FROM ".DB_ACCESSGROUP_TO_OBJECT." AS igp
    //         	 WHERE igp.object_type = 'post'
    //          AND igp.group_id IN (".$userUserGroupString.")";
    // ADDED:
            $postableTypes = $this->getPostableTypes();
            $postableTypesString = "'".implode("','", $postableTypes)."'";
            $postAssignedToUserSql = "
            	 SELECT igp.object_id
            	 FROM ".DB_ACCESSGROUP_TO_OBJECT." AS igp
            	 WHERE igp.object_type IN ( ".$postableTypesString." )
             AND igp.group_id IN (".$userUserGroupString.")";

    For me this did the trick. Be aware that on an update of the plugin, these changes will be lost (although hopefully the problem might be fixed by the update). Hope it works for others too!

    Plugin Author GM_Alex

    (@gm_alex)

    Thanks for report and the fix, will be fixed in the next version.

    Plugin Author GM_Alex

    (@gm_alex)

    Fixed in version 1.2.4.2.

    Thread Starter knijia

    (@knijia)

    <3 !

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: User Access Manager] Pagination problem when user isn't allowed to see some content’ is closed to new replies.