-
-
Save tommcfarlin/499008d8b1c322d58ad7dbc599f81665 to your computer and use it in GitHub Desktop.
[WordPress] WordPress Widgets: Refactoring, Part 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="text" name="widget-title" value="" /> | |
<textarea name="widget-content"></textarea> | |
<label> | |
<input | |
type="checkbox" | |
value="1" | |
name="widget-title-enabled" | |
/> | |
Display Title? | |
</label> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This file is part of WordPress Widget Boilerplate | |
* (c) Tom McFarlin <tom@tommcfarlin.com> | |
* | |
* This source file is subject to the GPL license that is bundled | |
* with this source code in the file LICENSE. | |
*/ | |
namespace WordPressWidgetBoilerplate\WordPress; | |
/** | |
* Manages the administrative functionality of the widget. | |
*/ | |
class WidgetAdmin extends Widget | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct($widgetSlug) | |
{ | |
parent::__construct($widgetSlug); | |
} | |
/** | |
* Displays the administrative view of the form and includes the options | |
* for the instance of the widget as arguments passed into the function. | |
* | |
* @param array $instance the options for the instance of this widget. | |
*/ | |
public function form($instance) | |
{ | |
include plugin_dir_path(__FILE__).'Views/Admin.php'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Registers the core Widget class using the WordPress APIs. | |
*/ | |
public function load() | |
{ | |
register_widget(new Widget('widget-name')); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Registers the core Widget class using the WordPress APIs. | |
*/ | |
public function load() | |
{ | |
register_widget(new WidgetAdmin('widget-name')); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="widget-content"> | |
<p> | |
<input | |
type="text" | |
name="widget-title" | |
value="" | |
placeholder="Widget Title" | |
class="widefat" | |
/> | |
</p> | |
<p> | |
<textarea | |
name="widget-content" | |
placeholder="Widget Content" | |
style="width:100%;"></textarea> | |
</p> | |
<p> | |
<input | |
type="checkbox" | |
value="1" | |
name="widget-title-enabled" | |
class="checkbox" | |
/> | |
<label for="widget-title-enabled">Display Title?</label> | |
</p> | |
</div><!-- .widget-content --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment