abstract-acf-legacy-location.php
1 year ago
abstract-acf-location.php
1 year ago
class-acf-location-attachment.php
1 year ago
class-acf-location-block.php
1 year ago
class-acf-location-comment.php
1 year ago
class-acf-location-current-user-role.php
1 year ago
class-acf-location-current-user.php
1 year ago
class-acf-location-nav-menu-item.php
1 year ago
class-acf-location-nav-menu.php
1 year 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
1 year ago
class-acf-location-page-type.php
1 year 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
1 year ago
class-acf-location-post-template.php
1 year ago
class-acf-location-post-type.php
1 year ago
class-acf-location-post.php
1 year ago
class-acf-location-taxonomy.php
1 year ago
class-acf-location-user-form.php
1 year ago
class-acf-location-user-role.php
1 year ago
class-acf-location-widget.php
1 year ago
index.php
1 year ago
class-acf-location-current-user.php
80 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly |
| 5 | } |
| 6 | |
| 7 | if ( ! class_exists( 'ACF_Location_Current_User' ) ) : |
| 8 | |
| 9 | class ACF_Location_Current_User 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'; |
| 21 | $this->label = __( 'Current User', '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 | switch ( $rule['value'] ) { |
| 38 | case 'logged_in': |
| 39 | $result = is_user_logged_in(); |
| 40 | break; |
| 41 | case 'viewing_front': |
| 42 | $result = ! is_admin(); |
| 43 | break; |
| 44 | case 'viewing_back': |
| 45 | $result = is_admin(); |
| 46 | break; |
| 47 | default: |
| 48 | $result = false; |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | // Reverse result for "!=" operator. |
| 53 | if ( $rule['operator'] === '!=' ) { |
| 54 | return ! $result; |
| 55 | } |
| 56 | return $result; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns an array of possible values for this rule type. |
| 61 | * |
| 62 | * @date 9/4/20 |
| 63 | * @since ACF 5.9.0 |
| 64 | * |
| 65 | * @param array $rule A location rule. |
| 66 | * @return array |
| 67 | */ |
| 68 | public function get_values( $rule ) { |
| 69 | return array( |
| 70 | 'logged_in' => __( 'Logged in', 'secure-custom-fields' ), |
| 71 | 'viewing_front' => __( 'Viewing front end', 'secure-custom-fields' ), |
| 72 | 'viewing_back' => __( 'Viewing back end', 'secure-custom-fields' ), |
| 73 | ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Register. |
| 78 | acf_register_location_type( 'ACF_Location_Current_User' ); |
| 79 | endif; // class_exists check |
| 80 |