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' => 600, '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; global $current_user; 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 $menu = array(); for($i = 0; $i < 10; $i++) { $menu[$i]['Type'] = $instance['Type_' . $i]; $menu[$i]['Title'] = $instance['Title_' . $i]; $menu[$i]['URL'] = $instance['URL_' . $i]; $menu[$i]['Visible'] = $instance['Visible_' . $i]; $menu[$i]['Weight'] = $instance['Weight_' . $i]; } 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['Type_'. $i] = strip_tags(stripslashes($new_instance['Type_'. $i])); $instance['Title_' . $i] = strip_tags(stripslashes($new_instance['Title_'. $i])); if ($instance['Type_'. $i] < 2){ $instance['URL_' . $i] = strip_tags(stripslashes($new_instance['URL_'. $i])); } else { $instance['URL_' . $i] = ''; } $instance['Visible_' . $i] = strip_tags(stripslashes($new_instance['Visible_'. $i])); } return $instance; } /** * Creates the edit form for the widget. * */ function form($instance){ global $xpress_config,$xoops_config; if (xpress_is_wp_version('<','2.1') ){ $addnew = get_settings('siteurl').'/wp-admin/post.php'; } else { $addnew = get_settings('siteurl').'/wp-admin/post-new.php'; } $type = array(); $type[0] = __('Link', 'xpressme'); $type[1] = __('Site Home', 'xpressme'); $type[2] = __('Add New', 'xpressme'); $type[3] = __('User Profile', 'xpressme'); $type[4] = __('WordPress Admin', 'xpressme'); $type[5] = __('Module Admin', 'xpressme'); $type[6] = __('XPressME Setting', 'xpressme'); $type[7] = __('Display Mode Select', 'xpressme'); $auto_setting = __('Auto Setting', 'xpressme'); //Defaults $instance = wp_parse_args( (array) $instance, array( 'title'=> __('User Menu', 'xpressme'), 'Type_0' =>1 , 'Title_0' => __('Site Home', 'xpressme'), 'URL_0' => get_xoops_url(), 'Visible_0' => 1, 'Type_1' =>2 , 'Title_1' => __('Add New', 'xpressme'), 'URL_1' => $auto_setting, 'Visible_1' => 1, 'Type_2' =>3 , 'Title_2' => __('User Profile', 'xpressme'), 'URL_2' => __('Auto Setting', 'xpressme'), 'Visible_2' => 1, 'Weight_2' => 3, 'Type_3' =>4 , 'Title_3' => __('WordPress Admin', 'xpressme'), 'URL_3' => $auto_setting, 'Visible_3' => 1, 'Type_4' =>5 , 'Title_4' => __('Module Admin', 'xpressme'), 'URL_4' => $auto_setting, 'Visible_4' => 1, 'Type_5' =>6 , 'Title_5' => __('XPressME Setting', 'xpressme'), 'URL_5' => $auto_setting, 'Visible_5' => 1, 'Type_6' =>7 , 'Title_6' => $auto_setting, 'URL_6' => $auto_setting, 'Visible_6' => 1, 'Type_7' =>0 , 'Title_7' => __('Link', 'xpressme'), 'URL_7' => '', 'Visible_7' => 0, 'Type_8' =>0 , 'Title_8' => __('Link', 'xpressme'), 'URL_8' => '', 'Visible_8' => 0, 'Type_9' =>0 , 'Title_9' => __('Link', 'xpressme'), 'URL_9' => '', 'Visible_9' => 0, ) ); echo ' '; // Output the options echo '

'. "\n"; echo " "; for($i = 0; $i < 10; $i++) { $even = $i % 2; if ($even) { $back_color = ' style="background-color:#E3E3E3"'; } else { $back_color = ' style="background-color:#F5F5F5"'; } $text_back_color = ' style="background-color:#FFFFEE"'; echo ""; $select_arg = "'" . $this->get_field_id('Type_' . $i) . "','" . $this->get_field_id('Title_' . $i) . "','" . $this->get_field_id('URL_' . $i) . "'"; echo ''; if ($instance['Type_'. $i] == 7) { $title_disible = 'disabled=disabled'; $title_back_color = $back_color; $title_value = $auto_setting; } else { $title_disible = ''; $title_back_color = $text_back_color; $title_value = $instance['Title_'. $i]; } echo ''. "\n"; if ($instance['Type_'. $i] > 1) { $url_disible = 'disabled=disabled'; $url_back_color = $back_color; $url_value = $auto_setting; } else { $url_disible = ''; $url_back_color = $text_back_color; $url_value = $instance['URL_'. $i]; } echo ''. "\n"; if ($instance['Visible_'. $i]) $check = ' checked="checked"'; else $check = ''; echo ''. "\n"; echo ''; } echo '
Type Title URL Visible
'; } }// 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'); ?>