title: Event handling in Moodle 2.8
body: <p>The objective is to copy two custom profile fields into the user table upon user create or update using the event triggers by the same name.  But for some reason, the events are not triggering.  I created a new module for /local/newuser with the required three files, as shown below.</p>
  
  <p>Any and all hints would be appreciated.</p>
  
  <p>Code from events.php</p>
  
  <pre><code>defined('MOODLE_INTERNAL') || die();
  
  $handlers = array (
      'user_updated' =&gt; array (
          'handlerfile'      =&gt; '/local/newuser/lib.php',
          'handlerfunction'  =&gt; 'local_newuser_user_updated',
          'schedule'         =&gt; 'instant',
      ),
  
      'user_created' =&gt; array (
          'handlerfile'      =&gt; '/local/newuser/lib.php',
          'handlerfunction'  =&gt; 'local_newuser_user_created',
          'schedule'         =&gt; 'instant',
      ),
  );
  </code></pre>
  
  <p>code from lib.php</p>
  
  <pre><code>defined('MOODLE_INTERNAL') || die();
  
  function local_newuser_user_updated($user) {
      require('../../config.php');
      global $DB;
      $userid = $user-&gt;id;
      $data1 = $DB-&gt;get_field_select('user_info_data', 'data', 'userid='.$userid.' AND fieldid=1', null);
      $data2 = $DB-&gt;get_field_select('user_info_data', 'data', 'userid='.$userid.' AND fieldid=2', null);
      if ($data1 !='' ) {
          $sql="UPDATE {user} set idnumber='$data1',department='$data2' where id=$userid";
          $DB-&gt;execute($sql);
      }
      return true;
  }
  
  function local_newuser_user_created($user) {
      require('../../config.php');
      global $DB;
      $userid = $user-&gt;id;
      $data1 = $DB-&gt;get_field_select('user_info_data', 'data', 'userid='.$userid.' AND fieldid=1', null);
      $data2 = $DB-&gt;get_field_select('user_info_data', 'data', 'userid='.$userid.' AND fieldid=2', null);
      if ($data1 !='' ) {
          $sql="UPDATE {user} set idnumber='$data1',department='$data2' where id=$userid";
          $DB-&gt;execute($sql);
      }
      return true;
  }
  </code></pre>
  
  <p>And of course, version.php</p>
  
  <pre><code>defined('MOODLE_INTERNAL') || die();
  
  $plugin-&gt;version   = 2014030200; // Plugin version.
  $plugin-&gt;requires  = 2013051402; // Moodle version.
  $plugin-&gt;component = 'local_newuser'; // Full name of the plugin (used for diagnostics).
  </code></pre>