Forums

Join
bbPress Support ForumsTroubleshootingWordPress + bbPress Integration 101

Info

WordPress + bbPress Integration 101

  1. Im integrating my second wp and bb site and this time around it seems there are some easier steps only I cant get this setup to work. I can login to the WP side fine. But when i login from bb side it just redirects to the forum homepage. It will login the person on the wp side but not let them do a thing on the bb side.

    I dont have admin access until wipe out the theme and clear the cookies. its very strange.

    I followed all steps correctly in the writeup. any help would be much appreciated.

    here is what my bb-config file looks like

    require_once('/path/to/blog/wp-blog-header.php');

    // ** MySQL settings ** //
    define('BBDB_NAME', 'db'); // The name of the database
    define('BBDB_USER', 'user'); // Your MySQL username
    define('BBDB_PASSWORD', 'pswd'); // ...and password
    define('BBDB_HOST', 'localhost'); // 99% chance you won't need to change these last few

    define('BBDB_CHARSET', 'utf8'); // If you are *upgrading*, and your old bb-config.php does
    define('BBDB_COLLATE', ''); // not have these two contstants in them, DO NOT define them
    // If you are installing for the first time, leave them here

    define('COOKIEPATH', '/' );
    define('SITECOOKIEPATH', '/');

    // Change BB_SECRET_KEY to a unique phrase. You won't have to remember it later,
    // so make it long and complicated. You can visit https://www.grc.com/passwords.htm
    // to get a phrase generated for you, or just make something up.
    // If you are integrating logins with WordPress, you will need to match the value
    // of the "SECRET_KEY" in the WordPress file wp-config.php
    define('BB_SECRET_KEY', 'secretkeydotcom'); // Change this to a unique phrase.

    // If you are running multiple bbPress installations in a single database,
    // you will probably want to change this.
    $bb_table_prefix = 'bb_'; // Only letters, numbers and underscores please!

    // Change this to localize bbPress. A corresponding MO file for the
    // chosen language must be installed to bb-includes/languages.
    // For example, install de.mo to bb-includes/languages and set BB_LANG to 'de'
    // to enable German language support.
    define('BB_LANG', '');

    /* Stop editing */

    if ( !defined('BB_PATH') )
    define('BB_PATH', dirname(__FILE__) . '/' );
    require_once( BB_PATH . 'bb-settings.php' );

    $bb->wp_siteurl = 'http://www.site.com/blog/';
    // that's your WordPress URL, not bbPress

    $bb->wp_home = 'http://www.site.com/blog/';
    // almost always the same as siteurl unless you tinker

    $bb->wp_table_prefix = 'wp_';
    // should almost always be wp_ unless you tinkered

    $bb->user_bbdb_name = 'db';
    // this is the MYSQL database name for *WordPress*
    // you can copy it right out of WordPress !

    $bb->user_bbdb_user = 'user';
    // this is the MYSQL user name for *WordPress*
    // you can copy it right out of WordPress !

    $bb->user_bbdb_password = 'pswd';
    // this is the MYSQL password for *WordPress*
    // you can copy it right out of WordPress !

    $bb->user_bbdb_host = 'localhost';
    // 99.9% of the time it's going to be localhost, unless you are on DreamHost or some other weird ISP

    $bb->custom_user_table = 'wp_users';
    // 99.9% of the time it's going to be wp_users

    $bb->custom_user_meta_table = 'wp_usermeta';
    // 99.9% of the time it's going to be wp_usermeta

    $bb->authcookie = 'wordpress_randomnumbers';
    // in theory you should be able to leave this out
    // but this is going to be copied from WordPress cookie
    // this *must* match the WordPress setting
    // do NOT use the 1234567 part, use your own cookiehash from WordPress - see the note at the very bottom

    $bb->cookiedomain = '.site.com';
    // note the leading DOT - this is important
    // this *must* match the WordPress setting

    $bb->cookiepath = '/';
    // I *highly* recommend you set the cookie path to /
    // this *must* match the WordPress setting

    $bb->sitecookiepath = '/';
    // I *highly* recommend you set the cookie path to /
    // this *must* match the WordPress setting

    //tried this - doesnt work with or without...ugh
    $bb->usercookie = 'wordpressuser_randomnumbers';
    $bb->passcookie = 'wordpresspass_randomnumbers';

  2. ok update as ive been messing with thing maybe too much.

    if i include the wp-blog-header.php to use WP functions i am never recognized as logged in on BB side even though using the bb form gets me logged in on wp side. everything redirects me to the forum homepage when trying to go to admin or profile. weird.

    with the include not there I can login and be shown logged in on bbpress side, but i cannot logout! omg it doesnt end. maybe its because i have had 5 hours of sleep the past two nights but any help on this would rock!

  3. Hi,
    any news about integrating the incoming WP 2.7?
    I just need (as most of you) to automatically post in BBpress the WP posts,and to made them commentable on there (BBpress).

    thanks.

  4. I'm not sure who has access to edit the information on this website (outwith the forums) but any change we could have :

    <b>"Do NOT try to integrate WordPress 2.6 with bbPress 0.9 - only use WP 2.5.x - the reason for this is simple - WordPress has radically changed the way cookies are used. "</b>

    oooh i dont know, maybe on the INTEGRATION TO WORDPRESS page?!?! or even on the download section.

    How daft is it to hide it away in a forum when it's quite essential information? If you download the latest stable wordpress and the latest stable BBpress - they're uncompatable. that to me seems kind of important to new people who download stable releases of both to get started!

  5. ATTENTION
    PHP 4 users with WP 2.5.0 + bbPress 0.9.x

    There is a HUGE BUG in the way the WP 2.5.0 (not 2.5.1) handles the login cookie. You won't have a problem with PHP 5, only PHP 4.

    So with PHP 4, you MUST use WP 2.5.1 and not WP 2.5.0 (aka 2.5) with bbPress 0.9 for cookie integration. Otherwise you'll never get it to work.

    There are only THREE files you need to replace in 2.5.0 to make it into 2.5.1:

    wp-includes/pluggable.php
    wp-admin/includes/media.php
    wp-admin/media.php

    Technical reason:
    function wp_hash() in WP 2.5.0 never calls hash_hmac if it doesn't exist and just returns a plain md5 instead. This method is incompatible with bbPress 0.9 - The compatibility function in compat.php is not loaded in time.

  6. Hello, is it possible to run bbPress in webroot and WordPress in a subdir and have them integrated? (This option is not mentioned in the initial FAQ here in this topic)

  7. Yes that configuration is certainly possible.
    The same logic applies, both cookies need to be using the webroot as the path.

  8. would this work with 2.7? and is there any install documentation of doing it this way?

  9. To include the wordpress theme I simply included the header and footer files into the bbpress themes (deleting the rest of content in there) and then added the login to the header in the wordpress theme using <? if (function_exists('bb_login')) ?>

    You can see this at http://superturbodiesel.com/. The only problem I found was that you can't login from the wp home page. In my case this is perfect as forum administrators are the only ones who can post in WP.

  10. hi winmutt
    did you also implementes the cross posting ?
    I mean post an article in the blog and automatically doubbing it on the forum?

    thanks

  11. No, I did not want that functionality at all. My post was simply an easy way to integrate an existing wp theme.

    RE PHP4 post earlier, php4 is all but deprecated, its EOL has already passed, tell your host to upgrade!!!!

  12. with wp 2.7 which version of bbpress i should use ?

  13. @marcomail

    bbPress 1.0 alpha 4

  14. HELP!
    mine was almost working... I upgraded to wpmu 2.7, and bbpress1.0 alpha 4.... the data base was sharing...everything was almost perfect....but then....

    I was in the Admin Panel for bbpress, and was changing User roles (admin of wp to be admin of bbpress, etc)....

    Then, I saw that the 'SECURE_AUTH_SALT' form was blank.... (in the admin panel of bbpress for wordpress integration)... I thought ..."mmm., thats strange, I already entered that when doing the setup.!".... so.....i entered the key again .....

    oops, really bad idea

    Now, i get an error message:

    Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /nfs/c02/h03/mnt/27695/domains/globotrends.com/html/forums/bb-includes/backpress/class.bpdb.php on line 123

    Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /nfs/c02/h03/mnt/27695/domains/globotrends.com/html/forums/bb-includes/backpress/class.bpdb.php on line 377

    HELP!!!!!!

    how do i undo what i did?

    where do I look? in what file?

    my sites are here:
    1. bbpress: http://globotrends.com/forums
    2. wpmu: http://globotrends.com/community

  15. i mean...bbpress. alpha6 (not 4)

  16. I followed some of these instructions and completely integrated WP 2.6.2 and bbPress 0.9 logins on my site today (BayAnime.com). I'd already had 2.6 up and running when I installed bbPress and didn't want to roll back (I really need to roll forward at some point), so I just copied and pasted all the old WP 2.5 cookie functions from pluggable.php into a separate plugin file for my 2.6 install, set all the paths and keys, and it's working well. I expect you can just do the same with WP 2.7 if you want to integrate it with bbPress 0.9. Anyway just wanted to report that it IS possible to get 2.6 (and up probably) working with bbPress 0.9 without too much more pain. If anyone's interested in the plugin file that has the WP 2.5 functions you need, just let me know!

  17. First post updated to reflect the two new plugins available to allow WP 2.6, 2.7 or 2.8 to work with bbPress 0.9

  18. If you're seeing WP logins work, and BB logins fail, then BB is probably logging you in and setting the wrong cookie path.

    (You can debug this sort of thing by using a proxy which lets you inspect the headers as they pass from client to server - I recommend the excellent Charles Web Debugging Proxy.)

    I fixed this using the WP Cookie Root plugin. Changing the COOKIE_PATH defines for me hadn't worked, but the plugin did.

    http://wordpress.org/extend/plugins/root-cookie/

    Q: With deep integration, I see any postings to BB get double-quoted, eg an apostrophe posted to the forum will appear as \' ...

    Here's hoping BBPress doesn't munge the line above. Apostrophes appear in the forum with a backslash to escape them, because both WP and BB are running the apostrophes thru their escaping function. How can I avoid this?

  19. So far I am failing on this. I am going to try the plug-in that xurizaemom has suggested.....my integration is failing and I have tried the suggested method running WP 2.7 and the latest bbpress 0.9.0.4 .

    There is definitely some conflict between the cookies as if I login as admin on wp, then go to bb, clicking on the admin link fails and I am redirected to the front page instead of admin area. Logged out of WP, and logging into BBPress as admin, the link works properly and the admin panel opens...

    The wordpress is in the the root directory and bbpress in its own directory in the root.

  20. andyimages, to use WP 2.7 with bbPress 0.9 you need one of the two plugin solutions now updated in the first post. Changing the cookie path is not enough, you have to change the cookie method entirely.

  21. CK I installed the plugin with the salt keys, etc......and there is evidentally a little progess as the cookies do not conflict as before, but the integration hasn't worked either. Not sure what the issue is but in the docs there are not a precise definition of the secret key. Is the database secret key that you refer to the key I have defined in the config, php that holds the database name, password, etc.....or is that the "secret," randomly derived string that is listed through options.php as "secret"? Also, since I am using .9, where exactly are the bbpress integration settings in wp......there was a new-plugin, but that was for 1. alpha, right.....not for .9?

    Excuse me because I am new to this, but does it make sense for me to upgrade to the alpha version, is that easier to integrate? Or do I want to go the other direction and downgrade the wp cookies.

    Thanks in advance>>

    Andy

  22. Do not even "try" the alpha as you can then never go back to 0.9
    Many plugins will not work with the alpha and won't for some time.

    You want to downgrade the wp cookies. Use Ann's plugin.

  23. Got the problem.....when copying the secret from the options.php in wordpress to enter into the WP INtegration in BBpress, on submit bbpress (or something) was stripping the final character off the secret string. I checked this twice to make sure it was happening, and then edited the record by just pasting in the ")." Voilla. Ann's cookie worked!

  24. Btw, when you do cookie integration please keep in mind that there are some login hooks in pluggable that might not be called in either WP or bbPress depending on which side your user logged in from. This might affect the functionality of some plugins.

    For example, after rerouting all my bbPress logins to WP I realized that the 'bb_set_current_user' action hook on a bbPress plugin I used was no longer being called, so I had to incorporate it in on the WP side using the 'set_current_user' hook.

  25. Thanks Ann, so far so good.....no problems on that end.

  26. How I do deep integration using WordPress 2.7 and bbPress 1.0 Alpha 6.

    Add to beginning of bb-config.php:

    if ( !defined('ABSPATH') & !defined('XMLRPC_REQUEST')) {
    	define('WP_USE_THEMES', false);
    	include_once( '/absolute/path/to/yourdomain.com/wp-blog-header.php' );
    	header("HTTP/1.1 200 OK");
    	header("Status: 200 All rosy");
    }
  27. I tried integrating bbPress (alpha 6) with 2.7 WP MU and ran into problems. The web-based installation failed if I selected integration (I left the "Add cookie integration settings" unchecked, only tried user database integration) - it threw up an error during the last step, and said Installation Halted! (although all previous tests and validations seemed to go through fine).

    I dropped the bb_ tables, then installed bbPress without the integration options and it worked. Is it possible to modify a working bbpress installation to integrate with WP MU after installation? Has anyone done this before - and might have instructions online somewhere?

    All on dreamhost.com server.

  28. @_ck_:

    A note on deep integration: As of 0.9.0.4, deep integration will break the localization due to the localization methods being used from WP's core files (bb_settings.php line 75), causing the system to look for bbPress-language files in the WP language directory. Here's what to fix to make bbPress load it's own language files from bb_includes/languages when using deep integration:

    In line 376-377 of bb-settings.php, replace

    // Load the default text localization domain.
        load_default_textdomain();

    with

    // Load the default text localization domain.
    if ( !(defined('DB_NAME')) ) {  // Include localization the bbPress-way when WP is not running.
        load_default_textdomain();
    }
    else {
        $locale = get_locale();
    	$mofile = BB_LANG_DIR . "$locale.mo";
    
    	load_textdomain('default', $mofile);
    };
  29. Hey all. After much help from reading these forums and tinkering endlessly, I have gotten cross site logins working between WP2.6 and bbpress 0.9 . I don't know if you'd call it 'integration', but it allows a user to log in once and gain access to all appropriate site resources. Although probably not the best solution, what I did is create my own cookie login, which is caught before wordpress or bbpress load, and creates a new user object which is universal to WP and BBPress (and any other webapps you use). It does take a little...alteration...of core WP and BBPress files. I strongly encourage you to make backups before doing this, and proceed at your own risk. It worked for me, but I cannot guarantee that it will fork for you. Also, it took a bit of hacking before I came up with this solution, so it may contain minor errors or accidental omissions as I am having to backtrack to recall what exactly I did.

    okay, here goes...

    First, we have to configure bbpress to use the wp_users table. That is done in the admin area of bbpress (settings->wordpress integration). Check 'Show Advanced Database Settings' and enter your database information for the wordpress install. Also, enter the wordpress database secret code near the top of the settings page.

    Next, I created a file in the document root called 'cookie_login.php':

    <?php
    if($_SERVER['REQUEST_URI'] == '/cookie_login.php'){die('Cannot access directly');}
    
    //Initial Setup of Variables
    $SECRET_KEY = 'SECRET_KEY_DEFINED_IN_BBPRESS_AND_WP';//use a real secret key
    $site_user = false;
    
    //Do the DB thing
    $the_db= mysql_connect('SERVER','USER','PASS');
    mysql_select_db('DATABASE',$the_db);
    
    //Start Session!
    session_set_cookie_params(1800,'/','.SITE.com'); //30 minute session
    session_start();
    if (isset($_COOKIE['site_cookie'])){ //cookie has been set, proceed to get user info!
    	$tmp = explode(':',$_COOKIE['site_cookie']); //this will make sense later
    	$tmpusr = $tmp[0];
    	$wpid = $tmp[1];
    	$tmphash = $tmp[2];
    	$hashShouldBe = md5($tmpusr . $SECRET_KEY . $wpid); //what the hash should be - prevent tampering!
    	if ($tmphash == $hashShouldBe){
    		if (isset($_SESSION['user'])){
    			$site_user = $_SESSION['user'];
    		}else{
    			$qry = "SELECT * from wp_users WHERE ID = ".mysql_real_escape_string($wpid,$the_db) . " LIMIT 1";
    			$result = mysql_query($qry,$the_db);
    			$site_user = mysql_fetch_assoc($result);
    			$qry = "SELECT meta_key, meta_value from wp_usermeta where user_id = ".mysql_real_escape_string($wpid,$the_db);//get additional data, just for fun
    			$resulta = mysql_query($qry,$the_db);
    			$temp_arr = array();
    			while ($row = mysql_fetch_assoc($resulta)){
    				$tmp_value = unserialize($row['meta_value']) ? unserialize($row['meta_value']) : $row['meta_value'];//if it a serialized array, unserialize it.  otherwise, dont.
    				$temp_arr[$row['meta_key']] = $tmp_value;
    			}
    			$site_user = $temp_arr + $site_user;
    			$_SESSION['user'] = (object)$site_user;//Object just out of preference, but doesn't have to be
    		}
    
    	}else{//tsk tsk, bad hash
    		$_SESSION['user'] = array();
    		setcookie('site_cookie',$_COOKIE['site_cookie'],time()-9600,'/','.SITE.com');
    		setcookie('PHPSESSID',$_COOKIE['PHPSESSID'],time()-9600,'/','.SITE.com');
    		setcookie(session_name(), session_id(), time()-9600, '/');//may be unnecessary...not sure...but can't hurt! (famous last words)
    		session_destroy();
    	}
    }
    if (!isset($_COOKIE['site_cookie']) && isset($_SESSION['user'])){//attempt to gain access?
    		$_SESSION['user'] = array();
                    setcookie('site_cookie',$_COOKIE['site_cookie'],time()-9600,'/','.SITE.com');
    		setcookie('PHPSESSID',$_COOKIE['PHPSESSID'],time()-9600,'/','.SITE.com');
    		setcookie(session_name(), session_id(), time()-9600, '/');//may be unnecessary...not sure...but can't hurt! (famous last words)
    		session_destroy();
    }
    session_write_close();
    unset($SECRET_KEY,$hashShouldBe,$tmp,$wpid,$tmphash,$tmpusr,$result,$_SESSION['user'],$resulta,$temp_arr);//burn the evidence!
    include ('site_functions.php'); //optional, can hook another file with functions (universal to all sites) to deal with this new user object
    ?>

    After I finished the cookie_login.php, I rolled up my sleeves and dove into the WordPress and BBPress core to allow my login to occur.

    in the /wp-config.php file, define the cookie domain:
    define('COOKIE_DOMAIN', '.SITE.com');

    Also, that secret key you used earlier in cookie_login...define it here as well
    define('SECRET_KEY', 'Same Key from Earlier. IMPORTANT to make sure it's identical');

    Next, I hooked in my cookie_login file to wordpress and bbpress by adding an include to the top of BOTH bb-config.php AND wp-config.php
    include $_SERVER['DOCUMENT_ROOT'] . '/cookie_login.php';

    To set up the 'site_cookie' properly, open up /wp-includes/user.php and find wp_signon function (was the first one for me). At the bottom of the function, after

    if ( is_wp_error($user) )
    		return $user;

    Add the following:

    $hashValue = $credentials['user_login'] . SECRET_KEY . $user->data->ID;
    	$crossCookieValue = $credentials['user_login'] . ':' . $user->data->ID . ':' . md5($hashValue);
    
    	setcookie('site_cookie',$crossCookieValue,0,'/','.SITE.com');
    	wp_set_auth_cookie($user->ID, $credentials['remember'], $secure_cookie);
    	do_action('wp_login', $credentials['user_login']);//this may have already been there, don't remember

    Remember how I mentioned the site_functions.php which can be included at the bottom of cookie_login.php? That is a perfect place to put the next function, for bbpress login, but it can just as well go inside cookie_login.php itself. The function overwrites the bbpress native wp_validate_auth_cookie function, found in /bb-includes/pluggable.php, with one of our own, which is as follows:

    function wp_validate_auth_cookie($cookie = '') {
          global $site_user;
          if (!isset($site_user->ID)){
            return false;
          }else{
            return $site_user->ID;
          }
        }

    This is used internally by bbpress to allow the login to proceed.

    Next, open /wp-login.php and find the case: logout section, and add the following right after it:

    setcookie('site_cookie',$_COOKIE['site_cookie'],time()-9600,'/','.SITE.com');
    setcookie('PHPSESSID',$_COOKIE['PHPSESSID'],time()-9600,'/','.SITE.com');'
    
    Finally, and this may be only applicable for subdomain usage, open /wp-includes/pluggable.php and find the function wp_safe_redirect. Add subdomains you want redirects to in the $allowed_hosts array, for example:
    $allowed_hosts[]="bbpress.SITE.com";
    $allowed_hosts[]="test_wordpres.SITE.com";`
    etc...

    That's all (I think) that I had to do. This is probably not ideal, as there are now two copies of a user when hey login, one defined in our new system and one in the wordpress/bbpress systems; however I found this necessary to have happen since I didn't want to go through all the core code and edit out mention of $user.

    Let me know if this works for you, I hope it was coherant enough. I may have accidentally omitted sections since, as I said before, this is the result of a few weeks of on-and-off tweaks and changes. I can always dig into code and find things I missed if I know what problems are occurring. Also, if anyone is interested, I altered a private messenging system I found which was a little outdated (http://www.pixel2life.com/publish/tutorials/608/simple_private_messaging_system/) to work with this model as well. Users can PM one another from within the wordpress dashboard, and message indicators are noted in the header throughout their visit (in wordpress, bbpress, and other subsites).