HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpemobiq/wp-content/plugins/zendesk/classes/zendesk-wordpress-agents.php
<?php

/*
 * The Zendesk Agents Class
 *
 * This has all the helper methods to use when dealing with zendesk agents
 *
 */

class Zendesk_Wordpress_Agents {
  protected static $instance = null;

  /*
   * get an instance of this class
   */
  public static function get_instance() {
    if ( is_null( self::$instance ) ) {
      self::$instance = new self();
    }

    return self::$instance;
  }

  /*
   * Helper: Is Agent
   *
   * A conditional function that returns true if the current or
   * specified Zendesk user is an agent, otherwise returns false,
   * meaning that it's probably an end-user.
   *
   */
  public function _is_agent( $user_ID = false ) {
    global $zendesk_support;

    // Current user or a specific user ID.
    $zendesk_user = $user_ID ? get_user_meta( $user_ID, 'zendesk_user_options', true ) : $zendesk_support->zendesk_user;

    // Check for actual value, expect admin or agent as value 
    return ( isset( $zendesk_user['role'] ) && in_array( $zendesk_user['role'], array( 'admin', 'agent' ), true ) );
  }

  /*
   * Helper: Get Zendesk_Wordpress_Agents
   *
   * Scans the WordPress database for all users that are authenticated with
   * Zendesk and whose roles are agents.
   *
   */
  public function _get_agents() {
    // 20150430-MM Before this we were retrieving all the users of the blog, to
    // then loop trough the results and check if each of them _is_agent()
    // This could create memory problems for blogs with thousands of users, so
    // now we retrieve only users that we know for sure are authenticated with
    // Zendesk, using the Zendesk user options key as a filter
    $args  = array(
      'blog_id'      => get_current_blog_id(),
      'meta_key'     => 'zendesk_user_options',
      'meta_value'   => null,
      'meta_compare' => '!=',
    );
    $users = get_users( $args );

    $data = array();

    foreach ( $users as $user ) {
      if ( $this->_is_agent( $user->ID ) ) {
        $data[] = get_userdata( $user->ID );
      }
    }

    return $data;
  }

  /*
   * Helper: Get Agent
   *
   * Returns the Zendesk user options for the requested user ID.
   *
   */
  public function _get_agent( $user_ID ) {
    if ( ! $this->_is_agent( $user_ID ) ) {
      return false;
    }

    return get_user_meta( $user_ID, 'zendesk_user_options', true );
  }

}