Skip to content

Instantly share code, notes, and snippets.

@mehrshaddarzi
Created September 23, 2017 16:15
Show Gist options
  • Save mehrshaddarzi/a1bb6bb769a74be350e873e12e3ffc71 to your computer and use it in GitHub Desktop.
Save mehrshaddarzi/a1bb6bb769a74be350e873e12e3ffc71 to your computer and use it in GitHub Desktop.
/**
* A widget that does amazing things!
*/
class Amazing_Widget extends WP_Widget {
/**
* Registers the widget with the WordPress Widget API.
*
* @return void.
*/
public static function register() {
register_widget( __CLASS__ );
}
/**
* Sets up the widget in the system.
*
* @return Amazing_Widget An instance of this widget.
*/
public function __construct() {
parent::__construct( 'amazing_widget', 'Amazing Widget' );
}
/**
* Outputs the widget admin form.
*
* @return void.
*/
public function form( $instance ) {
// Output the widget admin form here
}
/**
* Validates and sanitizes the widget form input.
*
* @return array The sanitized and updated values.
*/
public function update( $new_instance, $old_instance ) {
// Validate and sanitize updates here
}
/**
* Outputs the widget front end markup and data.
*
* @return void.
*/
public function widget( $args, $instance ) {
// Output the widget front end markup here
}
}
add_action( 'widgets_init', array( 'Amazing_Widget', 'register' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment