Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wpf_elementor_controls_section( $element ) {
- $element->add_control(
- 'wpf_not_any_all',
- [
- 'label' => 'Must NOT have ALL tags (default = match any):',
- 'type' => \Elementor\Controls_Manager::SWITCHER,
- 'lable_on' => 'Yes',
- 'lable_off' => 'No',
- 'return_value' => 'yes',
- 'default' => 'no',
- ]
- );
- $element->add_control(
- 'wpf_tags_any_all',
- [
- 'label' => 'Must have ALL tags: (default = match any)',
- 'type' => \Elementor\Controls_Manager::SWITCHER,
- 'lable_on' => 'Yes',
- 'lable_off' => 'No',
- 'return_value' => 'yes',
- 'default' => 'no',
- ]
- );
- }
- add_action( 'wpf_elementor_controls_section', 'wpf_elementor_controls_section' );
- function wpf_elementor_can_access( $can_access, $element, $user_tags ) {
- $widget_tags = $element->get_settings( 'wpf_tags' );
- $widget_any_all = $element->get_settings_for_display();
- if( ! empty( $widget_tags ) ) {
- if( 'yes' !== $widget_any_all['wpf_tags_any_all']) {
- $result = array_intersect( $widget_tags, $user_tags );
- if( empty( $result ) ) {
- $can_access = false;
- }
- }
- if( 'yes' === $widget_any_all['wpf_tags_any_all']) {
- foreach( $widget_tags as $temp_tag) {
- if( ! in_array( $temp_tag, $user_tags ) ) {
- $can_access = false;
- }
- }
- }
- }
- if( $can_access == true && ! empty( $widget_tags_not ) ) {
- if( 'yes' !== $widget_any_all['wpf_not_any_all'] ) {
- $result = array_intersect( $widget_tags_not, $user_tags );
- if( ! empty( $result ) ) {
- $can_access = false;
- }
- }
- if( 'yes' === $widget_any_all['wpf_not_any_all'] ) {
- foreach( $widget_tags_not as $temp_tag) {
- if( (in_array( $temp_tag, $user_tags ) ) ) {
- $can_access = false;
- } else {
- $can_access = true;
- break;
- }
- }
- }
- }
- return $can_access;
- }
- add_filter( 'wpf_elementor_can_access', 'wpf_elementor_can_access', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement