WordPress.org

Make WordPress Core

Ticket #43936: 43936.3.diff

File 43936.3.diff, 2.1 KB (added by kraftbj, 16 months ago)
  • src/wp-admin/includes/template.php

     
    886886 * Print out option html elements for role selectors.
    887887 *
    888888 * @since 2.1.0
     889 * @since 4.9.7 Added $roles_to_exclude argument.
    889890 *
    890891 * @param string $selected Slug for the role that should be already selected.
     892 * @param array  $roles_to_exclude Array of roles to not list in dropdown.
    891893 */
    892 function wp_dropdown_roles( $selected = '' ) {
     894function wp_dropdown_roles( $selected = '', $roles_to_exclude = array() ) {
    893895        $r = '';
    894896
    895897        $editable_roles = array_reverse( get_editable_roles() );
    896898
     899        if ( ! empty( $roles_to_exclude ) && is_array( $roles_to_exclude ) ) {
     900                foreach ( $roles_to_exclude as $role_to_exclude ) {
     901                        unset( $editable_roles[ $role_to_exclude ] );
     902                }
     903        }
     904
    897905        foreach ( $editable_roles as $role => $details ) {
    898906                $name = translate_user_role( $details['name'] );
    899                 // preselect specified role
     907                // preselect specified role.
    900908                if ( $selected == $role ) {
    901909                        $r .= "\n\t<option selected='selected' value='" . esc_attr( $role ) . "'>$name</option>";
    902910                } else {
  • src/wp-admin/options-general.php

     
    147147<tr>
    148148<th scope="row"><label for="default_role"><?php _e( 'New User Default Role' ); ?></label></th>
    149149<td>
    150 <select name="default_role" id="default_role"><?php wp_dropdown_roles( get_option( 'default_role' ) ); ?></select>
     150<?php
     151/**
     152 * Filters the roles excluded from the New Default Role option.
     153 *
     154 * @since 4.9.7
     155 *
     156 * @param array $roles_to_exclude Array of roles to exclude from the New Default Role drowndown.
     157 */
     158$roles_to_exclude = (array) apply_filters( 'new_default_user_excluded_roles', array( 'administrator' ) );
     159?>
     160<select name="default_role" id="default_role"><?php wp_dropdown_roles( get_option( 'default_role' ), $roles_to_exclude ); ?></select>
    151161</td>
    152162</tr>
    153163