Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.
This repository was archived by the owner on May 19, 2025. It is now read-only.

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

@chrisi-taylor

Description

@chrisi-taylor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions