| | 114 | * Add bulk dropdown forum role dropdown controls to the WordPress |
| | 115 | * Users table |
| | 116 | * |
| | 117 | * @return bool Always false |
| | 118 | */ |
| | 119 | public static function user_role_bulk_dropdown() { |
| | 120 | |
| | 121 | // Bail if current user cannot promote users |
| | 122 | if ( !current_user_can( 'promote_users' ) ) |
| | 123 | return; ?> |
| | 124 | |
| | 125 | <label class="screen-reader-text" for="bbp_new_role"><?php _e( 'Change forum role to…', 'bbpress' ) ?></label> |
| | 126 | <select name="bbp_new_role" id="bbp_new_role" style="display:inline-block;float:none;"> |
| | 127 | <option value=''><?php _e( 'Change forum role to…', 'bbpress' ) ?></option> |
| | 128 | <?php foreach ( bbp_get_dynamic_roles() as $role => $details ) : ?> |
| | 129 | |
| | 130 | <option value="<?php echo esc_attr( $role ); ?>"><?php echo translate_user_role( $details['name'] ); ?></option> |
| | 131 | |
| | 132 | <?php endforeach; ?> |
| | 133 | </select> |
| | 134 | <?php submit_button( __( 'Change Role' ), 'secondary', 'bbp_change_role', false ); ?> |
| | 135 | |
| | 136 | <?php |
| | 137 | } |
| | 138 | |
| | 139 | /** |
| | 140 | * Process bulk dropdown form submission from the WordPress Users |
| | 141 | * Table |
| | 142 | * |
| | 143 | * @uses current_user_can() to check for 'promote users' capability |
| | 144 | * @uses bbp_get_dynamic_roles() to get forum roles |
| | 145 | * @uses bbp_get_user_role() to get a user's current forums role |
| | 146 | * @uses bbp_set_user_role() to set the user's new forums role |
| | 147 | * @return bool Always false |
| | 148 | */ |
| | 149 | public function user_role_bulk_change() { |
| | 150 | global $current_user, $wp_roles; |
| | 151 | |
| | 152 | if ( !current_user_can( 'moderate' ) ) |
| | 153 | return; |
| | 154 | |
| | 155 | // Bail if no users specified |
| | 156 | if ( !isset( $_REQUEST['users'] ) || empty( $_REQUEST['users'] ) ) |
| | 157 | return; |
| | 158 | |
| | 159 | // Bail if this isn't a bbPress action |
| | 160 | if ( !isset( $_REQUEST['bbp_new_role'] ) || empty( $_REQUEST['bbp_new_role'] ) ) |
| | 161 | return; |
| | 162 | |
| | 163 | // Check that the new role exists |
| | 164 | $editable_roles = bbp_get_dynamic_roles(); |
| | 165 | if ( empty( $editable_roles[$_REQUEST['bbp_new_role']] ) ) |
| | 166 | return; |
| | 167 | |
| | 168 | // Run through user ids |
| | 169 | $user_ids = $_REQUEST['users']; |
| | 170 | foreach ( (array) $user_ids as $user_id ) { |
| | 171 | |
| | 172 | // Set up user and role data |
| | 173 | $user_id = (int) $user_id; |
| | 174 | $user = get_userdata( $user_id ); |
| | 175 | $current_role = bbp_get_user_role( $user_id ); |
| | 176 | $new_role = sanitize_text_field( $_REQUEST['bbp_new_role'] ); |
| | 177 | |
| | 178 | // Don't let a user demote themselves |
| | 179 | if ( $user_id == $current_user->ID ) |
| | 180 | continue; |
| | 181 | |
| | 182 | // Don't let a Moderator change Keymaster roles |
| | 183 | if ( bbp_get_user_role( $current_user->ID ) == bbp_get_moderator_role() |
| | 184 | && ( $current_role == bbp_get_keymaster_role() || $new_role == bbp_get_keymaster_role() ) ) |
| | 185 | continue; |
| | 186 | |
| | 187 | // Set the new forums role |
| | 188 | if ( $new_role != $current_role ) |
| | 189 | bbp_set_user_role( $user_id, $new_role ); |
| | 190 | } |
| | 191 | } |
| | 192 | |
| | 193 | /** |