Meta-Lite Widget: my first WordPress plugin

Based on tutorials from Widgetizing Plugins, Lisa Stewart, Emanuele Feronato, and especially Hrw website; here is my first plugin for WordPress: Meta-Lite Widget for your sidebar

All it does is showing the Register/Admin and Login/Logout links. It works on WordPress 2.6. You can try it with different version of WordPress and let me know if it works on yours. Meta-Lite uses its own namespace so it won’t conflict with the default Meta Widget that comes with WordPress. You can have them side by side.

Install

  • Download the zip (link below), unzip to get the widget-meta-lite.php file
  • Put it under /wp-content/plugins/widget-meta-lite.php
  • You will see the widget listed under Plugin Management, click to activate it

Un-install

  • Just delete the file /wp-content/plugins/widget-meta-lite.php

Usage

  • The widget should now be available for use in Design/Widgets
  • Use it as any other Widget ;-p. Drag and drop it to your sidebar

Download widget-meta-lite.zip

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/* <WP Plugin Data>
 * Plugin Name: Meta Lite
 * Description: Light version of Meta widget -- Only show Register/Admin and Login/Logout
 * Author: Chuong Nguyen
 * Version: 1
 * Plugin URI: http://www.chuongnguyen.info
 * Author URI: http://www.chuongnguyen.info
 * Based on Marcin Juszkiewicz's plugin
 */
 
/* Display the widget */
function widget_meta_lite($args) {
  extract($args);
  $options = get_option('widget_meta_lite');
  $title = empty($options['title']) ? __('Meta') : $options['title'];
?>
  <?php echo $before_widget; ?>
  <?php echo $before_title . $title . $after_title; ?>
  <ul>
    <?php wp_register(); ?>
    <li><?php wp_loginout(); ?></li>
  </ul>
  <?php echo $after_widget; ?>
<?php
}
 
/* Let user have the option to define 'title' when displaying the widget */
function widget_meta_lite_control() {
  $options = $newoptions = get_option('widget_meta_lite');
  if ( $_POST["meta-submit"] ) {
    $newoptions['title'] = strip_tags(stripslashes($_POST["meta-lite-title"]));
  }
  if ( $options != $newoptions ) {
    $options = $newoptions;
    update_option('widget_meta_lite', $options);
  }
  $title = attribute_escape($options['title']);
?>
  <p><label for="meta-lite-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="meta-lite-title" name="meta-lite-title" type="text" value="<?php echo $title; ?>" /></label></p>
  <input type="hidden" id="meta-submit" name="meta-submit" value="1" />
<?php
}
 
/* Hook the widget to the sidebar */
function widget_meta_lite_init() {
  if ( function_exists('register_sidebar_widget') ) {
    register_sidebar_widget(__('Meta Lite'), 'widget_meta_lite');
    register_widget_control('Meta Lite', 'widget_meta_lite_control');
  }
}
 
add_action('plugins_loaded', 'widget_meta_lite_init');
 
?>

1 comment so far. Skip to comment form »

  1. not karl rove said on August 21, 2008 at 2:23 pm

    Thanks for that. I needed it for a project I’m throwing together in a hurry… was going to have to build it myself but you saved me the trouble.

Leave a comment

No registration is required to comment. However, Registering and/or Logging In before posting comments is much appreciated