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

Incorrectly handled "Add User" for with multisite setup #179

Closed
terrance-orletsky-d7 opened this issue May 19, 2021 · 6 comments
Closed
Assignees
Labels
Milestone

Comments

@terrance-orletsky-d7
Copy link

terrance-orletsky-d7 commented May 19, 2021

GIVEN
AAM is installed,
Premium/ complete package,
and the WP site is a multisite subdomain installation:

WHEN
An Admin user tries to add a new user to a site

THEN
The 'Role' dropdown is missing from the lower form,
and the user is added with no role


EXPECTED BEHAVIOUR:

THEN
The 'Role' dropdown (or multiselect) is available,
and the Admin is able to select a role(s) for the new user being added
and the user is added with that/those role(s)


Incidentally, in the upper form, there are two ways to select (multiselect, and a dropdown), so my guess is that the dropdown was meant to be replaced in the second form as well, but it was not replaced properly

@terrance-orletsky-d7
Copy link
Author

terrance-orletsky-d7 commented May 19, 2021

@vasyltech @aamplugin Here is a screenshot of the issue:

Fullscreen_2021-05-19__7_50_AM

@terrance-orletsky-d7
Copy link
Author

This appears to be caused by the file: wp-content/plugins/advanced-access-manager/application/Backend/tmpl/user/multiple-roles.php

As you can see below, this file modifies the add-user page, but does not consider 'multi-site' installs, and the two forms that multisite presents on that admin page.

Here is the markup of the page that is affected - you can see that:

  1. the lower form has the select section with the ID 'role', so the selectbox is being removed from there, and not from the top form, which has different markup and id's

2 the new role selection is being added to the upper form only, not the lower one

<div class="wrap">
<h1 id="add-new-user">
Add New User</h1><div class="notice updated is-dismissible"><p>Hey, we noticed that you are in a multi-site network. Glossary now supports WordPress multi-site feature!<br>Please, read our <a href="http://docs.codeat.co/glossary/faq/#are-you-compatible-with-wordpress-multisite">documentation</a>.</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></div>


<div id="ajax-response"></div>

<h2 id="add-existing-user">Add Existing User</h2><p>Enter the email address or username of an existing user on this network to invite them to this site. That person will be sent an email asking them to confirm the invite.</p><form method="post" name="adduser" id="adduser" class="validate" novalidate="novalidate">
<input name="action" type="hidden" value="adduser">
	<input type="hidden" id="_wpnonce_add-user" name="_wpnonce_add-user" value="e0886d542b"><input type="hidden" name="_wp_http_referer" value="/wp-admin/user-new.php">
<table class="form-table" role="presentation">
	<tbody><tr class="form-field form-required">
		<th scope="row"><label for="adduser-email">Email or Username</label></th>
		<td><input name="email" type="text" id="adduser-email" class="wp-suggest-user ui-autocomplete-input" value="" autocomplete="off"></td>
	</tr>
	<tr class="form-field">
		<th scope="row"><label for="adduser-role">Role</label></th>
		<td><select name="role" id="adduser-role">
			
	<option selected="selected" value="subscriber">Subscriber</option>
	<option value="staffmanager">Staff Manager</option>
	<option value="staff">Staff</option>
	<option value="wpseo_manager">SEO Manager</option>
	<option value="wpseo_editor">SEO Editor</option>
	<option value="editor-template">Editor - Template</option>
	<option value="editor-school">Editor - School</option>
	<option value="editor-multidept">Editor - Multi Dept</option>
	<option value="editor-demo1">Editor - Demo1</option>
	<option value="editor-archives">Editor - Archives</option>
	<option value="editor-academics">Editor - Academics</option>
	<option value="editor">Editor</option>
	<option value="contributor">Contributor</option>
	<option value="author">Author</option>
	<option value="administrator">Administrator</option>			</select>
		</td>
	</tr>
		<tr>
		<th scope="row">Skip Confirmation Email</th>
		<td>
			<input type="checkbox" name="noconfirmation" id="adduser-noconfirmation" value="1">
			<label for="adduser-noconfirmation">Add the user without sending an email that requires their confirmation.</label>
		</td>
	</tr>
	</tbody></table>
		<p class="submit"><input type="submit" name="adduser" id="addusersub" class="button button-primary" value="Add Existing User"></p></form>
	<h2 id="create-new-user">Add New User</h2><p>Create a brand new user and add them to this site.</p>
<form method="post" name="createuser" id="createuser" class="validate" novalidate="novalidate">
<input name="action" type="hidden" value="createuser">
	<input type="hidden" id="_wpnonce_create-user" name="_wpnonce_create-user" value="bfef7d72f2"><input type="hidden" name="_wp_http_referer" value="/wp-admin/user-new.php">	<table class="form-table" role="presentation">
	<tbody><tr class="form-field form-required">
		<th scope="row"><label for="user_login">Username <span class="description">(required)</span></label></th>
		<td><input name="user_login" type="text" id="user_login" value="" aria-required="true" autocapitalize="none" autocorrect="off" maxlength="60"></td>
	</tr>
	<tr class="form-field form-required">
		<th scope="row"><label for="email">Email <span class="description">(required)</span></label></th>
		<td><input name="email" type="email" id="email" value=""></td>
	</tr>
			<tr class="form-field">
		<th scope="row"><label for="role">Role</label></th>
		<td><select name="role" id="role">
			
	<option selected="selected" value="subscriber">Subscriber</option>
	<option value="staffmanager">Staff Manager</option>
	<option value="staff">Staff</option>
	<option value="wpseo_manager">SEO Manager</option>
	<option value="wpseo_editor">SEO Editor</option>
	<option value="editor-template">Editor - Template</option>
	<option value="editor-school">Editor - School</option>
	<option value="editor-multidept">Editor - Multi Dept</option>
	<option value="editor-demo1">Editor - Demo1</option>
	<option value="editor-archives">Editor - Archives</option>
	<option value="editor-academics">Editor - Academics</option>
	<option value="editor">Editor</option>
	<option value="contributor">Contributor</option>
	<option value="author">Author</option>
	<option value="administrator">Administrator</option>			</select>
		</td>
	</tr>
			<tr>
		<th scope="row">Skip Confirmation Email</th>
		<td>
			<input type="checkbox" name="noconfirmation" id="noconfirmation" value="1">
			<label for="noconfirmation">Add the user without sending an email that requires their confirmation.</label>
		</td>
	</tr>
	</tbody></table>

	
	<p class="submit"><input type="submit" name="createuser" id="createusersub" class="button button-primary" value="Add New User"></p>
</form>
</div>

Here is the PHP from AAM that affects this:

Hope this helps! :)

<?php /** @version 6.0.0 */ ?>

<?php if (defined('AAM_KEY')) { ?>
    <?php $user = ($param === 'add-new-user' ? null : $param); ?>

    <?php if ((!defined('IS_PROFILE_PAGE') || !IS_PROFILE_PAGE) && !is_network_admin() && (empty($user) || current_user_can('promote_user', $user->ID))) { ?>
        <table class="form-table">
            <tr>
                <th><?php echo esc_html('User Roles', AAM_KEY); ?></th>
                <td>
                    <div class="wp-tab-panel">
                        <ul>
                            <?php $roles = (!empty($user) ? $user->roles : array('subscriber')); ?>
                            <?php foreach (get_editable_roles() as $id => $role) { ?>
                                <li>
                                    <label>
                                        <input type="checkbox" name="aam_user_roles[]" value="<?php echo esc_attr($id); ?>" <?php checked(in_array($id, $roles)); ?> />
                                        <?php echo esc_html(translate_user_role($role['name'])); ?>
                                    </label>
                                </li>
                            <?php } ?>
                        </ul>
                    </div>
                </td>
            </tr>
        </table>

        <!-- Remove standard WordPress roles selector-->
        <script>
            (function($) {
                $(document).ready(function() {
                    if ($('.user-role-wrap').length) {
                        $('.user-role-wrap').remove();
                    } else if ($('#role').length) {
                        $('#role').parent().parent().remove();
                    }
                });
            })(jQuery);
        </script>
    <?php } ?>
<?php }

@aamplugin
Copy link
Owner

@terrance-orletsky-d7 thank you so much for the information. I'm analyzing your feedback and the fix is going to be included in the next AAM release.

@aamplugin aamplugin changed the title CRITICAL - Activating AAM removes the required 'Role' select from Add User form Incorrectly handled "Add User" for with multisite setup May 23, 2021
@aamplugin aamplugin self-assigned this May 23, 2021
@aamplugin aamplugin added the bug label May 23, 2021
@aamplugin aamplugin added this to the 6.7.6 - AAM milestone May 23, 2021
@aamplugin
Copy link
Owner

aamplugin commented May 23, 2021

The side effect for the reported bug is also 3 PHP errors:

  • PHP Warning: in_array() expects parameter 2 to be array, null given in /.../plugins/advanced-access-manager/application/Backend/tmpl/user/multiple-roles.php on line 17
  • PHP Notice: Trying to get property 'roles' of non-object in /.../plugins/advanced-access-manager/application/Backend/tmpl/user/multiple-roles.php on line 13
  • PHP Notice: Trying to get property 'ID' of non-object in /.../plugins/advanced-access-manager/application/Backend/tmpl/user/multiple-roles.php on line 6

@terrance-orletsky-d7
Copy link
Author

Thanks for addressing this so quickly, @aamplugin - much appreciated!

@terrance-orletsky-d7
Copy link
Author

Thanks for the quick fix, @aamplugin @vasyltech - that all appears to work well now...

I noticed another issue now, with editing the multiple roles, but not sure if it is related, so I posted in another ticket

Cheers!

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

No branches or pull requests

2 participants