Advertisement
verygoodplugins

Untitled

Sep 14th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1. function wpf_elementor_controls_section( $element ) {
  2.  
  3.     $element->add_control(
  4.         'wpf_not_any_all',
  5.         [
  6.             'label' => 'Must NOT have ALL tags (default = match any):',
  7.             'type' => \Elementor\Controls_Manager::SWITCHER,
  8.             'lable_on' => 'Yes',
  9.             'lable_off' => 'No',
  10.             'return_value' => 'yes',
  11.             'default' => 'no',
  12.         ]
  13.     );
  14.  
  15.     $element->add_control(
  16.         'wpf_tags_any_all',
  17.         [
  18.             'label' => 'Must have ALL tags: (default = match any)',
  19.             'type' => \Elementor\Controls_Manager::SWITCHER,
  20.             'lable_on' => 'Yes',
  21.             'lable_off' => 'No',
  22.             'return_value' => 'yes',
  23.             'default' => 'no',
  24.         ]
  25.     ); 
  26.  
  27. }
  28.  
  29. add_action( 'wpf_elementor_controls_section', 'wpf_elementor_controls_section' );
  30.  
  31.  
  32. function wpf_elementor_can_access( $can_access, $element, $user_tags ) {
  33.  
  34.     $widget_tags = $element->get_settings( 'wpf_tags' );
  35.     $widget_any_all = $element->get_settings_for_display();
  36.  
  37.     if( ! empty( $widget_tags ) ) {
  38.        
  39.         if( 'yes' !== $widget_any_all['wpf_tags_any_all']) {
  40.             $result = array_intersect( $widget_tags, $user_tags );
  41.        
  42.             if( empty( $result ) ) {
  43.                 $can_access = false;
  44.             }
  45.         }
  46.        
  47.         if( 'yes' === $widget_any_all['wpf_tags_any_all']) {
  48.             foreach( $widget_tags as $temp_tag) {
  49.                 if( ! in_array( $temp_tag, $user_tags ) ) {
  50.                     $can_access = false;
  51.                 }  
  52.             }
  53.         }  
  54.     }
  55.  
  56.     if( $can_access == true && ! empty( $widget_tags_not ) ) {
  57.  
  58.         if( 'yes' !== $widget_any_all['wpf_not_any_all'] ) {
  59.             $result = array_intersect( $widget_tags_not, $user_tags );
  60.  
  61.             if( ! empty( $result ) ) {
  62.                 $can_access = false;
  63.             }
  64.         }
  65.        
  66.         if( 'yes' === $widget_any_all['wpf_not_any_all'] ) {
  67.             foreach( $widget_tags_not as $temp_tag) {
  68.                 if( (in_array( $temp_tag, $user_tags ) ) ) {
  69.                     $can_access = false;
  70.                 } else {
  71.                     $can_access = true;
  72.         break;
  73.                 }  
  74.             }  
  75.         }  
  76.     }
  77.  
  78.     return $can_access;
  79.  
  80. }
  81.  
  82. add_filter( 'wpf_elementor_can_access', 'wpf_elementor_can_access', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement