$allcaps The user's capabilities. * @return array */ public function grant_to_administrators( $allcaps ) { if ( empty( $allcaps['manage_options'] ) ) { return $allcaps; } foreach ( self::all() as $capability ) { $allcaps[ $capability ] = true; } return $allcaps; } /** * Stores every capability on the administrator role of the current site. * * @since 1.0.0 * * @return void */ public function add_to_administrator(): void { $role = get_role( 'administrator' ); if ( null === $role ) { return; } foreach ( self::all() as $capability ) { $role->add_cap( $capability ); } } /** * Lets editors and authors use the SEO box on the posts they can edit. * * Editors may also change the advanced fields (robots, canonical link). Site owners can * change this later; administrators are not affected. * * @since 1.0.0 * * @return void */ public function add_defaults(): void { $grants = array( 'editor' => array( self::EDIT_POST_SEO, self::EDIT_POST_ADVANCED ), 'author' => array( self::EDIT_POST_SEO ), ); foreach ( $grants as $role_name => $capabilities ) { $role = get_role( $role_name ); if ( null === $role ) { continue; } foreach ( $capabilities as $capability ) { $role->add_cap( $capability ); } } } /** * Removes every plugin capability from every role of the current site. * * @since 1.0.0 * * @return void */ public function remove_from_roles(): void { foreach ( wp_roles()->role_objects as $role ) { foreach ( self::all() as $capability ) { $role->remove_cap( $capability ); } } } }