tutorial.
* Author: toemon
* Author URI: http://ja.xpressme.info
*/
class XPress_Menu_Widget extends WP_Widget
{
/**
* Declares the XPress_Menu_Widget class.
*
*/
function XPress_Menu_Widget(){
$widget_ops = array('classname' => 'widget_xpress', 'description' => __( "XPressME User Menu Widget") );
$control_ops = array('width' => 400, 'height' => 300);
$this->WP_Widget('XPress_Menu', __('XPressME MENU'), $widget_ops, $control_ops);
}
/**
* Displays the Widget
*
*/
function widget($args, $instance){
global $xpress_config,$xoops_config;
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']);
# Before the widget
echo $before_widget;
# The title
if ( $title )
echo $before_title . $title . $after_title;
# Make the XPressME MENU widget
echo '
';
for($i = 0; $i < 10; $i++) {
$link_name = $instance['name' . $i];
$link_url = $instance['link' . $i];
if (!empty($link_name)) echo '' . $link_name . ' ';
}
echo ' ';
# After the widget
echo $after_widget;
}
/**
* Saves the widgets settings.
*
*/
function update($new_instance, $old_instance){
$instance = $old_instance;
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
for($i = 0; $i < 10; $i++) {
$instance['name'. $i] = strip_tags(stripslashes($new_instance['name'. $i]));
$instance['link' . $i] = strip_tags(stripslashes($new_instance['link'. $i]));
}
return $instance;
}
/**
* Creates the edit form for the widget.
*
*/
function form($instance){
global $xpress_config,$xoops_config;
//Defaults
$instance = wp_parse_args( (array) $instance,
array(
'title'=> __('User Menu'),
'name0' => __('Site Home'),
'link0' => $xoops_config->xoops_url,
'name1' => '',
'link1' => '',
'name2' => '',
'link2' => '',
'name3' => '',
'link3' => '',
'name4' => '',
'link4' => '',
'name5' => '',
'link5' => '',
'name6' => '',
'link6' => '',
'name7' => '',
'link7' => '',
'name8' => '',
'link8' => '',
'name9' => '',
'link9' => ''
) );
$title = htmlspecialchars($instance['title']);
// Output the options
echo ''. "\n";
echo __('Title:') . '
'. "\n";
echo '' . __('Title') . ' ' . '' . __('URL') . ' ' . "\n";
for($i = 0; $i < 10; $i++) {
echo ' :'. "\n";
echo '
'. "\n";
}
}
}// END class
/**
* Register Hello World widget.
*
* Calls 'widgets_init' action after the Hello World widget has been registered.
*/
function XPress_MenuInit() {
register_widget('XPress_Menu_Widget');
}
add_action('widgets_init', 'XPress_MenuInit');
?>