Last active
June 17, 2021 08:00
-
-
Save drblue/9d1a6763a9f773ad7b87ac1eb7ec8cd9 to your computer and use it in GitHub Desktop.
Revisions
-
drblue revised this gist
Jun 17, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public function form($instance) { // do we have a title set? if so, use it, otherwise set empty title $title = isset($instance['title']) ? $instance['title'] : __('A skeleton title', 'textdomain'); ?> <!-- title --> -
drblue created this gist
Jun 17, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,83 @@ <?php class MyWidgetSkeleton extends WP_Widget { /** * Construct a new widget instance. */ public function __construct() { parent::__construct( 'my-widget-skeleton', // Base ID 'Skeleton Widget 💀', // Name [ 'description' => 'A widget skeleton.', ] ); } /** * Front-end display of the widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved option values for this specific instance of the widget. * @return void */ public function widget($args, $instance) { // start widget echo $args['before_widget']; // end widget echo $args['after_widget']; } /** * Back-end widget form * * @see WP_Widget::form() * * @param array $instance Current saved values for this instance of the widget. * @return void */ public function form($instance) { // do we have a title set? if so, use it, otherwise set empty title $title = isset($instance['title']) ? $instance['title'] : get_option('ww_default_title', __('Current Weather', 'wcm20-weather')); ?> <!-- title --> <p> <label for="<?php echo $this->get_field_id('title') ?>">Title:</label> <input class="widefat" id="<?php echo $this->get_field_id('title') ?>" name="<?php echo $this->get_field_name('title') ?>" type="text" value="<?php echo $title; ?>" > </p> <?php } /** * Sanitize widget form data before they are saved to the database. * * @see WP_Widget::update() * * @param array $new_instance Form values just sent to be saved. * @param array $old_instance Currently saved values. * @return void */ public function update($new_instance, $old_instance) { $instance = []; $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : ''; return $instance; } }