Skip to content

Instantly share code, notes, and snippets.

@ahmad24
Forked from masiorama/gist:4967141
Last active December 29, 2015 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ahmad24/7638096 to your computer and use it in GitHub Desktop.
Save ahmad24/7638096 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Widget Example Plugin
Plugin URI: http://example.com/wordpress-plugins/my-plugin
Description: A plugin to create widgets in WordPress
Version: 1.0
Author: Brad Williams
Author URI: http://wrox.com
License: GPLv2
*/
// use widgets_init action hook to execute custom function
add_action( 'widgets_init', 'boj_widgetexample_register_widgets' );
//register our widget
function boj_widgetexample_register_widgets() {
register_widget( 'My_Widget' );
}
#PHP: Wordpress widget skeleton
class My_Widget extends WP_Widget {
public function __construct() {
// widget actual processes
}
public function form( $instance ) {
// outputs the options form on admin
}
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved
}
//display the widget
function widget($args, $instance) {
extract($args);
echo $before_widget;
$title = apply_filters( 'widget_title', $instance['title'] );
$movie = empty( $instance['movie'] ) ? ' & nbsp;' : $instance['movie'];
$song = empty( $instance['song'] ) ? ' & nbsp;' : $instance['song'];
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
echo ' <p> Fav Movie: ' . $movie . ' </p> ';
echo ' <p> Fav Song: ' . $song . ' </p> ';
echo $after_widget;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment