Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function can_access( $element ) {
- if ( is_admin() ) {
- return true;
- }
- $visibility = $element->get_settings( 'wpf_visibility' );
- $widget_tags = $element->get_settings( 'wpf_tags' );
- $widget_tags_all = $element->get_settings( 'wpf_tags_all' );
- $widget_tags_not = $element->get_settings( 'wpf_tags_not' );
- if ( ( empty( $visibility ) || 'everyone' == $visibility ) && empty( $widget_tags ) && empty( $widget_tags_all ) && empty( $widget_tags_not ) ) {
- // No settings, allow access
- $can_access = apply_filters( 'wpf_elementor_can_access', true, $element );
- return apply_filters( 'wpf_user_can_access', $can_access, wpf_get_current_user_id(), false );
- }
- if ( wp_fusion()->settings->get( 'exclude_admins' ) == true && current_user_can( 'manage_options' ) ) {
- return true;
- }
- $can_access = true;
- if ( wpf_is_user_logged_in() ) {
- $user_tags = wp_fusion()->user->get_tags();
- if ( 'everyone' == $visibility || 'loggedin' == $visibility ) {
- // See if user has required tags
- if ( ! empty( $widget_tags ) ) {
- // Required tags (any)
- $result = array_intersect( $widget_tags, $user_tags );
- if ( empty( $result ) ) {
- $can_access = false;
- }
- }
- if ( true == $can_access && ! empty( $widget_tags_all ) ) {
- // Required tags (all)
- $result = array_intersect( $widget_tags_all, $user_tags );
- if ( count( $result ) != count( $widget_tags_all ) ) {
- $can_access = false;
- }
- }
- if ( true == $can_access && ! empty( $widget_tags_not ) ) {
- // Required tags (not)
- $result = array_intersect( $widget_tags_not, $user_tags );
- if ( ! empty( $result ) ) {
- $can_access = false;
- }
- }
- } elseif ( 'loggedout' == $visibility ) {
- // The user is logged in but the widget is set to logged-out only
- $can_access = false;
- }
- } else {
- // Not logged in
- if ( 'loggedin' == $visibility ) {
- // The user is not logged in but the widget is set to logged-in only
- $can_access = false;
- } elseif ( 'everyone' == $visibility ) {
- // Also deny access if tags are specified
- if ( ! empty( $widget_tags ) || ! empty( $widget_tags_all ) ) {
- $can_access = false;
- }
- }
- }
- $can_access = apply_filters( 'wpf_elementor_can_access', $can_access, $element );
- global $post;
- if ( ! empty( $post ) ) {
- $post_id = $post->ID;
- } else {
- $post_id = 0;
- }
- $can_access = apply_filters( 'wpf_user_can_access', $can_access, wpf_get_current_user_id(), $post_id );
- if ( $can_access ) {
- return true;
- } else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement