Skip Navigation

[Resolved] Problem with read access

This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 7 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#517553

When trying to display a menu, with toolset access enabled, it checks to see if the content for a menu item is readable by the current user.

This check is done in Access_helper::toolset_access_api_get_post_permissions_process()

It reaches this part of the code

        //If settings set and post type managed by Access
        if ( isset($types_settings[$post_type]) && $types_settings[$post_type]['mode'] == 'permissions' && isset($types_settings[$post_type]['permissions'][$option_name]['roles']) ){
            if ( in_array($role, $types_settings[$post_type]['permissions'][$option_name]['roles']) !== FALSE ){
                return true;
            }else{
                return false;
            }
        }

        //If settings set and post not type managed by Access

        elseif ( (isset($types_settings[$post_type]) && $types_settings[$post_type]['mode'] != 'permissions' && isset($types_settings['post']) && $types_settings[$post_type]['mode'] == 'permissions') ||
            ( !isset($types_settings[$post_type]) && isset($types_settings['post']) && $types_settings['post']['mode'] == 'permissions' )  ){
            if ( isset($types_settings['post']['permissions'][$option_name]['roles']) && in_array($role, $types_settings['post']['permissions'][$option_name]['roles']) !== FALSE ){
                return true;
            }else{
                return false;
            }
        }
        //Use role capabilities
        else{  /* It ends up HERE */
            if ( $role == 'guest'  ){
                if ( $option_name == 'read' ){
                    return true;
                }else{
                    return false;
                }
            }

            $role_caps = $wp_roles->roles;
            if ( isset( $role_caps[$role]['capabilities'][$converted_caps[$option_name]] ) ){
                return true;
            }else{
                return false;
            }
        }

and ends up in the last 'else' (I added the comment with 'It ends up HERE) and $option_name == 'read'. For people logged in is ends up checking $role_caps, but 'read' is a standard WP capability for reading the dashboard (not content).

It seems to me the last part of the code should read

        else{
            if ( $option_name == 'read' ){
                  return true;
             }

             if ( $role == 'guest'  ){
                return false;
             }

            $role_caps = $wp_roles->roles;
            if ( isset( $role_caps[$role]['capabilities'][$converted_caps[$option_name]] ) ){
                return true;
            }else{
                return false;
            }
        }

I have got around the issue by enabling types access for the pages content type.

#517696

Dear Steve,

I assume we are talking about the PHP source code of Access plugin, file \types-access\includes\Helper.php, line 634~640:

            if ( $role == 'guest'  ){
                if ( $option_name == 'read' ){
                    return true;
                }else{
                    return false;
                }
            }

And you are right, the 'read' is a standard WP capability for reading the dashboard (not content).
https://codex.wordpress.org/Roles_and_Capabilities#read

Could you describe detail steps to duplicate same problem?
What is the issue you have got around?
Are we talking about the problem: some specific posts/pages should be display in the wordpress menus for guest users? how do you setup the access settings in the post/page?

#517963

Yes, this about menu items. The menu has some items to reference pages and also other items.

The menu displays correctly for people logged in and people who are administrators.

It was not displaying correctly to other people logged in, the menu items for pages were not displaying. Initially I was not using types access to control access to the page content type and none of the pages in question have individual access controls.

So initially these users were falling through to the 'else' clause and the code used the $role_caps to check for read access which failed since these people do not have access to the dashboard.

At this point I have enabled types access control for the page content type and set it so these users can read the content. This resolves the issue since now these users no longer fall through to the 'else' clause.

#518131

I still need detail steps to duplicate same problem, I just tested below steps in my localhost, but can not duplicate same problem, please correct me if there is anything missing:
1) Install Access plugin 2.3.1 in a fresh wordpress installation
2) Dashboard-> Toolset-> Access Control-> Post Types
Enable option "Managed by Access" for post type "Page"
3) Create a page, and add it into main menu
4) Test it in front-end with an "subscriber" user, it works fine, and does display the page in the menu
5) Dashboard-> Toolset-> Access Control-> Post Types
Disable option "Managed by Access" for post type "Page", it works fine too.