If you have useful tools to help you when you are writing an answer on a WPSE question, please list them here so we can all benefit from them!

4 Answers 4


I wrote a small script that creates a new plugin, based on the question ID. It uses the Stack Exchange API to get the question info, puts that in the plugin header, and opens the file in an editor.

I created a local setup with all WP versions since 1.5, with a plugin dir that has a symlink called wpse to a common plugin folder. I just need to go to this plugin folder, type wpse/create 1234, and it creates a plugin for question #1234 in the common folder, and a symlink in this version's plugin folder. If I want to try it out in another version I just create an extra symlink.

#!/usr/bin/env php
// This file is called `create`, in the common folder, and made executable
function createWPSEPlugin( $idQuestion )
    $questionInfo = getWPSEQuestionInfo( $idQuestion );

    if ( ! $questionInfo ) {
        exit( "Cannot get question info\n" );

    $questionSlug = strtolower( preg_replace( '/[^\w\-]/', '', str_replace( ' ','-', $questionInfo->title ) ) );

    $pluginDir = $idQuestion . '-' . $questionSlug;

    $baseDir = dirname( __FILE__ );

    if ( is_dir( $baseDir . '/' . $pluginDir ) ) {
        exit( "Plugin already exists here!\n" );

    if ( ! mkdir( $baseDir . '/' . $pluginDir ) ) {
        exit( "Cannot make plugin dir!\n" );

    $pluginFilename = 'wpse-' . $idQuestion . '.php';

    $fh = fopen( $baseDir . '/' . $pluginDir . '/' . $pluginFilename, 'w' );

    if ( ! $fh ) {
        exit( "Cannot create plugin file!\n" );

    fwrite( $fh, <<<EOF
Plugin Name: WPSE {$idQuestion}
Plugin URI: http://wordpress.stackexchange.com/questions/{$idQuestion}/{$questionSlug}
Description: {$questionInfo->title}
Version: 1.0
Author: Jan Fabry

    fclose( $fh );

    $currentDir = getcwd();

    if ( 'plugins' == basename( $currentDir ) ) {
        // Educated guess: we are in a WP plugin dir
        symlink( $baseDir . '/' . $pluginDir, 'wpse-' . $idQuestion );

    // Extra: open plugin file. Change this to suit your situation
    exec( 'open ' . $baseDir . '/' . $pluginDir . '/' . $pluginFilename );

function getWPSEQuestionInfo( $idQuestion )
    $urlAPI = 'http://api.wordpress.stackexchange.com/1.0/questions/';

    // This is probably not the best way to do this...
    $compressedResponse = file_get_contents( $urlAPI . $idQuestion );
    $jsonResponse = file_get_contents( 'compress.zlib://data://text/plain;base64,' . base64_encode( $compressedResponse ) );

    $arrayResponse = json_decode( $jsonResponse );

    return $arrayResponse->questions[0];

createWPSEPlugin( $argv[1] );
  • 2
    wow, very cool -- consider listing this on meta.so as well Commented Feb 4, 2011 at 2:35
  • @Jeff: As a WordPress-specific "question", or make it more generic, so people can post stub generators for other languages too?
    – Jan Fabry
    Commented Feb 4, 2011 at 8:52

I modified Jan Fabry's plugin above and created a mini-app of sorts that spits out a plugin file based on the question ID.

Here's what the front-end form looks like:

enter image description here

Here's a sample of what is generated.

WPSE Generated Plugin

All you need to do is:


Here's a simple workflow I use to identify answers to difficult questions that aren't obvious in the Codex or from previous experience: http://3-3.me/eMTF

Here's my local setup for researching/testing/etc...

  • Standard local installation of WordPress setup to create and test answers
  • I use my IDE's 'find in files' function to search WordPress core for functions, HTML class names, or any other clue I can find on the DOM to help locate functionality
  • My IDE is also setup to track WP phpdocs and functions. This allows me to easily traverse the core by simple shift-clicks on the convenient links to the original functions.
  • I use Twenty Eleven with no plugins activated for testing answers as it is a good sanity check against rogue code in custom themes/plugins.

As a caveat, if difficult questions pertain to specific plugins, I rarely answer them and usually direct users to the plugin author via the WordPress.org forums. I am also careful not to do the entire work for the user, but give them a functional proof-of-concept.


We already had a related question about creating screenshots. Skitch was recommended for Mac users.

  • @Jan Fabry: Yes, I would love to see more people providing screenshots with Skitch or another tool that provides shadows; they make for a much more pleasing view. Commented Feb 4, 2011 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .