get(); $roles = isset( $all['roles']['manage'] ) ? (array) $all['roles']['manage'] : array(); return array_values( array_unique( array_merge( self::ALWAYS, array_map( 'sanitize_key', $roles ) ) ) ); } /** * Grant the capability to the chosen roles and take it from the rest. * * @param Oorank_Settings $settings Settings store. */ public static function sync( Oorank_Settings $settings ) { $granted = self::granted( $settings ); foreach ( self::assignable() as $slug => $label ) { unset( $label ); $role = get_role( $slug ); if ( ! $role ) { continue; } if ( in_array( $slug, $granted, true ) ) { $role->add_cap( self::CAP ); } else { $role->remove_cap( self::CAP ); } } } /** * Roles the setting can hand the capability to. * * Only roles that can already edit something: giving Oorank to a * subscriber would be granting a content tool to an account that has no * content, and the audit's fix links all lead to the editor. * * @return array slug => display name. */ public static function assignable() { $roles = array(); foreach ( wp_roles()->roles as $slug => $role ) { $caps = isset( $role['capabilities'] ) ? $role['capabilities'] : array(); if ( empty( $caps['edit_posts'] ) && empty( $caps['manage_options'] ) ) { continue; } $roles[ $slug ] = translate_user_role( $role['name'] ); } return $roles; } }