Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin

tommcfarlin/00-widget-display.php Secret

Last active Mar 7, 2019
Embed
What would you like to do?
[WordPress] WordPress Widgets: Refactoring, Part 12
<?php
namespace WordPressWidgetBoilerplate\WordPress;
class WidgetDisplay
{
private $widgetSlug;
public function __construct(string $widgetSlug)
{
$this->widgetSlug = $widgetSlug;
}
public function show($args, $instance)
{
// More to come
}
}
<?php
public function widget($args, $instance)
{
return $this->widgetDisplay->show($args, $instance);
}
<?php
public function __construct($widgetSlug)
{
parent::__construct($widgetSlug);
$this->widgetSerializer = new WidgetSerializer($this->getWidgetSlug());
$this->widgetDisplay = new WidgetDisplay($this->getWidgetSlug());
}
<div id="<?php echo $args['id']; ?>">
<h3 class="widget-title"><?php echo $instance['title']; ?></h3>
<p><?php echo $instance['content']; ?></p>
<pre><?php echo $instance['display-title']; ?></pre>
</div><!-- #<?php echo $args['id']; ?>-->
<?php
public function show($args, $instance)
{
include_once 'Views/Widget.php';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.