#Overview
This filter is similar to the wpf_user_can_access filter, but runs only on Elementor elements, and passes the Elementor widget as an argument to the filter. To use the code examples below, add them to your active theme’s functions.php file.
#Parameters
$can_access
: This variable represents whether or not the user can access the content. It will either betrue
orfalse
.$element
: The Elementor widget
#Examples
#Require all tags to view an Element
This example changes the logic from the WP Fusion settings on an Element to require all of the specified tags, instead of any one of them.
function my_wpf_elementor_access( $can_access, $element ) {
$widget_tags = $element->get_settings( 'wpf_tags' );
if ( empty( $widget_tags ) ) {
return $can_access;
}
$user_tags = wp_fusion()->user->get_tags();
$result = array_intersect( $widget_tags, $user_tags );
if ( count( $result ) == count( $widget_tags ) ) {
$can_access = true;
} else {
$can_access = false;
}
return $can_access;
}
add_filter( 'wpf_elementor_can_access', 'my_wpf_elementor_access', 10, 2 );
#Create a custom access rule for a specific element
This example hides an element with ID fa65gh
unless the user has Tag X and does not have Tag Y.
function my_wpf_elementor_access_by_id( $can_access, $element ) {
if ( $element->get_id() == 'fa65gh' ) {
$can_access = false;
if ( wp_fusion()->user->has_tag( 'TAG X' ) && ! wp_fusion()->user->has_tag( 'TAG Y' ) ) {
$can_access = true;
}
}
return $can_access;
}
add_filter( 'wpf_elementor_can_access', 'my_wpf_elementor_access_by_id', 10, 2 );
Was this helpful?
Let us know if you liked the post. That’s the only way we can improve.