preload
Feb 04

I have developed a plugin for WordPress that is called DiveBook with the purpose of logging dives. I have now had it published at WordPress Plugin Directory for a while as a beta version. In this post I will talk about bugs and issues I experienced during the beta period and how I solved them.

Unexpected output during activation

The first issue I got was that when activating the plugin the following error message were displayed

The plugin generated 2 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin

Continue reading »

Tagged with:
Jan 13

My DiveBook plugin is completed and I want it to be listed in the WordPress Plugin Directory. This way it will be easier for others to install and read about the plugin. Before you get your plugin listed there is a few steps you must do and a few steps I think you should do. In this post I will talk about what I did to make my DiveBook plugin ready for the world.

First your plugin needs to follow a few restrictions set by WordPress. Then you need to sign up, send request for WordPress to host your plugin and add your plugin to the Subversion repository (you get access to the svn repository when WordPress have read and accepted your hosting request). You also need to create a readme.txt file for your plugin. You can read about the steps above at the WordPress Developer Central.

When it comes to writing the readme.txt file you should spend some effort to make this file detailed and good. All the information a potential user of your plugin will read is parsed from this file. Most important is to have a good description about the plugin, screenshots of the functionality and a good description on how to install and use your plugin.

This is all you need to do. WordPress will automatically publish your plugin from the subversion repository.

Continue reading »

Tagged with:
Jan 04

When developing a smooth plugin for WordPress you will quite often need to supplement php and html with some kind of scripting language. To make the floating input form for the DiveBook plugin I used jQuery and I used Javascript to validate user input and redirecting.

To include your script files to the plugin you need to add the following code in your main php file:

//Add script
add_action('wp_print_scripts', 'divebook_enqueue_js');

function divebook_enqueue_js () {
    wp_enqueue_script('divebookFunctions', WP_CONTENT_URL . '/plugins/divebook/functions.js', array('jquery'),'1.0.1');
    wp_enqueue_script('divebookPopup', WP_CONTENT_URL . '/plugins/divebook/divepopup.js', array('jquery'),'1.0.1');
}

Continue reading »

Tagged with:
Nov 11

I am writing a WordPress plugin called DiveBook that is a plugin for logging dives and view other logged dives. The main part of this plugin is the input form for logging dives and a view where users can search and view logged dives. I want the WordPress administrators using this plugin to be able to inject the plugin in posts or pages. This post describes how I achieved plugin injection to posts or pages.

I chose to enable injection of the plugin (and php in general) by adding a filter that is evaluating the content and looking for php executable code inside a defined bracket.

First I add the filter in top of my main php file (divebook.php). In the filter I hook the content to function filter_php_code

//Add filter to filter executable php code in content
add_filter('the_content', 'filter_php_code', 0);

Continue reading »

Tagged with:
Nov 07

In this post I will explain how I use the WordPress database (MySQL) for the DiveBook plugin I am currently developing. For my plugin I am using the options table in WordPress for storing options and settings for my plugin. The DiveBook plugin will be storing information about dives and for this I am creating new tables in the WordPress database.

In my previous post “Getting started with WordPress plugin development” I talked about how to create a widget for the plugin and how to save options for the widget in the control panel. In the widget.php file I used the option table to store and retrieve the data.

The following code will store data to the options table when the user submits the options.

        //Store title and numdives in options table
        if ($_POST['divebook-submit']) {
            $options['title'] = strip_tags(stripslashes($_POST['divebook-title']));
            $options['numdives'] = strip_tags(stripslashes($_POST['divebook-numdives']));
            update_option('divebook', $options);
        }

Continue reading »

Tagged with:
Nov 05

This post will describe what you need to do to get started with WordPress plugin development.

First you should install WordPress on your localhost to make it easy to test what you are developing. Good instructions about installing WordPress on your own computer can be found at wordpress.org Installing WordPress. I am using Windows 7 so I first installed Windows Web Platform Installer and then launched the WordPress installation from Web PI. I just used the default settings for ISS and selected to create a new database for this installation.  WordPress is now installed and I can access it at http://localhost/wordpress. I also find all the installed WordPress files in the inetpub directory on my drive.

After getting some tips on Twitter I downloaded and installed PhpStorm by JetBrains to use as my IDE for php development. There is a 45 days free trial license available.

To make live testing while developing I decided to work directly on the inetpub directory. I created a folder for my plugin called “divebook”. In PhpStorm open directory to work on. For my plugin the directory is: C:/inetpub/wwwroot/wordpress/wp-content/plugins/divebook/

Continue reading »

Tagged with:
Subscribe to my feeds Follow me on Twitter
DZone MVB