Created
June 23, 2014 21:16
-
-
Save theJasonJones/fa778e9251ae02c4506b to your computer and use it in GitHub Desktop.
Simple WP Widget
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 | |
error_reporting(E_ALL); | |
/* | |
Plugin Name: Messager Widget | |
Plugin URI: http://www.hazardouswasteexperts.com/ | |
Description: A example of how to make a WordPress widget | |
Author: Jason Jones | |
Author URI: http://www.hazardouswasteexperts.com/ | |
Version 1.0 | |
*/ | |
class Messager extends WP_Widget | |
{ | |
public function __construct() | |
{ | |
//Set attributes of the widget | |
$params = array( | |
'description' => 'Display message to readers', | |
'name' => 'Messager' | |
); | |
parent::__construct('Messager', '', $params); | |
} | |
//Creates the textbox in the widget area | |
public function form($instance) | |
{ | |
extract($instance); | |
?> | |
<p> | |
<label for="<?php echo $this->get_field_id('title');?>">Title: </label> | |
<!-- Add the widefat class to make the text span the entire width of widget--> | |
<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> | |
<!-- Add the widefat class to make the text span the entire width of widget--> | |
<textarea | |
class="widefat" | |
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 | |
} | |
public function widget($args, $instance) | |
{ | |
extract($args); | |
extract($instance); | |
$title = apply_filters('widget_title', $title); | |
$description = apply_filters('widget_description', $description); | |
echo $before_widget; | |
echo $before_title. $title . $after_title; | |
echo "<p>". $description. "<p>"; | |
echo $after_widget; | |
} | |
} | |
//Add widget to the available widgets area | |
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