If you like one of my plugins, then please consider donating a small amount towards my time and effort in developing and maintaining them.

Introduction

bbpress allows the creation of custom roles.

However the latest combination of WordPress and bbPress does not work if the code to do this is in the functions.php file of the child theme (or indeed parent theme!).

The code is shown in the bbpress documentation

If you put this code in a plugin, it seems to work fine.

Why does this not work

You can skip reading this if you just want the solution below !

bbpress uses WordPress roles and capabilities functionality.

WordPress loads both roles and capabilities as pages are rendered for the browser. These are created from code and database entries BUT held in a variable/variables for speed of execution.

My suspicion is that WordPress creates these variables after plugins have loaded, but before the child theme functions have executed, and therefore the filters are not executed correctly so don’t take effect.

I could spend days working out the solution, but the simple answer is below

Solution

My assumption is that as you are using code, you are comfortable in changing files and FTPing them to your site.

So
1. Install a plugin

This plugin is 3 lines long, so will not slow your site !!

a. Download this plugin using the link below
b. Go to Dashboard>plugins>add new
c. Click Upload, and select the file
d. Click install
e. and then activate

2. Download, amend and upload to your child theme a role-functions.php file

For a single file – download this file

For multiple roles – download this file

Once downloaded, unzip and open the file and amend as desired – I use Notepadd ++ as my code editor – it is excellent, but any plaintext editor will work

Then FTP this file to your child theme so you end up with a file here
ie wp-content/themes/%your-theme-name%/role-functions.php
where %your-theme-name% is the name of your theme