PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Addons / NonLoggedInUsers / Roles.php

Roles.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Addons/NonLoggedInUsers/Roles.php

40 lines 968 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\NonLoggedInUsers;
2
3 /**
4 * The roles a wholesale rule can name: the customer-facing WordPress roles plus "guest" for visitors
5 * who are not logged in.
6 */
7 class Roles {
8
9 const GUEST = 'guest';
10
11 /**
12 * @return array<string, string> role key => label
13 */
14 public static function getOptions(): array {
15 $options = array( self::GUEST => __( 'Guests (not logged in)', 'tier-pricing-table' ) );
16
17 if ( ! function_exists( 'wp_roles' ) ) {
18 return $options;
19 }
20
21 foreach ( wp_roles()->roles as $key => $role ) {
22 if ( in_array( $key, array( 'administrator', 'editor', 'author', 'contributor', 'shop_manager' ), true ) ) {
23 continue;
24 }
25
26 $options[ $key ] = translate_user_role( $role['name'] );
27 }
28
29 return $options;
30 }
31
32 public static function label( string $role ): string {
33 if ( self::GUEST === $role ) {
34 return __( 'Guests', 'tier-pricing-table' );
35 }
36
37 return self::getOptions()[ $role ] ?? $role;
38 }
39 }
40