get_user by guid did't work

hi

i want to add step to my community to force followers paid before send validation mail

i add this code to uservalidationbyemail:

if ($email) {
            $guid=$session->get('userguid', '');
            $user=get_user($guid);
            $user->paid=false;
            return elgg_get_site_url() . 'uservalidationbyemail/pay';
        }

as you show i add metadata "paid" flag to check user paid

and then after they paid and 3d partner send me notifications to "pay" page

i make that

if ($paid==1) {
    $guid=$session->get('userguid', '');
    $user=get_user($guid);
    $user->paid=true;
    forward('uservalidationbyemail/emailsent');
}

but the problem the metadata didn't updated to true I try many ways without fix this problem if anyone have the solution please provide me with it

Regards

  • if ($email) {
        $guid = get_input('guid');
        $user = get_entity($guid);
        create_metadata($user->getGUID(), 'paid', FALSE, '', 0, ACCESS_PUBLIC);
        return elgg_get_site_url() . 'uservalidationbyemail/pay';
    }
    
    if ($paid == 1) {
        $guid = get_input('guid');
        $user = get_entity($guid);
        update_metadata($user->getGUID(), 'paid', TRUE, '', 0, ACCESS_PUBLIC);
        forward('uservalidationbyemail/emailsent');
    }

    Learn docs

  • thank you very much

    the create function work properly and I check the database and every thing OK.

    but the next section still not work and give me FATAL ERROR and I try to give update function GUID direct ;

    update_metadata($guid, 'paid', TRUE, '', 0, ACCESS_PUBLIC);

    The fatal error didn't appear but no update occur in database  .

  • Try this:

    update_metadata($guid, 'paid', 'paid', 'text', $guid, ACCESS_PUBLIC);

    In future, just call

    if ($user->paid == 'paid') {
    
      your action here
    
    }

    If it does not work still then post error log

     

    Also, you could rewrite create_metadata function:

    create_metadata($guid, 'paid', 'nopaid', 'text', $guid, ACCESS_PUBLIC);
  • No thing work and no metadata updated

    and when I try to use

    $user->getGUID()

    the fatal error happened .

    and please tell who to post error log because I didn't know where located .

  • How you get $guid? In my previous posts I meant that you can get it from input (guid') where 'guid' is a GUID of logged in user. And all happen in actions.

    If not then you can try to use:

    $user = elgg_get_logged_in_user_entity();
    
    $guid = $user->getGUID();

    Error log usually saved in server's log directory

  • I can get the GUID from by stored in session and I can access and I show it in

    tag [Tue Dec 20 22:19:47.529614 2016] [:error] [pid 3288:tid 1596] [client 127.0.0.1:56496] Exception at time 1482268787: Error: Call to a member function getGUID() on null in C:\\xampp\\htdocs\\lol\\mod\\uservalidationbyemail\\views\\default\\resources\\uservalidationbyemail\\pay.php:26\nStack trace:\n#0 C:\\xampp\\htdocs\\lol\\vendor\\elgg\\elgg\\engine\\classes\\Elgg\\ViewsService.php(362): include()\n#1 C:\\xampp\\htdocs\\lol\\vendor\\elgg\\elgg\\engine\\classes\\Elgg\\ViewsService.php(300): Elgg\\ViewsService->renderViewFile('resources/userv...', Array, 'default', true)\n#2 C:\\xampp\\htdocs\\lol\\vendor\\elgg\\elgg\\engine\\lib\\views.php(504): Elgg\\ViewsService->renderView('resources/userv...', Array)\n#3 C:\\xampp\\htdocs\\lol\\mod\\uservalidationbyemail\\start.php(210): elgg_view_resource('uservalidationb...')\n#4 [internal function]: uservalidationbyemail_page_handler(Array, 'uservalidationb...')\n#5 C:\\xampp\\htdocs\\lol\\vendor\\elgg\\elgg\\engine\\classes\\Elgg\\Router.php(95): call_user_func('uservalidationb...', Array, 'uservalidationb...')\n#6 C:\\xampp\\htdocs\\lol\\vendor\\elgg\\elgg\\engine\\classes\\Elgg\\Application.php(429): Elgg\\Router->route(Object(Elgg\\Http\\Request))\n#7 C:\\xampp\\htdocs\\lol\\vendor\\elgg\\elgg\\engine\\classes\\Elgg\\Application.php(377): Elgg\\Application->run()\n#8 C:\\xampp\\htdocs\\lol\\index.php(8): Elgg\\Application::index()\n#9 {main}

  • I can get the GUID from by stored in session

    You can't bcz

    Error: Call to a member function getGUID() on null

    Try my above solution

  • I get the same error

    let me description some thing that i feel that the cause the problem

    I read this function in view page "pay" and i think this function for that not work i must make action function and trigger after user register and another trigger after user paid

    but I am just used elgg for one month and it is not easy to do that.

  • Combine 2 action (emailconfirm and pay) in one: just add my above code to resources\uservalidationbyemail\confirm.php where use $user_guid instead my $guid

  • User validation plugin disables entities so you need to enable hidden entities before loading a user. See an example in register action - see how username is validated.