I'm in agreement with the OP that Wordpress plugin authors have traditionally mixed business logic and view markup to a great degree, and I think continue to do so despite strides made with PHP frameworks. I'm relatively new to WP development, but as a programmer, I thought a simple fix for this would be in order. Thus, I hope it is acceptable to mention here that I've been working on TemplateSystem, a lightweight templating system that works well with WP plugins.
As Murphy's Law would have it, I released this code and then found that there are several libraries that will do WP plugin templating - my advice is to try several and see which you get on with. Mine is very lightweight, and some people will either use it or reject it on that basis!
Here's an example of an entry point to a plugin I am working on at the moment, that uses this templating system:
$root = dirname(__FILE__);
require_once $root . '/vendor/TemplateSystem/ControllerBase.php';
require_once $root . '/controllers/VersionedCommentsController.php';
$controller = new VersionedCommentsController( $root );
Here's some controller code:
// Import this class as a unique name
use TemplateSystem\Change2\ControllerBase as VersionedCommentsControllerBase;
class VersionedCommentsController extends VersionedCommentsControllerBase
* Main controller entry point (initialisation here)
public function execute()
add_action('add_meta_boxes_comment', array($this, 'editCommentDialogue'));
* This is a WP action handler
public function editCommentDialogue(stdClass $comment)
// Snipped detail, the important thing here is the rendering
array('commentVersions' => array_reverse($commentVersions), )
// Lots of other methods here, usually protected
A snippet of the template layer (shortened for brevity):
<!-- plugin/templates/version-history.php -->
Name: <?php echo $commentVersion['comment_author'] ?>
echo $commentVersion['comment_author_email'] ?
echo $commentVersion['comment_author_url'] ?
There's partials and component support too; see the README if you want to know more.