Last active
December 11, 2015 08:59
-
-
Save esgy/4577348 to your computer and use it in GitHub Desktop.
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 characters
<?php | |
/** | |
* Plugin Name: Messager Widget | |
* Plugin URI: http://point47.com | |
* Description: Displays any message designated | |
* Version: 1.0 | |
* Author: Sorin Gitlan | |
* Author URI: http://point47.com | |
*/ | |
class Messager extends WP_Widget { | |
public function __construct(){ | |
$params = array( | |
'description' => 'Displays message to readers', | |
'name' => 'Messager' | |
); | |
parent::__construct('Messager', '', $params); | |
} | |
/** | |
* Responsible for the form in the Widget management area | |
* @param Array $instance The form array Post data | |
* @return String | |
*/ | |
public function form($instance){ | |
extract($instance); | |
?> | |
<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'); ?>" | |
value="<?php if(isset($title)) echo esc_attr($title); ?>" | |
> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id('description'); ?>">Description: </label> | |
<textarea class="widefat" rows="8" | |
id="<?php echo $this->get_field_id('description'); ?>" | |
name="<?php echo $this->get_field_name('description'); ?>"><?php if(isset($description)) echo esc_attr($description); ?></textarea> | |
</p> | |
<?php | |
} | |
/** | |
* Responsible to display the results of our form | |
* @param Array $args the values that can be used to tailor how the widget displays | |
* @param Array $instance the values that are available from the widget area | |
* @return String | |
*/ | |
public function widget($args, $instance){ | |
extract($args); | |
extract($instance); | |
$title = apply_filters( 'widget_title', $title ); | |
$description = apply_filters( 'widget_description', $description ); | |
if(empty($title)) $title = 'My status'; | |
echo $before_widget; | |
echo $before_title . $title . $after_title; | |
echo '<p>'.$description.'</p>'; | |
echo $after_widget; | |
} | |
} | |
add_action('widgets_init', function(){ | |
register_widget( 'Messager' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment