1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Embedding WordPress in XenForo

Discussion in 'XenForo Development Discussions' started by Naatan, Apr 18, 2012.

  1. Naatan

    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:

    eg. my index.php file looks like this:

    $fileDir dirname(__FILE__);
    $fileDir '/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($fileDir '/library');
    XenForo_Application::initialize($fileDir '/library'$fileDir);
    $fc = new XenForo_FrontController(new XenForo_Dependencies_Public());
    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:

    class WpEmbed_Listen
        public static function 
    template_post_render($templateName, &$content, array &$containerDataXenForo_Template_Abstract $template)
    $themePath '/path/to/wordpress/wp-content/themes/saico/';
            if (
    $templateName != 'PAGE_CONTAINER' OR stripos($_SERVER['REQUEST_URI'],'admin.php'))
    $reporting error_reporting(E_ALL E_NOTICE);
    $themePath 'xenforo_container.php';
    $content ob_get_contents();
    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.
    Digital Doctor and Sadik B like this.
  2. Digital Doctor

    Digital Doctor Well-Known Member

    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 ?
  3. Naatan

    Naatan Well-Known Member

    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).
    Digital Doctor likes this.
  4. Fighter1405

    Fighter1405 Active Member

    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.
    adin, Naatan and Digital Doctor like this.
  5. Naatan

    Naatan Well-Known Member

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

    Fighter1405 Active Member

    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).
    adin likes this.
  7. Naatan

    Naatan Well-Known Member

    I'd say simply providing a widget area with logged in user details as well as providing template functions should be more than sufficient.
  8. xfrocks

    xfrocks Well-Known Member

  9. LPH

    LPH Well-Known Member

    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:

  10. Naatan

    Naatan Well-Known Member

    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.
  11. LPH

    LPH Well-Known Member

    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 :)
  12. Naatan

    Naatan Well-Known Member

    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.
  13. LPH

    LPH Well-Known Member

    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.
  14. Naatan

    Naatan Well-Known Member

    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!

Share This Page