GM-Alex / user-access-manager

Official mirror of https://plugins.svn.wordpress.org/user-access-manager/
39 stars 18 forks source link

UAM & Default-Widget : n last published articles #246

Open Trebly opened 6 years ago

Trebly commented 6 years ago

Hi,

Again a problem found to get a good application. The problem is to hide into several widgets the links to the articles which have a visibility full locked by UAM for the current user.

This is URGENT.

When you use a "Widget : n last published articles" without special development the titles of articles (or any optional element) remain visible even the visibility of the full article is locked for the current user.

The problem comes from the WP-query of these widgets, like this code:

        /**
         * Filters the arguments for the Recent Posts widget.
         *
         * @since 3.4.0
         * @since 4.9.0 Added the `$instance` parameter.
         *
         * @see WP_Query::get_posts()
         *
         * @param array $args     An array of arguments used to retrieve the recent posts.
         * @param array $instance Array of settings for the current widget.
         */
        $r = new WP_Query( apply_filters( 'widget_posts_args', array(
            'posts_per_page'      => $number,
            'no_found_rows'       => true,
            'post_status'         => 'publish',
            'ignore_sticky_posts' => true,
        ), $instance ) );

Explanation With this you get with $number=5 the last more recent 5 posts. If in these post there are posts which have a locked access by UAM you will nevertheless see them. You can add a test into the loop to not display an hidden article checking is_uam_access ($post) == true, but this can have the result : "no element to display" if the visibility of the last 5 posts is locked for the current user. The true question of the user which uses the widget is "what are the last 5 visible articles for me (current user)".

For this I must change the query so that it will return the last 5 visible ( articles for which is_uam_access ($post) == true), Alex what must be the right code ?

Do it exist a filter to do the same ? : add to "WP-query" the if(is_uam_access ($post) == true)

Best regards

Trebly


Note1 : I load UAM as first plugin Note2 : This problem is for all widgets of same type

Trebly commented 6 years ago

Alex,

It seam that the alone solution is to add to WP-query a "where" SQL clause by using a filter on WP-query.

This filter must define as main parameter (and send to WP-query) the "where clause" of the is_uam_access UAM function.

How can I get this "where" clause from UAM ?

Best regards

Trebly


note: temporarily I filter the display of links using is_uam_access. The result is that the visitors and subcribers get an empty list... most of time because articles which are in review are not accessible...