Extension devolpment; Where to put helper functions?

Like the title says; Convention wise, where to place helper functions.

Currently i am putting them in the main extension file, but it feels not the right place. I have tried creating a helpers.php in the /includes/ folder, however it does not seem to get loaded.

Hi,

Thanks for the request. Please describe your use case in more detail, and we will try to provide a solution or workaround. Also, please review this doc: Getting started | Developer Docs

My use case is the exact same as hivepress core:

Helper functions in the helper.php HivePress Code Reference.

So, when developing an extension, according to the conventions of hivepress, where to place the helper functions.

Hi,

Thanks for the details. Yes, the helpers.php file is loaded in the core only, it works this way to prevent function naming issues, since there’s the same namespace.

There are 3 ways to keep helper functions, if they have no specific context:

  • Create a custom component to access functions via hivepress()->mycomponent->function();
  • Create a custom helpers.php file and load it via require_once in the main extension file
  • Keep them at the bottom of the main extension file (a bit hacky but works fine)

Hope this helps

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.