We still use bbPress version 1 on some of our websites. It’s powerful and integrates well with WordPress. Alas the recently released upgrade to WordPress 4.0 breaks the integration and here are the steps for all of you who need to resolve this issue right now. In case you are wondering, for simple customisable forums, bbPress 1 absolutely rocks.
If you wonder why we still use bbPress version 1:
- We like its permalinks more than permalinks of bbPress version 2 (although we know enough about customizing WordPress rewrite rules, it’s still a big job)
- The integration with WordPress is only partial (no plugins load, so it’s faster)
- WordPress.org still uses bbPress 1.1 on their support forums (check generator meta tag here)
WordPress 4.0 forces the upgrade so you may have some clients in extreme pain. No need to panic. With two simple steps you can make WordPress 4.0 and bbPress 1 completely compatible again.
Note: This will only help if you integrate your bbPress with your WordPress by including wp-load.php.
-
Edit
bb-includes/backpress/class.wp-auth.php
– add following code right at the start of thevalidate_auth_cookie()
function of theWP_Auth
class (find function validate_auth_cookie(…) and enter it right behind the opening bracket {):return wp_validate_auth_cookie( $cookie, $scheme );
WordPress 4.0 changed the cookie format and also the hash function, so without this fix bbPress won’t understand that you are logged in.
-
If you use some advanced permission checks for WordPress capabilities, replacebb_get_current_user()
withwp_get_current_user()
.Update: Edit
bb-includes/backpress/class.wp-users.php
– add following code into functionWP_Users::get_user()
after the line which says$user = wp_cache_get( $_safe_user_id, 'users' );
$user_meta = wp_cache_get( $_safe_user_id, 'user_meta' ); foreach( $user_meta AS $k => $i ) { if( count($i) == 1 && isset($i[0]) ) { $user_meta[$k] = $i[0]; } } $user_meta = array_map( 'maybe_unserialize', $user_meta ); foreach( $user_meta AS $k => $i ) { $user->{$k} = $i; }
WordPress 4.0 user and user meta object cache is no longer compatible with bbPress 1.x. The above it a little bridge which makes sure the required user meta values are present and bbPress user capability checks can function. Without the above fix, bbPress admin backend (bb-admin) won’t work.
- If the above step doesn’t help with broken access into bb-admin and you use s2Member, review your user user_meta and make sure
bb_capabilities
has value ofa:1:{s:9:"keymaster";b:1;}
. s2Member bbPress bridge demotes the admin users to regular users if the required user meta value is not found.
So if you are having trouble with bbPress 1 integration, no need for any rushed migrations to bbPress 2, BuddyPress, vBulletin, Vanilla or anything else. Just keep enjoy the simple life.
Martin Viceník
Martin graduated as an engineer in Computer Science from Slovak Technical University in Bratislava. He grew up in Liptovský Mikuláš in northern Slovakia next to the beautiful Tatra mountains. He is the developer behind our FV Player.
Hi!
The first step (return wp_validate_auth_cookie( $cookie, $scheme );) wowking fine. Without having done this I was not able to visit bbpress part of my website at all.
But anyway, after implementation of the step above I am able to access the bbpress but I am not able to access the admin area of the bbpress.
Where exactly should the described replacement (bb_get_current_user() with wp_get_current_user().) take place?
Thanks a lot!
Thanks for this, I added a topic on bbPress.org and in our Codex docs linking back here :)
bbpress.org/forums/topic/bbpress-1-x-stand-alone-integration-and-wordpress-4-0/
codex.bbpress.org/legacy/integrating-with-wordpress/
Hello Martin and Stephen,
thank you for your feedback!
I updated the article with instructions about how to fix the broken bbPress admin section (bb-admin), as there is a problem in how WordPress 4.0 caches the user meta in object cache – bbPress can’t read it anymore.
We tried to also disable the object cache, but then we got hundreds of SQL queries on every page.
Thanks, Martin
Hi, where should i exactly place
return wp_validate_auth_cookie( $cookie, $scheme );
Is it not possible to upload to 2 new files?
Regards, Sat
Hello Sat,
just look for the function called “validate_auth_cookie” and put it behind the opening curly bracket.
You can download the fixed files here, but we only tested it on bbPress 1.0.3. So you need to backup your original files in case you have a different version and you want to check if our fixed files work for you: foliovision.com/downloads/bbpress-1-0-3-wordpress-4-0-fix.zip
Thanks, Martin
Martin thanks for your reply.
I have bbPress 1.1-alpha-2539. I tried to replace the files but i got an internal server error,
Thanks, Sat
Hi Sat,
Sorry to hear about your issues.
We’d be happy to investigate your site personally as a pro support incident.
Cordial regards,
Alec
Hi
I get this error upon changing the files, bbPress 1.2
Warning: Invalid argument supplied for foreach() in /home/xxxxx/public_html/f/bb-includes/backpress/class.wp-users.php on line 279
Warning: array_map(): Argument #2 should be an array in /home/xxxxx/public_html/f/bb-includes/backpress/class.wp-users.php on line 284
Warning: Invalid argument supplied for foreach() in /home/xxxxx/public_html/f/bb-includes/backpress/class.wp-users.php on line 285
Hi Chris,
Thanks for the info.
We aren’t running v. 1.2. If you come up with solution please let us know so we can help other bbPress 1.2 users update.
Thanks!
Hi Martin
this code return wp_validate_auth_cookie( $cookie, $scheme ); do multiple loop until the page down.
Any ideas?
Thanks
I got server error too, when i replaced the files.
Hello Fridayana and Sim,
what bbPress versions are you using? What do you see in the PHP error log? What error are you getting? Is it a “soft” error, or do you get HTTP Error 502?
Our fix appears to work for version 1.0.3 only.
We can’t really fix this without installing your website and having a look. As Alec noted above, we can have a look at the issue at your site if you purchase a pro support incident.
Thanks, Martin
Hi Martin,
The error is 500 – internal server error. I have also version 1.0.3
I don’t find this code WP_Auth::validate_auth_cookie() in bb-includes/backpress/class.wp-auth.php
Hello Sim,
WP_Auth::validate_auth_cookie() is the name of the class together with the name of the function.
Just look for:
function validate_auth_cookie( … ) {
And add it right after the opening {. I updated the article as well.
Thanks, Martin
Hi Martin,
I did this (previously i replaced files with one you posted here) and still there is 500 server error.
Thanks for keeping posting.
Hello Sim,
what about the PHP error log? You should be able to find it as a error_log file in the forum directory, or it might be in logs or directory of your site folder or your web server, depending on what setup you use.
Thanks, Martin
Hi Martin,
I don’t find any error log. When I add the code to class.wp-auth.php i get the 500 server error code and it shows hostgator website (since I host website there)
Hello Sim,
you could try to contact your server support to help you with locating the PHP error log.
Thanks, Martin
Hmmm, I have BBPress version 1.0.2 and just after adding: return wp_validate_auth_cookie( $cookie, $scheme );
in file: bb-includes/backpress/class.wp-auth.php
at line: 144
(as a first line of validate_auth_cookie function)
I am getting: [error] [client 127.0.0.1] PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 130968 bytes) in /path/to/bbpress/bb-includes/backpress/class.bp-log.php
I am investigating, but maybe you have already had that issue…
Warning: Undefined array key 1 in /srv/users/fvision-staging/apps/staging-foliovision/public/site/wp-content/plugins/thoughtful-comments/fv-thoughtful-comments.php on line 1449
Warning: Undefined array key 1 in /srv/users/fvision-staging/apps/staging-foliovision/public/site/wp-content/plugins/thoughtful-comments/fv-thoughtful-comments.php on line 1449
Warning: Undefined array key 1 in /srv/users/fvision-staging/apps/staging-foliovision/public/site/wp-content/plugins/thoughtful-comments/fv-thoughtful-comments.php on line 1450
There is something wrong. If I turn off logging, I get memory problems elsewhere. Those guys are also reporting similar/memory problem: wpml.org/forums/topic/fatal-error-allowed-memory-size-in-wpml-config-class-php/ wordpress.org/support/topic/pro-fatal-error-after-todays-update after upgrade…
My abouts: PHP Version 5.4.4-14+deb7u12 memory_limit 512M
I cant belive the solution is to go over 512M…
Any idea???
I am not sure I do understand BBPress correctly, but it seems like calling wp will call bb just with logging a call to deprecated code. In our case global function wp_validate_auth_cookie calls global function bb_validate_auth_cookie, which then basically calls a method on the object $wp_auth_object->validate_auth_cookie that we just changed.
This looks like a loop.
@Martin: can you please explain more? Do I understand it correctly?
Hello JH,
thank you for your thoughts! The links about memory issues don’t appear to be related though.
This could indeed by some php loop. Your assumptions about bb and wp functions are correct, but let’s stop here – notice that wp_validate_auth_cookie() only calls bb_validate_auth_cookie() if it’s not previously defined. And it should be defined from WordPress already. Perhaps your integration with WordPress works differently.
Could you please check where do you include Your WordPress’ wp-load.php in your bbPress install? We have it in bb-config.php, so it loads before bbPress and wp_validate_auth_cookie() is then defined.
Thanks, Martin
Well, my installation doesnt share/(re)include any file(s) between wp and bb. Are you including something from wp? Or define it before BBPress standard does it?
Lets find wp/bb function definitions or calls (in the BBPress directory): [code] grep -rin “_validate_auth_cookie” [/code]
Result: [code] bb-includes/backpress/class.wp-auth.php:107: * @uses wp_validate_auth_cookie() Retrieves current logged in user. bb-includes/backpress/class.wp-auth.php:147:// return wp_validate_auth_cookie( $cookie, $scheme ); bb-includes/functions.bb-deprecated.php:838:if ( !function_exists( ‘wp_validate_auth_cookie’ ) ) : // Deprecated in bbPress not WordPress bb-includes/functions.bb-deprecated.php:839:function wp_validate_auth_cookie( $cookie = ”, $scheme = ‘auth’ ) { bb-includes/functions.bb-deprecated.php:840: bb_log_deprecated( ‘function’, FUNCTION, ‘bb_validate_auth_cookie’ ); bb-includes/functions.bb-deprecated.php:841: return bb_validate_auth_cookie( $cookie, $scheme ); bb-includes/functions.bb-pluggable.php:5: if ( !bb_validate_auth_cookie( ”, $scheme ) ) { bb-includes/functions.bb-pluggable.php:141:if ( !function_exists( ‘bb_validate_auth_cookie’ ) ) : bb-includes/functions.bb-pluggable.php:142:function bb_validate_auth_cookie( $cookie = ”, $scheme = ‘auth’ ) { [/code]
2nd line in that output is commented out -> thats change suggested on this page (line numbers below might be shifted).
It is a standard integration with shared cookies (BBPPress on subdomain) with user database sharing, nothing really fency/custom.
Anyway, it means that you have this function defined elsewhere. Can you check your installation and paste your code in here?
I do not have any PATH / DIR constants defined to the WordPress directory, I also checked if anything is hardcoded – nothing like that. So BBPress has no way to include anything from WordPress.
Martin, can you explain your solution? What is its background, how did you came to it? Maybe I am missing something less or more obvious?
Function definitions (conditional as you already noticed) are – as listed above – here: [code] bb-includes/functions.bb-deprecated.php:839 bb-includes/functions.bb-pluggable.php:142 [/code]
I do not see any other place where those functions are defined.
PS. I wish there was a way to use codes like [img] or [code] (I do not see the toolbar, so I suspect it is not possible)
Cant edit comment, sorry for spam :) I didnt see the part where you say you include wp-load… Woow, thats a big change… Did you do it becouse of WP4.0, or any other reason?
Hello JH,
our bb-config.php includes wp-load.php of our WordPress to enable integration – mainly single-login and main menu.
If your bbPress doesn’t work this way, then I’m not sure why your are having any issues after upgrade to WordPress 4.0. Are you sure you have this problem and it’s not something else?
Oh, I see, you use the same cookies and WordPress changed the format of these cookies. We load WordPress in bbPress, so we are able to use its core functions. If you don’t load WordPress, then you can’t use it’s functions (which work with the new cookie data) and our solution won’t work for you.
You can try including wp-load.php. It only caused issues for us when we used “WordPress HTTPS (SSL)” plugin (now the plugin is outdated).
Thanks, Martin
Hi Martin,
I don’t have included wp-load.php in your bbPress install. How to add it to bb-config.php?
Thanks
Hello Sim,
let’s assume that your WordPress is in /home/your-account/public_html (so you can see wp-load.php in there) and your bbPress is in /home/your-account/public_html/forum.
In that case, put following at the start of /home/your-account/public_html/forum/bb-config.php (after the opening <?php tag):
require_once(dirname(FILE) . ‘/../wp-load.php’); // make sure you convert the quotes to normal non-UTF-8 quotes!
Hopefully that will resolve the issue. I suggest you test your forum functionality carefully after doing this (logged in as admin, logged in as normal user, not logged in, also bb-admin section as admin).
Thanks, Martin
Hi Martin,
I added this line require_once(dirname(FILE) . ‘/../wp-load.php’); in bb-config.php, and I got a blank page in forum. Maybe should I include any other code in the wp-load.php
Thanks for posting.
Hello Sim,
make sure you change the ‘ and ’ to regular quotes and it should work. Otherwise look into PHP error log.
WordPress automatically changes normal quotes to fancy UTF-8 quotes in comments, and I forgot about that, so you probably copied damaged code, sorry about that.
Thanks, Martin
Hi Martin,
I already take care about the ‘ and ‘, but still same error, blank page. Here the error log
PHP Fatal error: Call to a member function get() on a non-object in /home1/name/public_html/wp-includes/cache.php on line 113
Hello Sim,
I think we got similar issue when using the WP HTTPS plugin (see above: foliovision.com/2014/09/wordpress-original-bbpress#comment-4895651 )
Solving this is not easy, you can start by trying to disable your plugins one by one. Or you can rename the plugins folder in your wp-content for a minute just to see if it helps if you are experienced. However don’t visit your wp-admin plugins section in this time, otherwise the plugins will all deactivate.
Thanks, Martin
Hi Martin,
Thanks for keep posting. I don’t know, but still it was impossible for me to have wp site and bbpress connected. Previously I cookies worked well, so users who are logged in wp can be automatically logged in bbpress.
Anyway, thank you.
This worked perfectly for me… thank you for this!
Works well, except i can no longer post any new topics, the post form is no longer visible. post_form() only prints out the form header, nothing else. Please help.
Hi Paul,
You may need a more experienced developer at this point, not a coach. Try the same technique on a clean install and see if it works for you, as it has for others.
Hi Everyone,
We’re preparing to migrate to bbPress 2 (we’re finally giving in) as there’s some nice plugins available for bbPress 2 which will replace our custom moderation code with a bit of tweaking.
I know bbPress 1.2 or 1.1 is now antique and old but can you say why it is showing an Internal Server Error 500 to me when I try to install it?
Hello Amir,
you should be checking your PHP error logs. Look into your public_html folder, into the bbPress folder or into and the folder where the web server accesss logs are stored.
Thanks, Martin