1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'ACF_Location_Current_User_Role' ) ) :
- class ACF_Location_Current_User_Role extends ACF_Location {
-
- public function initialize() {
- $this->name = 'current_user_role';
- $this->label = __( 'Current User Role', 'acf' );
- $this->category = 'user';
- }
-
- public function match( $rule, $screen, $field_group ) {
-
- $user = wp_get_current_user();
- if ( ! $user ) {
- return false;
- }
-
- if ( $rule['value'] == 'super_admin' ) {
- $result = is_super_admin( $user->ID );
-
- } else {
- $result = in_array( $rule['value'], $user->roles );
- }
-
- if ( $rule['operator'] === '!=' ) {
- return ! $result;
- }
- return $result;
- }
-
- public function get_values( $rule ) {
- $choices = wp_roles()->get_names();
-
- if ( is_multisite() ) {
- return array_merge(
- array(
- 'super_admin' => __( 'Super Admin', 'acf' ),
- ),
- $choices
- );
- }
- return $choices;
- }
- }
-
- acf_register_location_type( 'ACF_Location_Current_User_Role' );
- endif;
|