Astra_Target_Rules_Fields::parse_user_role_condition( int $post_id, Array $rules )
Parse user role condition.
Description
Parameters
- $post_id
-
(int) (Required) Post ID.
- $rules
-
(Array) (Required) Current user rules.
Return
(boolean) True = user condition passes. False = User condition does not pass.
Source
File: classes/modules/target-rule/class-astra-target-rules-fields.php
public function parse_user_role_condition( $post_id, $rules ) { $show_popup = true; if ( is_array( $rules ) && ! empty( $rules ) ) { $show_popup = false; foreach ( $rules as $i => $rule ) { switch ( $rule ) { case '': case 'all': $show_popup = true; break; case 'logged-in': if ( is_user_logged_in() ) { $show_popup = true; } break; case 'logged-out': if ( ! is_user_logged_in() ) { $show_popup = true; } break; default: if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); if ( isset( $current_user->roles ) && is_array( $current_user->roles ) && in_array( $rule, $current_user->roles ) ) { $show_popup = true; } } break; } if ( $show_popup ) { break; } } } return $show_popup; }
Expand full source code Collapse full source code View on Trac
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |