BBpress: Create new roles from a separate php file


I want to add new roles to BBpress. I have a functioning code if I add it directly to functions.php, but I would like to add it to a separate file called bbpress.php in /app folder in order to organize everything.

I tried to add the file in the following code:

array_map(function ($file) use ($sage_error) {
$file = “…/app/{$file}.php”;
if (!locate_template($file, true, true)) {
$sage_error(sprintf(__(‘Error locating %s for inclusion.’, ‘sage’), $file), ‘File not found’);
}, [‘helpers’, ‘setup’, ‘filters’, ‘admin’]);

It does not work and I think the problem is that the creation of roles need to be called at a later stage for it to work.

What is the best way to do this with Sage 9.0?

Thanks in advance

@pete87p the BEST way to do this is as a separate plugin, but to answer your actual question:

  1. Create a new file in app named bbpress.php
  2. In that file, add the following:

namespace App;

// Your BBpress actions and filters here
  1. Edit resources/functions.php and add your new file to the array on line 61:
['helpers', 'setup', 'filters', 'admin', 'bbpress']
  1. That’s it! You’re done!

Many thanks @MWDelaney

This topic was automatically closed after 42 days. New replies are no longer allowed.