1 | <?php
|
---|
2 | /*
|
---|
3 | * Plugin Name: XPressME MENU
|
---|
4 | * Version: 1.0
|
---|
5 | * Plugin URI: http://jessealtman.com/2009/06/08/tutorial-wordpress-28-widget-api/
|
---|
6 | * Description: XPressME MENU widget using the the WordPress 2.8 widget API. This is meant strictly as a means of showing the new API using the <a href="http://jessealtman.com/2009/06/08/tutorial-wordpress-28-widget-api/">tutorial</a>.
|
---|
7 | * Author: toemon
|
---|
8 | * Author URI: http://ja.xpressme.info
|
---|
9 | */
|
---|
10 | class XPress_Menu_Widget extends WP_Widget
|
---|
11 | {
|
---|
12 | /**
|
---|
13 | * Declares the XPress_Menu_Widget class.
|
---|
14 | *
|
---|
15 | */
|
---|
16 | function XPress_Menu_Widget(){
|
---|
17 | $widget_ops = array('classname' => 'widget_xpress', 'description' => __( "XPressME User Menu Widget") );
|
---|
18 | $control_ops = array('width' => 400, 'height' => 300);
|
---|
19 | $this->WP_Widget('XPress_Menu', __('XPressME MENU'), $widget_ops, $control_ops);
|
---|
20 | }
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Displays the Widget
|
---|
24 | *
|
---|
25 | */
|
---|
26 | function widget($args, $instance){
|
---|
27 | global $xpress_config,$xoops_config;
|
---|
28 |
|
---|
29 | extract($args);
|
---|
30 | $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']);
|
---|
31 |
|
---|
32 | # Before the widget
|
---|
33 | echo $before_widget;
|
---|
34 |
|
---|
35 | # The title
|
---|
36 | if ( $title )
|
---|
37 | echo $before_title . $title . $after_title;
|
---|
38 |
|
---|
39 | # Make the XPressME MENU widget
|
---|
40 | echo '<ul>';
|
---|
41 | for($i = 0; $i < 10; $i++) {
|
---|
42 | $link_name = $instance['name' . $i];
|
---|
43 | $link_url = $instance['link' . $i];
|
---|
44 | if (!empty($link_name)) echo '<li><a href="' . $link_url . '">' . $link_name . '</a></li>';
|
---|
45 | }
|
---|
46 | echo '</ul>';
|
---|
47 | # After the widget
|
---|
48 | echo $after_widget;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Saves the widgets settings.
|
---|
53 | *
|
---|
54 | */
|
---|
55 | function update($new_instance, $old_instance){
|
---|
56 | $instance = $old_instance;
|
---|
57 | $instance['title'] = strip_tags(stripslashes($new_instance['title']));
|
---|
58 |
|
---|
59 | for($i = 0; $i < 10; $i++) {
|
---|
60 | $instance['name'. $i] = strip_tags(stripslashes($new_instance['name'. $i]));
|
---|
61 | $instance['link' . $i] = strip_tags(stripslashes($new_instance['link'. $i]));
|
---|
62 | }
|
---|
63 |
|
---|
64 | return $instance;
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Creates the edit form for the widget.
|
---|
69 | *
|
---|
70 | */
|
---|
71 | function form($instance){
|
---|
72 | global $xpress_config,$xoops_config;
|
---|
73 | //Defaults
|
---|
74 | $instance = wp_parse_args( (array) $instance,
|
---|
75 | array(
|
---|
76 | 'title'=> __('User Menu'),
|
---|
77 | 'name0' => __('Site Home'),
|
---|
78 | 'link0' => $xoops_config->xoops_url,
|
---|
79 | 'name1' => '',
|
---|
80 | 'link1' => '',
|
---|
81 | 'name2' => '',
|
---|
82 | 'link2' => '',
|
---|
83 | 'name3' => '',
|
---|
84 | 'link3' => '',
|
---|
85 | 'name4' => '',
|
---|
86 | 'link4' => '',
|
---|
87 | 'name5' => '',
|
---|
88 | 'link5' => '',
|
---|
89 | 'name6' => '',
|
---|
90 | 'link6' => '',
|
---|
91 | 'name7' => '',
|
---|
92 | 'link7' => '',
|
---|
93 | 'name8' => '',
|
---|
94 | 'link8' => '',
|
---|
95 | 'name9' => '',
|
---|
96 | 'link9' => ''
|
---|
97 | ) );
|
---|
98 |
|
---|
99 | $title = htmlspecialchars($instance['title']);
|
---|
100 |
|
---|
101 | // Output the options
|
---|
102 | echo '<p><label for="' . $this->get_field_name('title') . '">'. "\n";
|
---|
103 | echo __('Title:') . '<input style="width: 200px;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>'. "\n";
|
---|
104 | echo '<label>' . __('Title') . '</label>' . '<label style="margin-left:120px;">' . __('URL') . '</label>' . "\n";
|
---|
105 | for($i = 0; $i < 10; $i++) {
|
---|
106 | echo '<p><input style="width: 100px;" id="' . $this->get_field_id('name' . $i) . '" name="' . $this->get_field_name('name' . $i) . '" type="text" value="' . $instance['name'. $i] . '" />:'. "\n";
|
---|
107 | echo '<input style="width: 280px;" id="' . $this->get_field_id('link' . $i) . '" name="' . $this->get_field_name('link' . $i) . '" type="text" value="' . $instance['link'. $i] . '" /></p>'. "\n";
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | }// END class
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Register Hello World widget.
|
---|
115 | *
|
---|
116 | * Calls 'widgets_init' action after the Hello World widget has been registered.
|
---|
117 | */
|
---|
118 | function XPress_MenuInit() {
|
---|
119 | register_widget('XPress_Menu_Widget');
|
---|
120 | }
|
---|
121 | add_action('widgets_init', 'XPress_MenuInit');
|
---|
122 | ?>
|
---|