How to override a core library function and replace it with a plugin function

Hi everyone,

I want to override a core library function named tags.php and replace it with the function with similar name in /lib directory of my plugin. I've tried writing elgg_register_library('tags', elgg_get_plugins_path().'my_plugin/lib/tags.php'); in start.php file of my plugin (inside my_plugin_init function) but it doesn't work. how can I do that ?

I've read previous discussion about this issue but the answers were ambiguous, so I'd really appreciate that you help me with writing the proper code for this matter (and not just explaining by words)

Thanks in advance


  • You cannot override those functions.

    What is it you're trying to accomplish? That would help us give you a better direction to go.

  • Ok, I want to change tags delimiter from ',' to '-' by changing implode and explode functions. how can I do that properly so that all tags inputs and outputs are affected? 

  • Changing the tag delimiter would be difficult to do correctly. Here's one hack:

    1. override the css/elements/components view and change the .elgg-tags li.elgg-tag:after rule.
    2. override the input/tags view and change the implode there.
    3. register for the plugin hook ("action", "all"). In your handler function, do something like this:
    $tags = explode("-", get_input("tags", ""));
    set_input("tags", implode(",", $tags));

    This should work for each form that uses "tags" as the name of the input/tags view, but blindly rewriting input is a brittle solution.

    My advice is to not do this.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking