Advertisement
verygoodplugins

Untitled

Mar 18th, 2020
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) {
  4.     exit; // Exit if accessed directly
  5. }
  6.  
  7.  
  8. class WPF_Oxygen extends WPF_Integrations_Base {
  9.  
  10.     /**
  11.      * Gets things started
  12.      *
  13.      * @access  public
  14.      * @since   3.30.1
  15.      * @return  void
  16.      */
  17.  
  18.     public function init() {
  19.  
  20.         $this->slug = 'oxygen';
  21.  
  22.         add_action( 'init', array( $this, 'register_condition' ) );
  23.  
  24.     }
  25.  
  26.     /**
  27.      * Register custom Oxygen condition
  28.      *
  29.      * @access public
  30.      * @return void
  31.      */
  32.  
  33.     public function register_condition() {
  34.  
  35.         $available_tags = wp_fusion()->settings->get( 'available_tags', array() );
  36.  
  37.         $options = array();
  38.  
  39.         foreach ( $available_tags as $id => $label ) {
  40.  
  41.             if ( is_array( $label ) ) {
  42.                 $label = $label['label'];
  43.             }
  44.  
  45.             $options[ $id ] = $label;
  46.  
  47.         }
  48.  
  49.         $args = array(
  50.             'options' => $options,
  51.             'custom'  => true,
  52.         );
  53.  
  54.         $operators = array( __( 'Has tag', 'wp-fusion' ), __( 'Does not have tag', 'wp-fusion' ) );
  55.  
  56.         oxygen_vsb_register_condition( sprintf( __( '%s Tags', 'wp-fusion' ), wp_fusion()->crm->name ), $args, $operators, 'wpf_oxygen_condition_callback', 'User' );
  57.  
  58.     }
  59.  
  60.  
  61. }
  62.  
  63. /**
  64.  * Check conditions to determine visibility of component (this should really be in the class but Oxygen doesn't support array syntax for callbacks)
  65.  *
  66.  * @access public
  67.  * @return bool Can Access
  68.  */
  69.  
  70. function wpf_oxygen_condition_callback( $value, $operator ) {
  71.  
  72.     $can_access = true;
  73.  
  74.     if ( 'Has tag' == $operator && ! wp_fusion()->user->has_tag( $value ) ) {
  75.  
  76.         $can_access = false;
  77.  
  78.     } elseif ( 'Does not have tag' == $operator && ! wpf_is_user_logged_in() ) {
  79.  
  80.         $can_access = true;
  81.  
  82.     } elseif ( 'Does not have tag' == $operator && wp_fusion()->user->has_tag( $value ) ) {
  83.  
  84.         $can_access = false;
  85.  
  86.     }
  87.  
  88.     if ( wp_fusion()->settings->get( 'exclude_admins' ) == true && current_user_can( 'manage_options' ) ) {
  89.         $can_access = true;
  90.     }
  91.  
  92.     global $post;
  93.  
  94.     $post_id = 0;
  95.  
  96.     if ( ! empty( $post ) ) {
  97.         $post_id = $post->ID;
  98.     }
  99.  
  100.     $can_access = apply_filters( 'wpf_user_can_access', $can_access, wpf_get_current_user_id(), $post_id );
  101.  
  102.     return $can_access;
  103.  
  104. }
  105.  
  106. new WPF_Oxygen();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement