abstract-acf-legacy-location.php
1 year ago
abstract-acf-location.php
2 weeks ago
class-acf-location-attachment.php
2 weeks ago
class-acf-location-block.php
1 year ago
class-acf-location-comment.php
1 year ago
class-acf-location-current-user-role.php
2 weeks ago
class-acf-location-current-user.php
2 weeks ago
class-acf-location-nav-menu-item.php
1 year ago
class-acf-location-nav-menu.php
2 weeks ago
class-acf-location-options-page.php
1 year ago
class-acf-location-page-parent.php
1 year ago
class-acf-location-page-template.php
2 weeks ago
class-acf-location-page-type.php
2 weeks ago
class-acf-location-page.php
1 year ago
class-acf-location-post-category.php
1 year ago
class-acf-location-post-format.php
1 year ago
class-acf-location-post-status.php
1 year ago
class-acf-location-post-taxonomy.php
2 weeks ago
class-acf-location-post-template.php
2 weeks ago
class-acf-location-post-type.php
2 weeks ago
class-acf-location-post.php
1 year ago
class-acf-location-taxonomy.php
2 weeks ago
class-acf-location-user-form.php
2 weeks ago
class-acf-location-user-role.php
2 weeks ago
class-acf-location-widget.php
1 year ago
index.php
1 year ago
class-acf-location-user-role.php
87 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly |
| 5 | } |
| 6 | |
| 7 | if ( ! class_exists( 'ACF_Location_User_Role' ) ) : |
| 8 | |
| 9 | class ACF_Location_User_Role extends ACF_Location { |
| 10 | |
| 11 | /** |
| 12 | * initialize |
| 13 | * |
| 14 | * Sets up the class functionality. |
| 15 | * |
| 16 | * @date 5/03/2014 |
| 17 | * @since ACF 5.0.0 |
| 18 | * |
| 19 | * @return void |
| 20 | */ |
| 21 | function initialize() { |
| 22 | $this->name = 'user_role'; |
| 23 | $this->label = __( 'User Role', 'secure-custom-fields' ); |
| 24 | $this->category = 'user'; |
| 25 | $this->object_type = 'user'; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Matches the provided rule against the screen args returning a bool result. |
| 30 | * |
| 31 | * @date 9/4/20 |
| 32 | * @since ACF 5.9.0 |
| 33 | * |
| 34 | * @param array $rule The location rule. |
| 35 | * @param array $screen The screen args. |
| 36 | * @param array $field_group The field group settings. |
| 37 | * @return boolean |
| 38 | */ |
| 39 | public function match( $rule, $screen, $field_group ) { |
| 40 | |
| 41 | // Check screen args. |
| 42 | if ( isset( $screen['user_role'] ) ) { |
| 43 | $user_role = $screen['user_role']; |
| 44 | } elseif ( isset( $screen['user_id'] ) ) { |
| 45 | $user_id = $screen['user_id']; |
| 46 | $user_role = ''; |
| 47 | |
| 48 | // Determine $user_role from $user_id. |
| 49 | if ( $user_id === 'new' ) { |
| 50 | $user_role = get_option( 'default_role' ); |
| 51 | |
| 52 | // Check if user can, and if so, set the value allowing them to match. |
| 53 | } elseif ( ( $rule['value'] ?? '' ) && user_can( $user_id, $rule['value'] ) ) { |
| 54 | $user_role = $rule['value']; |
| 55 | } |
| 56 | } else { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | // Compare rule against $user_role. |
| 61 | return $this->compare_to_rule( $user_role, $rule ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns an array of possible values for this rule type. |
| 66 | * |
| 67 | * @date 9/4/20 |
| 68 | * @since ACF 5.9.0 |
| 69 | * |
| 70 | * @param array $rule A location rule. |
| 71 | * @return array |
| 72 | */ |
| 73 | public function get_values( $rule ) { |
| 74 | global $wp_roles; |
| 75 | return array_merge( |
| 76 | array( |
| 77 | 'all' => __( 'All', 'secure-custom-fields' ), |
| 78 | ), |
| 79 | $wp_roles->get_names() |
| 80 | ); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // initialize |
| 85 | acf_register_location_type( 'ACF_Location_User_Role' ); |
| 86 | endif; // class_exists check |
| 87 |