Overriding a method of a class

Elgg 2.3.14

In my_plugin I need to override one method in a class of another_plugin.

I tried to use elgg_register_class() but it did not work. Maybe I made some mistake.

The class reside in:


Thank you for your guidance.

  • Easy method:



    To your plugin


    And change this

    namespace some_folder;


    namespace my_folder;

    Edit in start.php of your plugin code where this class calls using elgg_unregister_plugin_hook_handler and elgg_register_plugin_hook_handler hooks.


    elgg_unregister_plugin_hook_handler('register', 'menu:entity', '\some_folder\class_name::setupMenu');
    elgg_register_plugin_hook_handler('register', 'menu:entity', '\my_folder\class_name::setupMenu');

    You can find more in the existing plugins.


    Advanced method:

    Use Extending.

  • The "Easy method" works fine.

    I do not have menu links for this class but calls from an action. And also the class calls other siblings in the original namespace. So I adjusted the "use" calls and it works perfect.

    Thank you very much RvR for the useful and detailed answer.

  • I do not have menu links

    It was an example only for understating what you can do ;)