WordCamp Boulder – Plugin Development Tips

DandyID

This plugin displays the social identity favicons of the blog author and displays them in a sidebar widget. The DandyID return_services API returns the data as XML.

The code for the DandyID Services plugin has examples of several WordPress plugin features that I hope you find helpful.

See how the readme.txt maps to the hosted plugin page. Includes the specification of several screenshots.

The main module dandyid-services.php has examples of:

  • Creating a sidebar widget.
  • Processing returned XML that is PHP4 and PHP5 compatible.
  • Storing and retrieving wp-database options using an array.
  • Embedding the plugin name and version-number into a <div> tag that appears on all blog pages that render the plugin.
  • Localization for international language support.
  • Creating an options page for admin plugin configuration, including HTML that renders radio buttons and checkboxes.
  • Caching the DandyID API results — on a busy blog, regardless of traffic, the plugin only calls the DandyID API once every 2 hours.
  • A plugin activation hook that creates initialized, defaulted wp-database options.
  • A plugin deactivation hook that cleanly removes the plugin wp-database options.

WordPress maintains this repository which contains all of the files in the plugin package.

PeoplePond

This plugin retrieves “about me” information from PeoplePond, and creates (or refreshes once daily) an About page on a blog.

The main module peoplepond.php has the following examples:

  • Hooking the_content() with a filter hook, causing the plugin code to be called each time any page renders. If it’s the About page, the PeoplePond API is called (only once per day max) to update the About page content.
  • Using wp_insert_post() and wp_update_post().


These tips were prepared for WordCamp Boulder 2010.

Boulder Startup Week – PHP Hacking Demo

This code demonstrates:
- Using PHP to create a command-line utility.
- Passing in arguments from the command-line.
- Calling the Weather Underground REST API (returns XML).
- Extracting the weather text from the returned XML.

Thanks to Ryan Cook for organizing this Boulder Startup Week session.

#!/usr/local/php5/bin/php
<?php

/*****************************************************************************/
/* This demo was created by Neil Simon for Ryan Cooks PHP Hacking Session    */
/* Boulder Startup Week, 05/05/2010                                          */
/*****************************************************************************/
/* Module ........ get_forecast.php                                          */
/* Description ... (1) Uses PHP to create a command-line utility             */
/*                 (2) Passes arguments in from the command-line             */
/*                 (3) Calls the Weather Underground REST API (returns XML)  */
/*                 (4) Extracts the weather text from the returned XML       */
/* Usage ......... get_forecast.php {zip5}                                   */
/* Example ....... get_forecast.php 80304                                    */
/*****************************************************************************/

// First executable line, calls main()
main ($argc, $argv);

function main ($argc, $argv)
    {
    // Initialize to failure, set to 0 upon success
    $rc = 1;

    // Ex: $argv[0] get_forecast.php
    // Ex: $argv[1] 80304
    if ($argc != 2)
        {
        printf ("Usage ..... get_forecast.php {zip5}\n");
        printf ("Example ... get_forecast.php 80304\n");
        }
    else
        {
        // Extract option value
        $zip5 = $argv [1];

        // Get weather lines of text
        $weatherForecastLinesArray = array ();

        // Get lines of weather text
        if (getWeatherForecast ($zip5, $weatherForecastLinesArray) == 0)
            {
            // Display lines
            foreach ($weatherForecastLinesArray as $weatherForecastLine)
                {
                printf ("%s\n", $weatherForecastLine);
                }

            // Successful
            $rc = 0;
            }
        }

    // Returns status code to the operating system
    return ($rc);
    }

function getWeatherForecast ($zip5, &$weatherForecastLinesArray)
    {
    // Initialize to failure, set to 0 upon success
    $rc = 1;

    // Create a constant that points to the REST API
    define (WUNDERGROUND_API_URL,
    "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=$zip5");

    // Get the weather text -- returned as XML
    if (($wundergroundStr = file_get_contents (WUNDERGROUND_API_URL)) == FALSE)
        {
        printf ("ERROR: file_get_contents (WUNDERGROUND_API_URL) failed.\n");
        }
    else
        {
        // Create the XML array from the returned data
        $wundergroundXml = new SimpleXMLElement ($wundergroundStr);

        // Extract the text fields
        $forecastday = $wundergroundXml->txt_forecast->forecastday [0];
        $weatherForecastLinesArray [] = $forecastday->title;
        $weatherForecastLinesArray [] = $forecastday->fcttext . "\n";

        // Successful
        $rc = 0;
        }

    return ($rc);
    }

?>

What Matters Most

What matters most is how you program.

Technologies come and go, but good working practices last forever.

The easiest mistakes to fix are the ones you don’t make.

Top People Skills for Developers

Be Friendly

  • People like to work with people they like.
  • A genuine smile and a positive attitude goes a long way.
  • Respect everyone — you can learn from everyone.

Be Collaborative

  • Work hard to build concensus among stakeholders.
  • Be willing to compromise.
  • If you don’t agree with an idea, suggest creative alternatives that can incorporate the idea in different ways.

Be a Great Listener

  • What does the user really need?
  • It’s not what you want — it’s what they want.
  • Listen objectively. Ask open ended questions. Allow everyone the opportunity to speak.

Deliver Some Early Pieces Quickly

  • Lets your user know you’ve been listening.
  • Gives users an opportunity for feedback.
  • Keeps the conversation going in a positive direction.