| 1 |
<?php |
| 2 |
/** |
| 3 |
* Displays and processes the 'Add New Role' page in the admin. |
| 4 |
* |
| 5 |
* @package Members |
| 6 |
* @subpackage Admin |
| 7 |
*/ |
| 8 |
|
| 9 |
/* Check if the current user can create roles and the form has been submitted. */ |
| 10 |
if ( current_user_can( 'create_roles' ) && isset( $_POST['role-name'] ) && isset( $_POST['role-label'] ) ) { |
| 11 |
|
| 12 |
/* Verify the nonce. */ |
| 13 |
check_admin_referer( members_get_nonce( 'new-role' ) ); |
| 14 |
|
| 15 |
/* Check if any capabilities were selected. */ |
| 16 |
if ( !empty( $_POST['capabilities'] ) && is_array( $_POST['capabilities'] ) ) |
| 17 |
$new_role_caps = array_map( 'esc_attr', $_POST['capabilities'] ); |
| 18 |
|
| 19 |
/* If no capabilities were selected, set the variable to null. */ |
| 20 |
else |
| 21 |
$new_role_caps = null; |
| 22 |
|
| 23 |
/* Check if both a role name and role were submitted. */ |
| 24 |
if ( !empty( $_POST['role-name'] ) && !empty( $_POST['role-label'] ) ) { |
| 25 |
|
| 26 |
/* Sanitize the new role, removing any unwanted characters. */ |
| 27 |
$new_role_name = sanitize_key( $_POST['role-name'] ); |
| 28 |
|
| 29 |
/* Sanitize the new role name/label. We just want to strip any tags here. */ |
| 30 |
$new_role_label = strip_tags( $_POST['role-label'] ); |
| 31 |
|
| 32 |
/* Add a new role with the data input. */ |
| 33 |
if ( !empty( $new_role_name ) && !empty( $new_role_label ) ) |
| 34 |
$new_role_added = add_role( $new_role_name, $new_role_label, $new_role_caps ); |
| 35 |
|
| 36 |
} // End check for role and role name |
| 37 |
|
| 38 |
} // End check for form submit ?> |
| 39 |
|
| 40 |
<div class="wrap"> |
| 41 |
|
| 42 |
<?php screen_icon(); ?> |
| 43 |
|
| 44 |
<h2><?php _e( 'Add New Role', 'members' ); ?></h2> |
| 45 |
|
| 46 |
<?php if ( !empty( $new_role_added ) ) members_admin_message( '', sprintf( __( 'The %s role has been created.', 'members' ), esc_html( $_POST['role-name'] ) ) ); ?> |
| 47 |
|
| 48 |
<?php do_action( 'members_pre_new_role_form' ); // Available action hook for displaying messages. ?> |
| 49 |
|
| 50 |
<div id="poststuff"> |
| 51 |
|
| 52 |
<form name="form0" method="post" action="<?php echo admin_url( 'users.php?page=role-new' ); ?>"> |
| 53 |
|
| 54 |
<?php wp_nonce_field( members_get_nonce( 'new-role' ) ); ?> |
| 55 |
|
| 56 |
<table class="form-table"> |
| 57 |
|
| 58 |
<tr> |
| 59 |
<th> |
| 60 |
<label for="role-name"><?php _e( 'Role Name', 'members' ); ?></label> |
| 61 |
</th> |
| 62 |
<td> |
| 63 |
<input type="text" id="role-name" name="role-name" value="" size="30" /> |
| 64 |
<br /> |
| 65 |
<label for="role-name"><?php _e( "<strong>Required:</strong> The role name should be unique and contain only alphanumeric characters and underscores.", 'members' ); ?></label> |
| 66 |
</td> |
| 67 |
</tr> |
| 68 |
|
| 69 |
<tr> |
| 70 |
<th> |
| 71 |
<label for="role-label"><?php _e( 'Role Label', 'members' ); ?></label> |
| 72 |
</th> |
| 73 |
<td> |
| 74 |
<input type="text" id="role-label" name="role-label" value="" size="30" /> |
| 75 |
<br /> |
| 76 |
<label for="role-label"><?php _e( '<strong>Required:</strong> The role label is used to represent your role in the WordPress admin.', 'members' ); ?></label> |
| 77 |
</td> |
| 78 |
</tr> |
| 79 |
|
| 80 |
<tr> |
| 81 |
<th> |
| 82 |
<?php _e( 'Role Capabilities', 'members' ); ?> |
| 83 |
</th> |
| 84 |
<td> |
| 85 |
<p> |
| 86 |
<?php _e( '<strong>Optional:</strong> Select the capabilities this role should have. These may be updated later.', 'members' ); ?> |
| 87 |
</p> |
| 88 |
|
| 89 |
<?php $i = -1; foreach ( members_get_capabilities() as $cap ) { ?> |
| 90 |
|
| 91 |
<div class="members-role-checkbox <?php if ( ++$i % 3 == 0 ) echo 'clear'; ?>"> |
| 92 |
<input type="checkbox" name="capabilities[<?php echo esc_attr( $cap ); ?>]" id="capabilities-<?php echo esc_attr( $cap ); ?>" <?php checked( true, in_array( $cap, members_new_role_default_capabilities() ) ); ?> value="true" /> |
| 93 |
<label for="capabilities-<?php echo esc_attr( $cap ); ?>" class="<?php echo ( in_array( $cap, members_new_role_default_capabilities() ) ? 'has-cap' : 'has-cap-not' ); ?>"><?php echo $cap; ?></label> |
| 94 |
</div> |
| 95 |
|
| 96 |
<?php } // Endforeach ?> |
| 97 |
</td> |
| 98 |
</tr> |
| 99 |
|
| 100 |
</table><!-- .form-table --> |
| 101 |
|
| 102 |
<?php submit_button( esc_attr__( 'Add Role', 'members' ) ); ?> |
| 103 |
|
| 104 |
</form> |
| 105 |
|
| 106 |
</div><!-- #poststuff --> |
| 107 |
|
| 108 |
</div><!-- .poststuff --> |