registry = $registry; } /** * Hook into the two registration actions, if this core has them. * * @return void */ public function boot() { if ( ! $this->api_available() ) { return; } add_action( 'wp_abilities_api_categories_init', array( $this, 'register_category' ) ); add_action( 'wp_abilities_api_init', array( $this, 'register_abilities' ) ); } /** * Whether this WordPress has the Abilities API. * * A method rather than an inline check so the unsupported path stays reachable in tests on a * core that does have the API. * * @return bool */ protected function api_available() { return class_exists( 'WP_Ability' ) && function_exists( 'wp_register_ability' ); } /** * Register the category the abilities are filed under. * * @return void */ public function register_category() { wp_register_ability_category( self::NAMESPACE_PREFIX, array( 'label' => __( 'Adminkeep', 'adminkeep' ), 'description' => __( 'Content actions offered by Adminkeep: duplicating a post, rewriting a published one, replacing a media file and ordering a post type.', 'adminkeep' ), ) ); } /** * Register an ability for every booted feature that offers one. * * Booted, not registered: a feature that is switched off registers no abilities, exactly as it * registers no hooks. An agent's view of the site matches the site owner's settings. * * @return void */ public function register_abilities() { foreach ( $this->registry->booted() as $feature_id ) { $feature = $this->registry->get( $feature_id ); if ( ! $feature instanceof AbilityProvider ) { continue; } foreach ( $feature->abilities() as $name => $args ) { $args['category'] = self::NAMESPACE_PREFIX; wp_register_ability( self::NAMESPACE_PREFIX . '/' . $name, $args ); } } } }