Integrating Zend_View with WordPress

I just read a blog post about integrating Zend Framework and WordPress and figured I’d add some commentary of my own, since I’ve done something similar.  In my ESchrade plugin I use Zend_View to render some of my admin pages, though there is no reason why you couldn’t use it elsewhere, as long as the plugin has already been loaded.

Getting Zend Framework set up with WordPress is super simple.  Assuming you have Zend Framework already in your include path all you need to do is put the autoloader in your plugin file.

Here is a very slimmed down version of my plugin class that integrates with WordPress.  From the Zend_View perspective, all it really does create a new view object and set it up.


namespace com\eschrade;

class Application
* @var \Zend_View
private $view;
public function __construct()
$this->view = new \Zend_View();
realpath(__DIR__ . '/../../../templates')
$widget = new Popular($this->view);
wp_register_sidebar_widget('popular-posts', 'Popular Posts', array($widget, 'handle'));       

public function setView(\Zend_View_Interface $view)
$this->view = $view;

public function getView()
return $this->view;

public function handleJobs()
$this->view->jobs = new Jobs();
$this->view->jobs->setAction('/wp-admin/plugins.php?page=eschrade-config&action=Run Job');
// cut
echo $this->view->render('admin/runjobs.phtml');

Obviously you don’t have the view renderer set up, or some of the controller helpers that are so useful, but if you want access to anything that Zend_View has to offer it is thuper eathy to do.

5 Thoughts to “Integrating Zend_View with WordPress”

  1. Pingback:
  2. BTW, you can simplify your code a little using import statements. I’d suggest the following:

    use Zend_View as ViewEngine,
    Zend_View_Interface as View;

    This will make the code slightly easier to read, document your dependencies, and allow for later substitutions (e.g., when you start using ZF2 in a few months). 🙂

Leave a Reply

Your email address will not be published.