May 04

I have not been active visiting my own blog lately and when I opened it today it did not look very good. Actually it was broken with an error message on the top of the page and no posts/articles showing.

Warning: Parameter 1 to fb_update_comment_type_cache() expected to be a reference, value given in /home/breathin/public_html/wp-includes/plugin.php on line 230

php_issue earlier today when I first noticed this issue

Since I had not attended the website for a while I hoped that just doing some updates of WordPress and plugins would fix the problem but it did not. It is the theme I am using that is causing this problem and I am not updating the theme since I have done a lot of changes to it.

Continue reading »

Tagged with:
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 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 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:
Jul 07

I wanted to make it as easy as possible for my blog readers to directly retweet my posts. First I started to install and test several WordPress plugins for this but I just couldn’t seem to find one that I liked. Some of them are to massive and are showing information about how many and who has retweeted your post, I don’t need that. Other required the Twitter Anywhere connection and the user must accept that the retweet application on my blog can connect directly to their Twitter account, I don’t want to force my readers to do this. I decided to create the Retweet functionality by myself so I would have full control on the behavior. This post will tell you step by step how to achieve this.

First I wanted to shorten the post url by using, I am not a php expert or familiar with the API so I googled and found the php code needed for using to shorten my url. I found a great example at in a post called Automatically Create a URL for WordPress Posts. Just follow the steps in the referred post at to achieve this.  I did a minor modification to the code to make it work in my WordPress : I added “<? php” before the code and  “?>” after the code. I also added the “if function exists” check.

The complete code to add in your functions.php file:

//create url
if ( !function_exists(‘bitly’) ) {
function bitly()
//login information
$url = get_permalink(); //generates wordpress’ permalink
$login = ‘yourbitlyusername’; //your login
$apikey = ‘yourbitlyapikey’; // apikey
$format = ‘json’; //choose between json or xml
$version = ‘2.0.1’;

Continue reading »

Tagged with:
Subscribe to my feeds Follow me on Twitter