Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for role-assignment problem... :-) #58

Open
chrisi-taylor opened this issue Dec 1, 2023 · 1 comment
Open

Fix for role-assignment problem... :-) #58

chrisi-taylor opened this issue Dec 1, 2023 · 1 comment

Comments

@chrisi-taylor
Copy link

chrisi-taylor commented Dec 1, 2023

There is a problem with the role assignment:
If $amp_default_role is set, all logged in users are assigned to this default_role,
no matter if there is an entry for the user in the $amp_role_assignment-array.
As stated in the previous published issues this seems not to be a consistent behaviour.

I tried to get down to the problem and found a solution.

Change the following lines in plugin.php: 271-278 in the following way:

                if ( amp_user_is_assigned ( $user ) )
                {
                    foreach ( $amp_role_capabilities as $rolename => $rolecaps )
                    {
                        if ( amp_user_has_role( $user, $rolename ) ){
                                    $user_caps = array_merge( $user_caps, $rolecaps );
                        }
                    }
                }
                elseif ( isset( $amp_default_role )  &&
                         in_array ($amp_default_role, array_keys( $amp_role_capabilities ) ))
                         {
                            $user_caps = $amp_role_capabilities [ $amp_default_role ];
                         }

The introduced brackets are imminent important!
The bracket in the line before the elseif makes the difference!
It assigns the elseif to the if-statement in line 271!
Without the bracket it depends on the version of your php interpreter how the elseif is assigned...
Some php interpreters (I presume the older ones) handle this assignment as described above...
Others (newer ones perhaps) seem to loose track and handle the elseif as a normal if-statement
without assignment due to missing brackets...

Regards

@UTCGilligan
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants