Help with custom plugin for an action when new user is added

Discussion in 'aMember Pro v.4' started by rance, Jan 27, 2013.

  1. rance

    rance aMember Pro Customer

    Joined:
    Dec 1, 2012
    Messages:
    42
    i want to listen for '
    SIGNUP_USER_ADDED"
    from amember available events..

    i wrote ​
    custom plugin..shown in API/Hooks Manager.. like this..


    class MyPlugin extends Am_Plugin
    {
    function onSIGNUP_USER_ADDED(Am_Event $event)
    {
    $event->addReturn($event->getX() + 1);
    }
    }

    Two part question:
    1. How do i get User object from Am_Event.. i am interested in getting username..
    2. once i have Username.. how can i call other website on same domain like xxx.com?username=?????
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Hi,
    First of all this will not work because function name is not correct.
    You should use: onSignupUserAdded(Am_Event $event)
    1. $user = $event->getUser();
    2. You should use Am_HttpRequest to make http requestrs from aMember:
    PHP:
    $r Am_HttpRequest('http://www.url.com/');
    $r->send();
  3. rance

    rance aMember Pro Customer

    Joined:
    Dec 1, 2012
    Messages:
    42
    I am still having issue with this.
    I created the plugin below:
    PHP:
    <?php
    class Am_Plugin_ivpmake extends Am_Plugin
    {
        function 
    onSignupUserAdded(Am_Event $event)
        {
            
    $user $event->getUser();
            
    $r Am_HttpRequest('http://dev.ivestplus.com/investage/userSignup.form');
            
    $r->send();
        }
    }
    ?>
    When I sign up, I am getting this error message:
    Fatal error: Call to undefined function Am_HttpRequest() in /var/www/amember/application/default/plugins/misc/ivpmake.php on line 7

    Any help would be greatly appreciated.
  4. rance

    rance aMember Pro Customer

    Joined:
    Dec 1, 2012
    Messages:
    42
    Made some headway. using "new" prior to "Am_HttpRequest" worked to hitting the outside server. However, I am not getting the user name.
    Any ideas how to get user name to show at end of url?
  5. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Something like this
    PHP:
    $user $event->getUser();
    $params = array(
        
    'username' => $user->login,
        
    'name_f' => $user->name_f,
        
    'email' => $user->email,
    );
    $url .= 'http://dev.ivestplus.com/investage/userSignup.form?' 
         
    http_build_query($params);
    $r = new Am_HttpRequest($url);
    $response $r->send();
    // $response->getStatus(); $response->getBody();
  6. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
  7. rance

    rance aMember Pro Customer

    Joined:
    Dec 1, 2012
    Messages:
    42
    Resolved: Thanks again for awesome support.
    I am including what worked for me in case it helps anyone else.
    PHP:
    <?php
    class Am_Plugin_ivpmake extends Am_Plugin
    {
        function 
    onSignupUserAdded(Am_Event $event)
        {
            
    $user $event->getUser();
            
    $username $user->login;
            
    $r = new Am_HttpRequest('http://www.myurl.com/platform/userSignup.form?username=' $username);
            
    $r->send();
        }
    }
    ?>

Share This Page