-
-
Save zarankumar/95e91624050bae5ebac0 to your computer and use it in GitHub Desktop.
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 | |
/* | |
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