Using plugin to replace code in specific pages

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Using plugin to replace code in specific pages

Post by Mythotical »

I'm wanting to know how I would replace code in the signup_page.php with my own form code. I'm also wanting to know how I can find the </head> tag and replace it with my code followed by the </head> tag.
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Using plugin to replace code in specific pages

Post by cas »

Plugins are event based, you can find those back in core/events_inc.php
You have various events available for the lay-out etcetra.
In addition you can add events yourself ( although this requires an adjustment of the core code).
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: Using plugin to replace code in specific pages

Post by Mythotical »

cas wrote: 27 Aug 2020, 15:36 Plugins are event based, you can find those back in core/events_inc.php
You have various events available for the lay-out etcetra.
In addition you can add events yourself ( although this requires an adjustment of the core code).
The problem with events is they aren't where I need. Such as EVENT_LAYOUT_RESOURCES, it loads my code before everything else and I need mine to be right before </head>.
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Using plugin to replace code in specific pages

Post by cas »

So you define your own event ( declare it within the plugin) and add the event statement @ the place where you require it.
If it needs to be right before the </head> statement, you need to declare your event within function html_head_end which you can find within core/html_api.php
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: Using plugin to replace code in specific pages

Post by Mythotical »

cas wrote: 27 Aug 2020, 16:41 So you define your own event ( declare it within the plugin) and add the event statement @ the place where you require it.
If it needs to be right before the </head> statement, you need to declare your event within function html_head_end which you can find within core/html_api.php
Since I'm new to coding a plugin for MantisBT. How do I declare it in my plugin and how do I add the event statement where I need it?
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Using plugin to replace code in specific pages

Post by cas »

you can find that in the developer guide which is included in your installation.
Clearly you need to insert the event command @ the location where you would need to execute the code you want
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: Using plugin to replace code in specific pages

Post by Mythotical »

I know how to trigger events but I wasn't sure about adding my own event to the core file because if I do that then it will get replaced on updates to Mantis so it would need to be done via a file similar to what we do with config_inc.php is that possible with adding my own event to html_api.php or is there a way to call the html_head_end function in my plugin to add code? If so, how? I'm a visual learn so sample code would help in the long run.
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Using plugin to replace code in specific pages

Post by cas »

you can try to declare the events in config_inc.php but you would still need to adjust the core file to insert it @ the right place. I am not aware of a plugin that allows you to dynamically change code.
In case you believe such an event to be essential, you can request to have it added in the next release ( following the procedure to get this done, available on the mantis website).
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: Using plugin to replace code in specific pages

Post by Mythotical »

After some testing I found I don't need a new point added but being able to replace the captcha that exists now with custom code would be needed without editing core files.
Post Reply