How do I find a users GUID

I am trying to implement the plugin be_tom.  It requires that I know the GUID of the person I want to be Tom.  Where can I find the GUID?

Thanks

  • I have an edited plugin laying arround to find the guid of a user I'll package it up and post it here, it's just an edited version of user_contact_list.

  • Here's the zipped up edited plugin:

    www.robertscmc.com/mf_user_contact_list.zip

    Just remove line 18 and 27 in the start.php file because those lines limit plugin access to guid 2 who is an admin so just remove those lines and  all admins can now see the plugin in the admin menu... hope this helps :)

  • $username = "admin";
    echo "\n*** fetch user=($username)";
    echo "\n*** get_user_by_username";
    $user = get_user_by_username($username);
    if ($user) {
            echo "\n*** user($username) FND OK";
            $userGuid = $user->getGUID();

    this will give you guid for a given username

    Also Table: elgg_users_entity display in phpmyadmin -->
    you can also browse to your hearts content ; -)

  • so many ways to skin the cat... ;-)

  • Thanks for the info.  I was able to find the GUID but the "be tom" plugin failed to work.  Below is the code I had to modify.  My GUID is "129".  Did I fill in the info correctly?

    <?php

    /* Be Tom - Elgg plugin to automatically add the user you specify as friends with every new user that registers on your site.
     *
     * Instructions:
     * *************
     * 1) Find the GUID for the user you want to be Tom.
     *     If you don't know how a simple way is to look at any of
     *     the action links on their profile and in the link there will
     *     be a part where it says guid=123. 123 is what you want.
     * 2) Put that GUID below in the $friend_guid = 2; line
     * 3) Decide if you want to get emails when people join and become your friend automatically.
     *     By default this is set to not allow the emails to get sent out.
     *     To change it look below for $i_want_emails = false; and make it $i_want_emails = true;
     *
     * And of course check out my Elgg blog for updates, mods, and articles about setting my own Elgg based site up.
     * Blog: http://www.addicted2kicks.com/devblog/
     * Elgg Site: http://www.addicted2kicks.com/
     *
     * Version 1.0 - Zac
     * It's a low priority, but a future todo item will be a page in the admin interface to allow you to
     * configure this plugin easily w/o messing with code. It's a very low priority, but if there is a lot
     * of interest I will start on it.
     */
     
    function betom_init(){
     global $CONFIG;
     register_elgg_event_handler('create', 'user', 'AutoAddFriend',501);
    }

    function AutoAddFriend($event, $object_type, $object){
     global $CONFIG;
     
     $friend_guid = 129; //REPLACE THE GUID # HERE WITH THE ONE YOU WANT!
     
     if($friend = get_entity($friend_guid)) {
      //READ ME: If you want your 'Tom' to receive emails every time someone registers (it'll be the friend added email) then you
      //need to set the below variable to false instead of true.
      $i_want_emails = true;
      
      if(!$i_want_emails) {
       //The engine/lib/relationships.php file would usually catch the friend created event and send an email to our Tom.
       //This will prevent that by removing any hooks that would handle the friend created event.
       //This will also stop any other plugins from interfering with our friend add process (say a friend request plugin)
       if(isset($CONFIG->events['create']['friend'])) {
        $oldEventHander = $CONFIG->events['create']['friend'];
        $CONFIG->events['create']['friend'] = array();   //Removes any event handlers
       }
      }
      
      try {
       $_SESSION['user']->addFriend($friend_guid);
      } catch (Exception $e) {
      }
      
      //If we disabled any events below then reenable them:
      if(!$i_want_emails) {
       if(isset($CONFIG->events['create']['friend'])) {
        $CONFIG->events['create']['friend'] = $oldEventHander;
       }
      }
     }
    }

     

    register_elgg_event_handler('init', 'system', 'betom_init');

    ?>