For a few weeks/months I’ve been struggling with the following matter at hand.

Old environment:
– Joomla website in “/
–  Smf installation in “/forum

Joomla was simply the front-end, providing news to our users while Smf was responsible for registrations, logins and maintenances of  members.

for years this worked perfectly but as time moved on a change for our site was necessary. Regarding the important use of Smf in this case  it was clear where our starting point would come from.

New environment: 

– WordPress installation in”/
– Smf installation in “/forum

I wanted to make sure that:

  1. users from Smf were able to login to WordPress
  2. users from Wp were able to login to Smf
  3. information from Smf could be used in Wp
  4. and the forum was integrated in WordPress

And so began an epic struggle:

Step 1. A bridge

bridgeSince Smf and WordPress are too different handling registration, logins, logouts and managing their “content”, we need something to overlap this, hence a bridge.

A search revealed that  a lot of these “bridges” are available for different types of blogs, forums and/or CMSs and most of them provide a basic functionality to sync the different databases so a login eg is possible in both.

Let’s see what’s out there.

My first approach was using a wp bridge for smf:  SMF Bridge

WP-SMF-Bridge is a simple user registration and logon bridge between WordPress and Simple Machine Forum. To get this working, it is highly recommended that you have a fresh, unmodified install of SMF 1.1 or higher installed and running alongside an install of WordPress. It must be installed in a subdirectory under your WP install and should not be being accessed through a sumdomain. For example, if your website’s address is mysite.mydomain.com, your forums should be somewhere like mysite.mydomain.com/myforum. Also, WordPress must be able to access your SMF configuration files, otherwise it won’t work!

Unfortunately, this plugin has not been updated since 2010-5-26 and didn’t make me use the SSI.php functions in wordpress.

Second approach: SMF2WP

SMF2WP is a simple one way bridge from Simple Machine Forum (v2.0.1 tested) to WordPress (v3.2.1 tested). This means, this one uses databases of SMF Forum and sync to WP database every time a user performs log-in action in both WP and SMF. […]

This plugin will do these following tasks:

  1. If a user log in WP, then that user will be logged in SMF using SMF2API.
  2. If a user logout WP, then that user will be logged out SMF using SMF2API.
  3. If a user log in SMF, will be logged in WP as well.
  4. If a user log out SMF, will be loged out WP as well.

When I was busy with this project, SMF 2.0RC came out and at that time SMF2WP didn’t work for me, so I was pushed in another way of achieving my goals.

Instead of using a WordPress plugin, why not go the other way around ? Use a Smf plugin which does the same. Since SMf was our basis from the beginning, this deemed to be a good solution.

Third approach: BlogBridger

BlogBridger is an Open Source PHP Application to bridge WordPress 3.0+ with SMF 2.0. It is released under the Mozilla Public License v1.1. BlogBridger makes no code changes to SMF, operating soley on it’s integration hooks. It is easy to install, uninstall and manage.
Features:

  1. Installable on new OR existing SMF and WordPress installations
  2. Migrates users to both SMF or WordPress if they do not exist in the other
  3. When a user logs into SMF, they are also logged into WordPress (vice versa)
  4. Assign WordPress roles to SMF member groups when exporting users from SMF
  5. Assign SMF Member groups to WordPress roles when importing users from WordPress

This could work ! After setup and installation I tried to login with wordpress and: Success! I was able to login using my smf credentials.

With this I was one step closer for reaching my goal.

2. How do you want your login sir ?

Login of SMF

I wanted to get rid of the login page that wordpress provides, so a few files needed some adjustments: ssi.php and header.php. (Ofcourse the wp-login.php can still be used, I simply did not let it show in my widget structure.)

This also allowed me to use the functions residing in smf.

ssi.php can be found in “/forum” and header.php can be found in
your “/wp-content/themes/<themename>” folder.

header.php

We need to change the  first lines. by adding ssi.php.
Change

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
  4.  
  5. <head profile="http://gmpg.org/xfn/11">
  6. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
  7.  
  8. [...]

to

  1. <?php
  2. require_once('/forum/SSI.php');
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  5. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
  7.  
  8. <head profile="http://gmpg.org/xfn/11">
  9. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

With this added line we can use variables from smf, let say: the loginbox

<div id=loginbox>
<?php  ssi_login(); ?>
</div>

But this gives us the entire loginform, we only need the username and password textfields. Thus requiring a little adjustment in ssi.php

Ssi.php

Change

  1. // Shows a login box.
  2. function ssi_login($redirect_to = '', $output_method = 'echo')
  3. {
  4. global $scripturl, $txt, $user_info, $context, $modSettings;
  5.  
  6. if ($redirect_to != '')
  7. $_SESSION['login_url'] = $redirect_to;
  8.  
  9. if ($output_method != 'echo' || !$user_info['is_guest'])
  10. return $user_info['is_guest'];
  11.  
  12. echo '
  13. <form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '">
  14. <table border="0" cellspacing="1" cellpadding="0" class="ssi_table">
  15. <tr>
  16. <td align="right"><label for="user">', $txt['username'], ':</label>&nbsp;</td>
  17. <td><input type="text" id="user" name="user" size="9" value="', $user_info['username'], '" class="input_text" /></td>
  18. </tr><tr>
  19. <td align="right"><label for="passwrd">', $txt['password'], ':</label>&nbsp;</td>
  20. <td><input type="password" name="passwrd" id="passwrd" size="9" class="input_password" /></td>
  21. </tr>';

to

  1. // Shows a login box.
  2. function ssi_login($redirect_to = '', $output_method = 'echo')
  3. {
  4. global $scripturl, $txt, $user_info, $context, $modSettings;
  5.  
  6. if ($redirect_to != '')
  7. $_SESSION['login_url'] = $redirect_to;
  8.  
  9. if ($output_method != 'echo' || !$user_info['is_guest'])
  10. return $user_info['is_guest'];
  11.  
  12. echo '
  13. <form id="loginform" action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '">
  14.  
  15. <label for="user">USERNAME</label>
  16. <input type="text" id="user" name="user" size="9" value="', $user_info['username'], '" class="input_text" />
  17.  
  18. <label for="passwrd">PASSWORD</label>
  19. <input type="password" name="passwrd" id="passwrd" size="9" class="input_password" />
  20. <!--
  21. <select name="cookielength">
  22. <option value="60">for 1 Hour</option>
  23. <option value="1440">for 1 Day</option>
  24. <option value="-1" selected="selected">until you log out</option>
  25. </select>
  26. -->
  27. ';

Et voila ! Now we only have our needed textfields.

So, what’s our status so far ? Users can login with their forum credentials and are automatically added to the wp_users table in the database.

From this point on you have 2 choices:

You continue to use this combination of blog and forum or start over with your freshly added users, who are now “imported” in wordpress.
I choosed the first.

© 2012 Ceekes boarderline Suffusion theme by Sayontan Sinha