verygoodplugins

Untitled

Jan 20th, 2021 (edited)
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.27 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) {
  4.     exit; // Exit if accessed directly
  5. }
  6.  
  7. class WPF_Divi extends WPF_Integrations_Base {
  8.  
  9.     /**
  10.      * Gets things started
  11.      *
  12.      * @since 3.17.2
  13.      */
  14.  
  15.     public function init() {
  16.  
  17.         $this->slug = 'divi';
  18.  
  19.         add_filter( 'et_pb_all_fields_unprocessed_et_pb_section', array( $this, 'add_field' ) );
  20.         add_filter( 'et_pb_all_fields_unprocessed_et_pb_row', array( $this, 'add_field' ) );
  21.         add_filter( 'et_pb_all_fields_unprocessed_et_pb_column', array( $this, 'add_field' ) );
  22.         add_filter( 'et_pb_all_fields_unprocessed_et_pb_text', array( $this, 'add_field' ) );
  23.  
  24.         add_filter( 'et_pb_module_shortcode_attributes', array( $this, 'shortcode_attributes' ), 10 );
  25.  
  26.     }
  27.  
  28.     /**
  29.      * Add new field to Divi settings display
  30.      *
  31.      * @return  array Fields
  32.      */
  33.  
  34.     public function add_field( $fields ) {
  35.  
  36.         $fields['wpf_tag'] = array(
  37.             'label'       => 'Required tags (any)',
  38.             'type'        => 'text',
  39.             'tab_slug'    => 'custom_css',
  40.             'toggle_slug' => 'visibility',
  41.             'description' => 'Enter a comma-separated list of tags that are required to view this element.',
  42.         );
  43.  
  44.         return $fields;
  45.  
  46.     }
  47.  
  48.  
  49.     /**
  50.      * Shortcode attributes
  51.      *
  52.      * @return  array Shortcode atts
  53.      */
  54.  
  55.     public function shortcode_attributes( $props ) {
  56.  
  57.         if ( ! empty( $props['wpf_tag'] ) ) {
  58.  
  59.             $can_access = true;
  60.  
  61.             if ( wp_fusion()->settings->get( 'exclude_admins' ) == true && current_user_can( 'manage_options' ) ) {
  62.  
  63.                 $can_access = true;
  64.  
  65.             } else {
  66.  
  67.                 if ( ! wpf_is_user_logged_in() ) {
  68.  
  69.                     $can_access = false;
  70.  
  71.                 } else {
  72.  
  73.                     $setting_tags_string = explode( ',', $props['wpf_tag'] );
  74.                     $setting_tags        = array();
  75.  
  76.                     foreach ( $setting_tags_string as $tag ) {
  77.                         $setting_tags[] = wp_fusion()->user->get_tag_id( $tag );
  78.                     }
  79.  
  80.                     $user_tags = wp_fusion()->user->get_tags();
  81.  
  82.                     if ( empty( array_intersect( $user_tags, $setting_tags ) ) ) {
  83.                         $can_access = false;
  84.                     }
  85.                 }
  86.             }
  87.  
  88.             $can_access = apply_filters( 'wpf_user_can_access', $can_access, wpf_get_current_user_id(), false );
  89.  
  90.             $can_access = apply_filters( 'wpf_divi_can_access', $can_access, $props );
  91.  
  92.             if ( false === $can_access ) {
  93.                 $props['disabled'] = 'on';
  94.             }
  95.         }
  96.  
  97.         return $props;
  98.  
  99.     }
  100.  
  101. }
  102.  
  103. new WPF_Divi;
  104.  
Add Comment
Please, Sign In to add comment