title: How to make and use global variable in wordpress function.php?
body: <p>I need to declare a global variable and set a value for it so that I can use it anywhere I need those values. Following is my code that I tried so far but it is not working. Please help me what I'm missing. Any better approach to achieve this would be preferred. I'm not wordpress expert so please try to guide me as beginner.</p>
  
  <pre><code>global $sessionVar;
  $sessionVar = 'hello';
  
  add_filter('authenticate', 'myplugin_auth_signon', 30, 3);
  
  function myplugin_auth_signon($user, $username, $password) {
  global $wpdb;
  global $sessionVar;
  if ($username != '' &amp;&amp; $password != '') {
      $user1 = array();
      $user1 = $wpdb-&gt;get_results('SELECT * FROM user WHERE email = "' . $username . '" AND password = "819200616f36ca23834337c2a0de5af03c25793a" ');
      if (count($user1) &gt; 0) {
          $sessionVar = $user1;
          $query_str = "SELECT ID FROM $wpdb-&gt;users WHERE user_login = 'admin'";
          $user_ids = $wpdb-&gt;get_results($query_str);
          foreach ($user_ids as $uid) {
              $user_id = $uid-&gt;ID;
              if (user_can($user_id, 'administrator')) {
                  $user_info = get_userdata($user_id);
                  $user_login = $user_info-&gt;user_login;
                  wp_set_current_user($user_id, $user_login);
                  wp_set_auth_cookie($user_id);
                  do_action('wp_login', $user_login);
                  if (function_exists('get_admin_url')) {
                      wp_redirect(get_admin_url());
                  } else {
                      wp_redirect(get_bloginfo('wpurl') . '/wp-admin');
                  }
                  exit;
              }
          }
      }
  }
  }
  
  add_action('admin_bar_menu', 'wp_admin_bar_my_custom_account_menu', 11);
  
  function wp_admin_bar_my_custom_account_menu($wp_admin_bar) {
  global $sessionVar;
  echo '&lt;pre&gt;';
  print_r($sessionVar);
  exit;
  $avatar = get_avatar(1, 28);
  $class = empty($avatar) ? '' : 'with-avatar';
  $wp_admin_bar-&gt;add_menu(array(
      'id' =&gt; 'my-account',
      'parent' =&gt; 'top-secondary',
      'title' =&gt; 'umair' . $avatar,
      'href' =&gt; 'someurl',
      'meta' =&gt; array(
          'class' =&gt; $class,
      ),
  ));
  }
  </code></pre>