Embedding WordPress in XenForo

Naatan

Well-known member
WARNING: This is for dev's only! Don't use anything posted in this thread unless you know what you're doing!

FYI it's totally possible to use XenForo and Wordpress side-by-side, as in you can run both codebases in the same process, which essentially allows you to show anything you have in Wordpress as part of XenForo and vise-versa.

It's as simple as adding this before your "Autoloader.php" line in XenForo's "index.php" file:

PHP:
require('/path/to/wordpress/wp-load.php');

eg. my index.php file looks like this:

PHP:
<?php
 
$startTime = microtime(true);
$fileDir = dirname(__FILE__);
 
require('/Users/nathanrijksen/Sites/naatan.com/wp-load.php');
require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
 
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);
 
$fc = new XenForo_FrontController(new XenForo_Dependencies_Public());
$fc->run();

You now have full access to all wordpress functionality from within XenForo.

I already experimented a bit by trying to embed XenForo within my Wordpress theme, which works great in theory, but in practice you have a humongous list of css conflicts to resolve. The only way I could see this working properly is if you "design" your wordpress theme in XenForo.

I won't be going doing any more work on this, but I thought I'd share my findings so that other can take it to the next level if they so desire.

This was my experimental code for wrapping XenForo in my Wordpress theme:

PHP:
<?php
 
class WpEmbed_Listen
{
 
    public static function template_post_render($templateName, &$content, array &$containerData, XenForo_Template_Abstract $template)
    {
        $themePath = '/path/to/wordpress/wp-content/themes/saico/';
 
        if ($templateName != 'PAGE_CONTAINER' OR stripos($_SERVER['REQUEST_URI'],'admin.php'))
        {
            return;
        }
 
        ob_end_clean();
 
        $reporting = error_reporting(E_ALL ^ E_NOTICE);
 
        ob_start();
        require_once $themePath . 'xenforo_container.php';
        $content = ob_get_contents();
        ob_end_clean();
 
        error_reporting($reporting);
 
        ob_start();
    }
 
}

xenforo_container.php is basically a Wordpress template that includes the header, footer, sidebar and echo's $content.

All this is of course highly experimental and will likely break lots of stuff, so don't use any of this unless you know what you're doing or like to experiment.
 
Naatan, are you able to get Xenforo Alerts and Inbox to appear on a Wordpress Home Page ?
I know people were very interested in that.

What I mean is someone is using Xenscripts Bridge, and they are logged into Wordpress ... Could their Xenforo alerts show on the Wordpress landing page ?
 
Naatan, are you able to get Xenforo Alerts and Inbox to appear on a Wordpress Home Page ?
I know people were very interested in that.

What I mean is someone is using Xenscripts Bridge, and they are logged into Wordpress ... Could their Xenforo alerts show on the Wordpress landing page ?

What I've done here embeds Wordpress in XenForo, what you're asking for requires the reverse of that (XF in WP), but seeing as the former is possible, I don't see any reason why that wouldn't work.

It'd be a pretty bloated solution for such a simple problem though. It'd be much easier just to create an API endpoint which returns the alerts and notifications. You could probably use my Ajax Polling addon for this purpose (tweak the JS a little and you're pretty much set to show your alerts / notifications anywhere on the same domain as your XF install, provided that you're logged in on XF).
 
What I've done here embeds Wordpress in XenForo, what you're asking for requires the reverse of that (XF in WP), but seeing as the former is possible, I don't see any reason why that wouldn't work.

It'd be a pretty bloated solution for such a simple problem though. It'd be much easier just to create an API endpoint which returns the alerts and notifications. You could probably use my Ajax Polling addon for this purpose (tweak the JS a little and you're pretty much set to show your alerts / notifications anywhere on the same domain as your XF install, provided that you're logged in on XF).

XF in WP is essentially how my bridge works at the moment, we boostrap in XF functionality when we load the WP instance. You're absolutely right that loading things like notices would be possible in the future.
 
XF in WP is essentially how much bridge works at the moment, we boostrap in XF functionality when we load the WP instance. You're absolutely right that loading things like notices would be possible in the future.

It's already "possible", I take it you mean to say that you will be supporting it in the future with your addon? :)
 
It's already "possible", I take it you mean to say that you will be supporting it in the future with your addon? :)

You're right of course, it is already possible. It's something that I'd like to add support for in the future with my addon, as time allows =) I have a few other things in my todo list first, but theoretically I don't think loading alerts/notices would be a huge challenge - the bigger challenge is where to put them (given I aim to support every available WP theme with my plugin, not just ones that have a specific area set aside for XF stuff).
 
You're right of course, it is already possible. It's something that I'd like to add support for in the future with my addon, as time allows =) I have a few other things in my todo list first, but theoretically I don't think loading alerts/notices would be a huge challenge - the bigger challenge is where to put them (given I aim to support every available WP theme with my plugin, not just ones that have a specific area set aside for XF stuff).

I'd say simply providing a widget area with logged in user details as well as providing template functions should be more than sufficient.
 
Whenever I add the line for wp-load.php then I receive a Zend error:


An exception occurred: Registry is already initialized in /path/to/library/Zend/Registry.php on line 101
  1. Zend_Registry::setClassName() in XenForo/Application.php at line 244
  2. XenForo_Application::initialize() in /path/to/community/index.php at line 11

Search results bring up someone else trying something with headers and footers and getting the same error.

Now, If the theme is changed (not XenDynamic 0.2.0) then a different error shows:

An unexpected error occurred. Please try again later.
 
Whenever I add the line for wp-load.php then I receive a Zend error:




Search results bring up someone else trying something with headers and footers and getting the same error.

Now, If the theme is changed (not XenDynamic 0.2.0) then a different error shows:

Like I said it's highly experimental, conflicts can occur. If you don't know how to handle them you shouldn't be using anything posted in this thread ;)

I'm just sharing my findings with other dev's so that they may be able to implement it in their addons.
 
I was just tinkering out of curiosity. It would be nice to get WP and XF to work together out of the box rather than having to tinker. But this is a great way to learn and I'm glad you posted. After all, I now have a test environment set up and am eager to learn more :)
 
I was just tinkering out of curiosity. It would be nice to get WP and XF to work together out of the box rather than having to tinker. But this is a great way to learn and I'm glad you posted. After all, I now have a test environment set up and am eager to learn more :)


You will rarely see two products working together "out of the box", as it's never really a desirable scenario to have 2 codebases share the same process and thereby share namespaces, classes, etc. It's a means to an end but ideally you would do this through API communications or sharing of specific libraries.
 
You will rarely see two products working together "out of the box", as it's never really a desirable scenario to have 2 codebases share the same process and thereby share namespaces, classes, etc. It's a means to an end but ideally you would do this through API communications or sharing of specific libraries.

I appreciate what you are saying - from a developer's perspective. I wasn't meaning shared namespaces, etc. I was meaning - easy access integration to with each other - from an end user perspective.

Now - I'm not meaning to distract. So, I bid you a good day and repeat that I appreciate you sharing your experience.
 
I appreciate what you are saying - from a developer's perspective. I wasn't meaning shared namespaces, etc. I was meaning - easy access integration to with each other - from an end user perspective.

Now - I'm not meaning to distract. So, I bid you a good day and repeat that I appreciate you sharing your experience.


No worries, I don't mind sharing my experiences, just wanted to make clear that you shouldn't be using this on a production environment unless you know what you're doing :) Good luck!
 
Top Bottom