Zend Framework and WordPress Integration

We have an existing Zend Framework site hosted at ourdomain.com and a wordpress blog at blog.ourdomain.com

We want to migrate the blog into the site at ourdomain.com/blog – but I seemed to have googled to the end of the earth and cannot find out how. I have tried various .htaccess stuff, setting up a blog controller and including some wordpress files, etc – but to no avail.

Read More

Does anyone have any ideas?

Virtual host setup:

ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/Users/bradyeager/Sites/TWPZend/public"
ServerName twps
ErrorLog "logs/twps-error-log"
CustomLog "logs/twps-access_log" common

Options Indexes FollowSymLinks

AllowOverride All

Order allow,deny
Allow from all

Related posts

Leave a Reply

6 comments

  1. The most efficient and easiest way to accomplish this by modifying your .htaccess file to NOT send anything that starts with /blog to the ZF app — just pass it through to WordPress. WordPress would have to be installed inside your document root, of course, for this to work, exactly how you would normally install it.

    An example:

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    
    RewriteRule ^blog - [NC,L]
    
    RewriteRule ^.*$ index.php [NC,L]
    

    All this nonsense about creating custom controllers, actions and routes in your ZF app, then passing off to WordPress via your app is absolutely ridiculous. You’d be executing a full dispatch cycle of your application’s engine, just to forward off to another app?

  2. I often use this configuration actually , here’s what I do:

     /application
     /library
         /Zend 
         /wordpress ( symlink to my wordpress folder )
     /public
         index.php ( i add wordpress & the zend folder to my include path )
    

    Admittedly a bit of a brutal solution , considering all the unnecessary stuff that’s included in the process…

    Edit:

    // Define path to application directory
    defined('APPLICATION_PATH')
        || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
    
    // Define application environment
    defined('APPLICATION_ENV')
        || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
    
    // Ensure library/ is on include_path
    set_include_path(implode(PATH_SEPARATOR, array(
        realpath(APPLICATION_PATH . '/../library'),
        realpath(APPLICATION_PATH . '/../library/wordpress'),
        get_include_path(),
    )));
    
    //Get the wordpress environment
    define('WP_USE_THEMES', false);
    require_once 'wp-blog-header.php';
    
    /** Zend_Application */
    require_once 'Zend/Application.php';  
    
    
    
    // Create application, bootstrap, and run
    $application = new Zend_Application(
        APPLICATION_ENV, 
        APPLICATION_PATH . '/configs/application.ini'
    );
    $application->bootstrap()
                ->run();
    
  3. One of the best articles about migrating a non-ZF site into ZF is from Chris Abernethy.

    Like you, he sets up a special controller for those non-ZF handled script. However, he (eventually) sets up ZF-routes corresponding to those non-ZF pages, rather than playing around with external .htaccess.

    Might not apply directly to your case, since your example involves a subdomain while his involves pages on the same domain. But there are some good ideas in there that might be helpful.

  4. See the correct answer provided by Jason. Just make sure your wordpress .htacess file is rewriting to the correct index.php By default, it will rewrite back to the base index.php – which belongs to Zend. My solutions was to change WordPress’ .htaccess RewriteBase to /blog instead of /

  5. I wrote an open source library that might solve your problem called Vulnero that allows you to run your Zend Framework application inside WordPress. Your routes get handled by your app, everything else goes to WordPress. Can even render your views in your WordPress template if you like. Integrates authentication, database connections, all that. Source is on GitHub or you can read the documentation at http://www.vulnero.com/.

  6. For migrating WordPress into ZF you can use wploader.
    This works for me when i use wordpress as multiple site enabled.
    You can use all ZF controller objects inside your wordpress files.
    You don’t need any hack in your wordpress , so you can upgrade or update your wordpress version easily.