Page Handling for Core pages?

I know that I can modify pages in other plugins with elgg_register_page_handler() in a new plugin. But is there such a feature for pages in the Elgg Core? For example I would like to change something in the file /pages/friends/index.php. How can I do this without hacking the core?

  • Its just like with other plugins. Either unregister the page handler and then register yours or use the root hook.

  • Example:

    elgg_unregister_page_handler('friends', 'friends_page_handler');
    elgg_unregister_page_handler('friendsof', 'friends_page_handler');

    elgg_register_page_handler('editors','theme_editors_page_handler');

     

    function theme_editors_page_handler($segments, $handler) {
        elgg_set_context('editors');
        
        if (isset($segments[0]) && $user = get_user_by_username($segments[0])) {
            elgg_set_page_owner_guid($user->getGUID());
        }
        if (elgg_get_logged_in_user_guid() == elgg_get_page_owner_guid()) {
            collections_submenu_items();
        }

        switch ($handler) {
            case 'editors':
                require_once(dirname(dirname(dirname(__FILE__))) . "/pages/friends/index.php");
                break;
            default:
                return false;
        }
        return true;
    }

     

    Check it on http://weborganizm.com

  • Ok, thanks to both of you.

    I did it exactly like you have suggested it. But my handler is routed to the home page. I suppose that something is wrong with the place I have stored the index.php. I put it to '/mod/myplugin/pages/friends/index.php'. And no matter if I am writing:

    require_once(dirname(dirname(dirname(__FILE__))) . "/pages/friends/index.php");

    or

    require_once(elgg_get_plugins_path() . "myplugin/pages/friends/index.php");

    It doesn't route to my index.php. Any hints?

     

  • I found the bug. It was the usual copy & paste error. ;-)

    I copied parts of the code from the original friends_page_handler() function in /engine/lib/users.php, but used in my plugin_friends_page_handler() function another name for the parameter $segments.

    Now it works fine.

    Thanks again for your help.