preload
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

breathingtech.com 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:
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:
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 Bit.ly, I am not a php expert or familiar with the Bit.ly API so I googled and found the php code needed for using Bit.ly to shorten my url. I found a great example at www.devmoose.com in a post called Automatically Create a Bit.ly URL for WordPress Posts. Just follow the steps in the referred post at devmoose.com 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:

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

Continue reading »

Tagged with:
Aug 12

Displaying pingbacks to your post is a good thing because your readers often will find interesting and value added information in the post that links to your post. What I don’t like is when pingbacks get mixed with the comments to your post, I find that messy. Therefore I decided to separate the pingbacks from my comments and in this post I will show you how I did it.

I guess that some WordPress themes already have this functionality, but mine did not so I decided to implement this by my self.

First I changed the post summary heading to count comments and pingbacks separately. Originally it counted both comments and pingbacks and displayed it as “x comments”. By implementing the following code “x comments and x pingbacks” will be displayed.
Insert the following code in the have_posts() loop in index.php

<div class="post" id="post-<?php the_ID(); ?>">
<div class="date"><span><?php the_time(‘M’) ?>
</span> <?php the_time(‘d’) ?></div>

<div class="title">
<h2 class="posttitle">
<a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h2>

Continue reading »

Tagged with:
Jul 19

It is always a good thing to have as many readers as possible on your blog. To increase the number of readers it is important to make it easy for them to both follow your blog posts and share your posts on social networks.

I will show you how you very easy can add icons with links for rss feed, twitter, delicious, stumbleupon, technorati and digg.

I have chosen to have the RSS feed and Twitter icon on the top of my left side bar. This is how you do can do this in WordPress.

Insert in the very beginning of sidebar.php

<div style="text-align:center; padding-top:5px;">
<a href="YOURRSSFEEDURL"><img title="Subscribe to my feeds"
 src="RSSFEEDICONURL" alt="Subscribe to my feeds" /></a>
<a href="YOURTWITTERURL"><img title="Follow me on Twitter"
 src="TWITTERICONURL" alt="Follow me on Twitter" /></a>
</div>

Continue reading »

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