Skip to content

Commit

Permalink
Show custom capabilities that are not stored but only active in a cap…
Browse files Browse the repository at this point in the history
…s view

See #70
  • Loading branch information
JoryHogeveen committed Aug 16, 2017
1 parent 9bc6223 commit 2107465
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions modules/class-role-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public function vaa_init() {
// Show the admin bar node.
add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu' ), 6, 2 );
add_action( 'vaa_admin_bar_caps_manager_before', array( $this, 'admin_bar_menu_caps' ), 6, 2 );

// Add custom capabilities.
if ( $this->store->get_view( 'caps' ) ) {
add_filter( 'view_admin_as_get_capabilities', array( $this, 'filter_custom_view_capabilities' ), 10, 2 );
}
}
}

Expand Down Expand Up @@ -258,6 +263,30 @@ public function ajax_handler( $null, $data ) {
return $success;
}

/**
* Add all current caps view capabilities to an array of existing capabilities.
* Makes sure that if you add a custom capability to your view it is still visible after reload.
*
* @since 1.7.3
* @access public
* @param array $caps Current capabilities.
* @param array $args Function arguments.
* @return array
*/
public function filter_custom_view_capabilities( $caps = array(), $args = array() ) {

if ( isset( $args['vaa_role_manager'] ) && ! $args['vaa_role_manager'] ) {
return $caps;
}

$view_caps = $this->store->get_view( 'caps' );
if ( ! $view_caps ) {
return $caps;
}
$cap_keys = array_keys( $view_caps );
return array_merge( array_combine( $cap_keys, $cap_keys ), $caps );
}

/**
* Save a role.
* Can also add a new role when it doesn't exist.
Expand Down

0 comments on commit 2107465

Please sign in to comment.