/wp/wp-content/plugins/members/admin/roles-list-table.php

https://bitbucket.org/akeda/bmw-id-hris · PHP · 238 lines · 145 code · 75 blank · 18 comment · 35 complexity · 970756139500f10ebb5c0555537b060a MD5 · raw file

  1. <?php
  2. /**
  3. * This file handles the display of the 'Roles' page in the admin.
  4. *
  5. * @package Members
  6. * @subpackage Admin
  7. */
  8. /* Get a count of all the roles available. */
  9. $roles_count = members_count_roles();
  10. /* Get all of the active and inactive roles. */
  11. $active_roles = members_get_active_roles();
  12. $inactive_roles = members_get_inactive_roles();
  13. /* Get a count of the active and inactive roles. */
  14. $active_roles_count = count( $active_roles );
  15. $inactive_roles_count = count( $inactive_roles );
  16. /* If we're viewing 'active' or 'inactive' roles. */
  17. if ( !empty( $_GET['role_status'] ) && in_array( $_GET['role_status'], array( 'active', 'inactive' ) ) ) {
  18. /* Get the role status ('active' or 'inactive'). */
  19. $role_status = esc_attr( $_GET['role_status'] );
  20. /* Set up the roles array. */
  21. $list_roles = ( ( 'active' == $role_status ) ? $active_roles : $inactive_roles );
  22. /* Set the current page URL. */
  23. $current_page = admin_url( "users.php?page=roles&role_status={$role_status}" );
  24. }
  25. /* If viewing the regular role list table. */
  26. else {
  27. /* Get the role status ('active' or 'inactive'). */
  28. $role_status = 'all';
  29. /* Set up the roles array. */
  30. $list_roles = array_merge( $active_roles, $inactive_roles );
  31. /* Set the current page URL. */
  32. $current_page = $current_page = admin_url( 'users.php?page=roles' );
  33. }
  34. /* Sort the roles array into alphabetical order. */
  35. ksort( $list_roles ); ?>
  36. <div class="wrap">
  37. <?php screen_icon(); ?>
  38. <h2>
  39. <?php _e( 'Roles', 'members' ); ?>
  40. <?php if ( current_user_can( 'create_roles' ) ) echo '<a href="' . admin_url( 'users.php?page=role-new' ) . '" class="add-new-h2">' . __( 'Add New', 'members' ) . '</a>'; ?>
  41. </h2>
  42. <?php do_action( 'members_pre_edit_roles_form' ); // Available action hook for displaying messages. ?>
  43. <div id="poststuff">
  44. <form id="roles" action="<?php echo $current_page; ?>" method="post">
  45. <?php wp_nonce_field( members_get_nonce( 'edit-roles' ) ); ?>
  46. <ul class="subsubsub">
  47. <li><a <?php if ( 'all' == $role_status ) echo 'class="current"'; ?> href="<?php echo admin_url( esc_url( 'users.php?page=roles' ) ); ?>"><?php _e( 'All', 'members' ); ?> <span class="count">(<span id="all_count"><?php echo $roles_count; ?></span>)</span></a> | </li>
  48. <li><a <?php if ( 'active' == $role_status ) echo 'class="current"'; ?> href="<?php echo admin_url( esc_url( 'users.php?page=roles&amp;role_status=active' ) ); ?>"><?php _e( 'Has Users', 'members' ); ?> <span class="count">(<span id="active_count"><?php echo $active_roles_count; ?></span>)</span></a> | </li>
  49. <li><a <?php if ( 'inactive' == $role_status ) echo 'class="current"'; ?> href="<?php echo admin_url( esc_url( 'users.php?page=roles&amp;role_status=inactive' ) ); ?>"><?php _e( 'No Users', 'members' ); ?> <span class="count">(<span id="inactive_count"><?php echo $inactive_roles_count; ?></span>)</span></a></li>
  50. </ul><!-- .subsubsub -->
  51. <div class="tablenav">
  52. <?php if ( current_user_can( 'delete_roles' ) ) { ?>
  53. <div class="alignleft actions">
  54. <select name="bulk-action">
  55. <option value="" selected="selected"><?php _e( 'Bulk Actions', 'members' ); ?></option>
  56. <?php if ( current_user_can( 'delete_roles' ) ) { ?>
  57. <option value="delete"><?php esc_html_e( 'Delete', 'members' ); ?></option>
  58. <?php } ?>
  59. </select>
  60. <?php submit_button( esc_attr__( 'Apply', 'members' ), 'button-secondary action', 'roles-bulk-action', false ); ?>
  61. </div><!-- .alignleft .actions -->
  62. <?php } // End cap check ?>
  63. <div class='tablenav-pages one-page'>
  64. <span class="displaying-num"><?php printf( _n( '%s item', '%s items', count( $list_roles ), 'members' ), count( $list_roles ) ); ?></span>
  65. </div>
  66. <br class="clear" />
  67. </div><!-- .tablenav -->
  68. <table class="widefat fixed" cellspacing="0">
  69. <thead>
  70. <tr>
  71. <th class='check-column'><input type='checkbox' /></th>
  72. <th class='name-column'><?php _e( 'Role Label', 'members' ); ?></th>
  73. <th><?php _e( 'Role Name', 'members' ); ?></th>
  74. <th><?php _e( 'Users', 'members' ); ?></th>
  75. <th><?php _e( 'Capabilities', 'members' ); ?></th>
  76. </tr>
  77. </thead>
  78. <tfoot>
  79. <tr>
  80. <th class='check-column'><input type='checkbox' /></th>
  81. <th class='name-column'><?php _e( 'Role Label', 'members' ); ?></th>
  82. <th><?php _e( 'Role', 'members' ); ?></th>
  83. <th><?php _e( 'Users', 'members' ); ?></th>
  84. <th><?php _e( 'Capabilities', 'members' ); ?></th>
  85. </tr>
  86. </tfoot>
  87. <tbody id="users" class="list:user user-list plugins">
  88. <?php foreach ( $list_roles as $role => $name ) { ?>
  89. <tr valign="top" class="<?php echo ( isset( $active_roles[$role] ) ? 'active' : 'inactive' ); ?>">
  90. <th class="manage-column column-cb check-column">
  91. <?php if ( ( is_multisite() && is_super_admin() && $role !== get_option( 'default_role' ) ) || ( !current_user_can( $role ) && $role !== get_option( 'default_role' ) ) ) { ?>
  92. <input type="checkbox" name="roles[<?php echo esc_attr( $role ); ?>]" id="<?php echo esc_attr( $role ); ?>" value="<?php echo esc_attr( $role ); ?>" />
  93. <?php } ?>
  94. </th><!-- .manage-column .column-cb .check-column -->
  95. <td class="plugin-title">
  96. <?php $edit_link = admin_url( wp_nonce_url( "users.php?page=roles&amp;action=edit&amp;role={$role}", members_get_nonce( 'edit-roles' ) ) ); ?>
  97. <?php if ( current_user_can( 'edit_roles' ) ) { ?>
  98. <a href="<?php echo esc_url( $edit_link ); ?>" title="<?php printf( esc_attr__( 'Edit the %s role', 'members' ), $name ); ?>"><strong><?php echo esc_html( $name ); ?></strong></a>
  99. <?php } else { ?>
  100. <strong><?php echo esc_html( $name ); ?></strong>
  101. <?php } ?>
  102. <div class="row-actions">
  103. <?php if ( current_user_can( 'edit_roles' ) ) { ?>
  104. <a href="<?php echo esc_url( $edit_link ); ?>" title="<?php printf( esc_attr__( 'Edit the %s role', 'members' ), $name ); ?>"><?php _e( 'Edit', 'members' ); ?></a>
  105. <?php } ?>
  106. <?php if ( ( is_multisite() && is_super_admin() && $role !== get_option( 'default_role' ) ) || ( current_user_can( 'delete_roles' ) && $role !== get_option( 'default_role' ) && !current_user_can( $role ) ) ) { ?>
  107. | <a href="<?php echo admin_url( wp_nonce_url( "users.php?page=roles&amp;action=delete&amp;role={$role}", members_get_nonce( 'edit-roles' ) ) ); ?>" title="<?php printf( esc_attr__( 'Delete the %s role', 'members' ), $name ); ?>"><?php _e( 'Delete', 'members' ); ?></a>
  108. <?php } ?>
  109. <?php if ( current_user_can( 'manage_options' ) && $role == get_option( 'default_role' ) ) { ?>
  110. | <a href="<?php echo admin_url( ( 'options-general.php' ) ); ?>" title="<?php _e( 'Change default role', 'members' ); ?>"><?php _e( 'Default Role', 'members' ); ?></a>
  111. <?php } ?>
  112. <?php if ( current_user_can( 'list_users' ) ) { ?>
  113. | <a href="<?php echo admin_url( esc_url( "users.php?role={$role}" ) ); ?>" title="<?php printf( esc_attr__( 'View all users with the %s role', 'members' ), $name ); ?>"><?php _e( 'View Users', 'members' ); ?></a>
  114. <?php } ?>
  115. </div><!-- .row-actions -->
  116. </td><!-- .plugin-title -->
  117. <td class="desc">
  118. <p>
  119. <?php echo $role; ?>
  120. </p>
  121. </td><!-- .desc -->
  122. <td class="desc">
  123. <p>
  124. <?php if ( current_user_can( 'list_users' ) ) { ?>
  125. <a href="<?php echo admin_url( esc_url( "users.php?role={$role}" ) ); ?>" title="<?php printf( __( 'View all users with the %s role', 'members' ), $name ); ?>"><?php printf( _n( '%s User', '%s Users', members_get_role_user_count( $role ), 'members' ), members_get_role_user_count( $role ) ); ?></a>
  126. <?php } else { ?>
  127. <?php printf( _n( '%s User', '%s Users', members_get_role_user_count( $role ), 'members' ), members_get_role_user_count( $role ) ); ?>
  128. <?php } ?>
  129. </p>
  130. </td><!-- .desc -->
  131. <td class="desc">
  132. <p>
  133. <?php
  134. $role_object = get_role( $role );
  135. $cap_count = count( $role_object->capabilities );
  136. printf( _n( '%s Capability', '%s Capabilities', $cap_count, 'members' ), $cap_count );
  137. ?>
  138. </p>
  139. </td><!-- .desc -->
  140. </tr><!-- .active .inactive -->
  141. <?php } // End foreach ?>
  142. </tbody><!-- #users .list:user .user-list .plugins -->
  143. </table><!-- .widefat .fixed -->
  144. <div class="tablenav">
  145. <?php if ( current_user_can( 'delete_roles' ) ) { ?>
  146. <div class="alignleft actions">
  147. <select name="bulk-action-2">
  148. <option value="" selected="selected"><?php _e( 'Bulk Actions', 'members' ); ?></option>
  149. <?php if ( current_user_can( 'delete_roles' ) ) { ?>
  150. <option value="delete"><?php _e( 'Delete', 'members' ); ?></option>
  151. <?php } ?>
  152. </select>
  153. <?php submit_button( esc_attr__( 'Apply', 'members' ), 'button-secondary action', 'roles-bulk-action-2', false ); ?>
  154. </div><!-- .alignleft .actions -->
  155. <?php } // End cap check ?>
  156. <div class='tablenav-pages one-page'>
  157. <span class="displaying-num"><?php printf( _n( '%s item', '%s items', count( $list_roles ), 'members' ), count( $list_roles ) ); ?></span>
  158. </div>
  159. <br class="clear" />
  160. </div><!-- .tablenav -->
  161. </form><!-- #roles -->
  162. </div><!-- #poststuff -->
  163. </div><!-- .wrap -->