Exemplo n.º 1
0
 /**
  * Handles the row actions.
  *
  * @since  1.0.0
  * @access protected
  * @param  string     $role
  * @param  string     $column_name
  * @param  string     $primary
  * @return array
  */
 protected function handle_row_actions($role, $column_name, $primary)
 {
     $actions = array();
     // Only add row actions on the primary column (title/role name).
     if ($primary === $column_name) {
         // If the role can be edited.
         if (members_is_role_editable($role)) {
             // If the current user can edit the role, add an edit link.
             if (current_user_can('edit_roles')) {
                 $actions['edit'] = sprintf('<a href="%s">%s</a>', esc_url(members_get_edit_role_url($role)), esc_html__('Edit', 'members'));
             }
             // If the current user can delete the role, add a delete link.
             if (is_multisite() && is_super_admin() && $role !== $this->default_role || current_user_can('delete_roles') && $role !== $this->default_role && !current_user_can($role)) {
                 $actions['delete'] = sprintf('<a class="members-delete-role-link" href="%s">%s</a>', esc_url(members_get_delete_role_url($role)), esc_html__('Delete', 'members'));
             }
             // If the role cannot be edited.
         } else {
             // Add the view role link.
             $actions['view'] = sprintf('<a href="%s">%s</a>', esc_url(members_get_edit_role_url($role)), esc_html__('View', 'members'));
         }
         // If the current user can create roles, add the clone role link.
         if (current_user_can('create_roles')) {
             $actions['clone'] = sprintf('<a href="%s">%s</a>', esc_url(members_get_clone_role_url($role)), esc_html__('Clone', 'members'));
         }
         // If this is the default role and the current user can manage options, add a default role change link.
         if (current_user_can('manage_options') && $role === $this->default_role) {
             $actions['default_role'] = sprintf('<a href="%s">%s</a>', esc_url(admin_url('options-general.php#default_role')), esc_html__('Change Default', 'members'));
         }
         // If the currrent user can view users, add a users link.
         if (current_user_can('list_users')) {
             $actions['users'] = sprintf('<a href="%s">%s</a>', members_get_role_users_url($role), esc_html__('Users', 'members'));
         }
         // Allow devs to filter the row actions.
         $actions = apply_filters('members_roles_row_actions', $actions, $role);
     }
     return $this->row_actions($actions);
 }
    /**
     * Outputs the meta box HTML.
     *
     * @since  1.0.0
     * @access public
     * @param  object  $role
     * @return void
     */
    public function meta_box($role)
    {
        // Set up some defaults for new roles.
        $is_editable = true;
        $user_count = 0;
        $grant_count = 0;
        $deny_count = 0;
        // If we're editing a role, overwrite the defaults.
        if ($role) {
            $is_editable = members_is_role_editable($role->name);
            $user_count = members_get_role_user_count($role->name);
            $grant_count = members_get_role_granted_cap_count($role->name);
            $deny_count = members_get_role_denied_cap_count($role->name);
        }
        ?>

		<div class="submitbox" id="submitpost">

			<div id="misc-publishing-actions">

				<div class="misc-pub-section misc-pub-section-users">
					<i class="dashicons dashicons-admin-users"></i>
					<?php 
        esc_html_e('Users:', 'members');
        ?>
					<strong class="user-count"><?php 
        echo number_format_i18n($user_count);
        ?>
</strong>
				</div>

				<div class="misc-pub-section misc-pub-section-granted">
					<i class="dashicons dashicons-yes"></i>
					<?php 
        esc_html_e('Granted:', 'members');
        ?>
					<strong class="granted-count"><?php 
        echo number_format_i18n($grant_count);
        ?>
</strong>
				</div>

				<div class="misc-pub-section misc-pub-section-denied">
					<i class="dashicons dashicons-no"></i>
					<?php 
        esc_html_e('Denied:', 'members');
        ?>
					<strong class="denied-count"><?php 
        echo number_format_i18n($deny_count);
        ?>
</strong>
				</div>

			</div><!-- #misc-publishing-actions -->

			<div id="major-publishing-actions">

				<div id="delete-action">

					<?php 
        if ($is_editable && $role) {
            ?>
						<a class="submitdelete deletion members-delete-role-link" href="<?php 
            echo esc_url(members_get_delete_role_url($role->name));
            ?>
"><?php 
            echo esc_html_x('Delete', 'delete role', 'members');
            ?>
</a>
					<?php 
        }
        ?>
				</div>

				<div id="publishing-action">

					<?php 
        if ($is_editable) {
            ?>
						<?php 
            submit_button($role ? esc_attr__('Update', 'members') : esc_attr__('Add Role', 'members'), 'primary', 'publish', false, array('id' => 'publish'));
            ?>
					<?php 
        }
        ?>

				</div><!-- #publishing-action -->

				<div class="clear"></div>

			</div><!-- #major-publishing-actions -->

		</div><!-- .submitbox -->
	<?php 
    }