Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active March 7, 2019 16:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tommcfarlin/caf46620cf110e5d55f4a302f1d5a471 to your computer and use it in GitHub Desktop.
[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