What plugin hook should I write to get the profile page owner?

How can I get the ownerguid of a current profile in another plugin?I did it by unregistering the default profile pagehandler and then registering a new profile pagehandler in my plugin. Is there any other easier/better way of achieving it?

  • get_input('username')

    get_user_by_username()

    won't that work?

  • No, it wont. I tried all possible things. Even tried elgg_get_page_owner_guid(), which is returning "0"/null

  • it would help to know what you are trying to do. are you creating a widget?

  • No, I want to show my user(Mr.X) a system message when they are looking at another user profile (Mr.Y). If I can get the Mr.Y guid, then it is easier. I can do this by overriding the profile page or a component of it. But I am trying to do it through the start.php itself. Any idea?

  • Hmmm. Quite strange. I can't get the guid either, even though the page_handler is setting the page_owner guid...

    function profile_page_handler($page) {

     

    if (isset($page[0])) {

    $username = $page[0];

    $user = get_user_by_username($username);

    elgg_set_page_owner_guid($user->guid);

    }

     

    // short circuit if invalid or banned username

    if (!$user || ($user->isBanned() && !elgg_is_admin_logged_in())) {

    register_error(elgg_echo('profile:notfound'));

    forward();

    }

     

    $action = NULL;

    if (isset($page[1])) {

    $action = $page[1];

    }

     

    if ($action == 'edit') {

    // use the core profile edit page

    $base_dir = elgg_get_root_path();

    require "{$base_dir}pages/profile/edit.php";

    return;

    }

     

    // main profile page

    $params = array(

    'content' => elgg_view('profile/wrapper'),

    'num_columns' => 3,

    );

    $content = elgg_view_layout('widgets', $params);

     

    $body = elgg_view_layout('one_column', array('content' => $content));

    echo elgg_view_page($user->name, $body);

    return true;

    }

  • Yes, thats the problem. May be a bug?

  • Just checked. Not a bug. 

    You need to call page_owner from a view. You can't do it from the init. 

     

  • That means, its a must for me to override the profile page view,right?. Isn't there any other option to get it by a plugin view hook or something?

  • Remember that there is a pagesetup event that is called immediately before views are rendered. You can register a hook for that and check the page context and owner there.

  • Kevin, tried the elgg_register_event_handler('pagesetup', 'system', 'getPvalue'); But still get nothing. Any idea?.

Feedback and Planning

Feedback and Planning

Discussions about the past, present, and future of Elgg and this community site.