diff --git a/modules/class-role-manager.php b/modules/class-role-manager.php index 88425aad..d8d96b4b 100644 --- a/modules/class-role-manager.php +++ b/modules/class-role-manager.php @@ -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 ); + } } } @@ -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.