Categories
Journal

First WordPress Widget/Plugin

I wrote this Widget (Plugin) for WordPress to be able to properly display the subscription form for The Tech Doctor Newsletter. It builds on the PHPlist Plugin by Jesse Heap which connects to PHPlist. It is based on a sample plugin by Kaf Oseo

&lt::?php

/*

      Plugin Name: PHPlist Widget

      Plugin URI: http://www.geekzone.com.au/

      Description: PHPlist  Widget that makes a widget out of &lt::a href=&quot::http://www.jesseheap.com/projects/wordpress-phplist-plugin.php&quot::&gt::Jesse Heap\’s PHPlist&lt::/a&gt:: plugin

      Author: Mark Snell

      Version: 0.65

      Author URI: http://www.geekzone.com.au/

      based on: http://guff.szub.net/2006/04/06/my-widget-example-wordpress-widget/

      */

function widget_PHPlist_init(){

      function widget_PHPlist($args) {

        extract($args)::

        $options = get_option(\’widget_PHPlist\’)::

        $title = empty($options[\’title\’]) ? \’&lt::b&gt::\’.\’Join our Mailing List:\’.\’&lt::/b&gt::\’ : \’&lt::b&gt::\’.$options[\’title\’].\’&lt::/b&gt::\’::

        echo $before_widget::

        echo $before_title . $title . $after_title::

        $content = apply_filters(\’the_content\’, \’&lt::!–phplist form–&gt::\’)::

        echo $content::

        echo $after_widget::

        }

  

    // This is the function that outputs the form to let users edit

    // the widget\’s title and so on. It\’s an optional feature, but

    // we\’ll use it because we can!

    function widget_PHPlist_control() {

        // Collect our widget\’s options.

        $options = get_option(\’widget_PHPlist\’)::

        // This is for handing the control form submission.

        if ( $_POST[\’PHPlist-submit\’] ) {

            // Clean up control form submission options

            $options[\’title\’] = strip_tags(stripslashes($_POST[\’PHPlist-title\’]))::

            update_option(\’widget_PHPlist\’, $options)::

        }

        // Format options as valid HTML. Hey, why not.

        $title = htmlspecialchars($options[\’title\’], ENT_QUOTES)::

// The HTML below is the control form for editing options.

?&gt::

        &lt::div&gt::

        &lt::label for=&quot::PHPlist-title&quot:: style=&quot::line-height:35px::display:block::&quot::&gt::Widget title: &lt::input type=&quot::text&quot:: id=&quot::PHPlist-title&quot:: name=&quot::PHPlist-title&quot:: value=&quot::&lt::?php echo $title:: ?&gt::&quot:: /&gt::&lt::/label&gt::

        &lt::input type=&quot::hidden&quot:: name=&quot::PHPlist-submit&quot:: id=&quot::PHPlist-submit&quot:: value=&quot::1&quot:: /&gt::

        &lt::/div&gt::

    &lt::?php

    // end of widget_PHPlist_control()

    }

    register_sidebar_widget(\’PHPlist\’, \’widget_PHPlist\’)::   

        // This registers the (optional!) widget control form.

    register_widget_control(\’PHPlist\’, \’widget_PHPlist_control\’)::

     }

    add_action(\’plugins_loaded\’, \’widget_PHPlist_init\’)::

?&gt::

You can download the file here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.