PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.9.5
Secure Custom Fields v6.9.5
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / locations / class-acf-location-current-user-role.php
secure-custom-fields / includes / locations Last commit date
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-current-user-role.php
89 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'ACF_Location_Current_User_Role' ) ) :
8
9 class ACF_Location_Current_User_Role extends ACF_Location {
10
11 /**
12 * Initializes props.
13 *
14 * @date 5/03/2014
15 * @since ACF 5.0.0
16 *
17 * @return void
18 */
19 public function initialize() {
20 $this->name = 'current_user_role';
21 $this->label = __( 'Current User Role', 'secure-custom-fields' );
22 $this->category = 'user';
23 }
24
25 /**
26 * Matches the provided rule against the screen args returning a bool result.
27 *
28 * @date 9/4/20
29 * @since ACF 5.9.0
30 *
31 * @param array $rule The location rule.
32 * @param array $screen The screen args.
33 * @param array $field_group The field group settings.
34 * @return boolean
35 */
36 public function match( $rule, $screen, $field_group ) {
37
38 // Get current user.
39 $user = wp_get_current_user();
40 if ( ! $user ) {
41 return false;
42 }
43
44 // Check super_admin value.
45 $rule_value = $rule['value'] ?? '';
46 if ( 'super_admin' === $rule_value ) {
47 $result = is_super_admin( $user->ID );
48
49 // Check role.
50 } else {
51 $result = in_array( $rule_value, $user->roles, true );
52 }
53
54 // Reverse result for "!=" operator.
55 if ( ( $rule['operator'] ?? '' ) === '!=' ) {
56 return ! $result;
57 }
58 return $result;
59 }
60
61 /**
62 * Returns an array of possible values for this rule type.
63 *
64 * @date 9/4/20
65 * @since ACF 5.9.0
66 *
67 * @param array $rule A location rule.
68 * @return array
69 */
70 public function get_values( $rule ) {
71 $choices = wp_roles()->get_names();
72
73 // Prepend Super Admin choice.
74 if ( is_multisite() ) {
75 return array_merge(
76 array(
77 'super_admin' => __( 'Super Admin', 'secure-custom-fields' ),
78 ),
79 $choices
80 );
81 }
82 return $choices;
83 }
84 }
85
86 // Register.
87 acf_register_location_type( 'ACF_Location_Current_User_Role' );
88 endif; // class_exists check
89