12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'ACF_Location_User_Role' ) ) :
- class ACF_Location_User_Role extends ACF_Location {
-
- function initialize() {
- $this->name = 'user_role';
- $this->label = __( 'User Role', 'acf' );
- $this->category = 'user';
- $this->object_type = 'user';
- }
-
- public function match( $rule, $screen, $field_group ) {
-
- if ( isset( $screen['user_role'] ) ) {
- $user_role = $screen['user_role'];
- } elseif ( isset( $screen['user_id'] ) ) {
- $user_id = $screen['user_id'];
- $user_role = '';
-
- if ( $user_id === 'new' ) {
- $user_role = get_option( 'default_role' );
-
- } elseif ( user_can( $user_id, $rule['value'] ) ) {
- $user_role = $rule['value'];
- }
- } else {
- return false;
- }
-
- return $this->compare_to_rule( $user_role, $rule );
- }
-
- public function get_values( $rule ) {
- global $wp_roles;
- return array_merge(
- array(
- 'all' => __( 'All', 'acf' ),
- ),
- $wp_roles->get_names()
- );
- }
- }
-
- acf_register_location_type( 'ACF_Location_User_Role' );
- endif;
|