Google now also reports about old versions of software

When I logged in to Google Webmastertools today I was presented with a message that I’m using an old version of Vbulletin on one of my websites. Vbulletin is currently in the 4.x.x. version but in the 3.x.x versions there is still a maintained one, which we’re using. But it’s probably good that Google monitors for it as many outdated versions come with security vulnerabilities. I hope to update to the 4.x.x. branch soon but as our forum is rather large this is more than simply running the update script.

Posted in Google | Leave a comment

WordPress wp_list_comments callback explanation

When working with comments you might want to drastically change the appearance of the comments. You can use a new comment template with

comments_template( '/my-comments.php', true )

which you call from the template where you want to list the comments. But if you want each single comment to be different, you can use the callback function of wp_list_comments.

You use wp_list_comments in your comments template. Default is comments.php in your theme function, but if you used the comments_template function from above, you have to look for that file (of course). You should see wp_list_comments like the The Loop on it’s own. It goes through all of the comments and lists them. With the callback you can modify The Comment Loop and totally make it to your own likings.


<?php 
global $my_object;
wp_list_comments(array('type' => 'all', 'callback', array($my_object, 'my_custom_comments'));
?>

I’m using classes in my plugins, hence the inclusion of the global, you can also put the function in your functions.php and simply remove the references to the object. Then you can create a function in your class or functions.php and start the fun:


function my_custom_comments($comment, $args, $depth){
        
        $GLOBALS['comment'] = $comment;
    
        comment_text();
        
    }

In it, you can use the Comments Tags which are listed here. Questions? I’m happy to help you a little further, so don’t hesitate to post!

Posted in Uncategorized | Leave a comment

WordPress get_comment_meta and update_comment_meta

WordPress now features a function to allow you to store meta data for each comment. Just like it’s able to do so for posts. It seems that, under the hood, WordPress has functionality that potentially prepares it for metadata on whatever you want. As get_comment_meta is nothing but a call to update_meta with the first parameter prefilled with ‘comment’.

Anyway, when you are reading this you are probably looking for a way to get get_comment_meta working. It’s not documented in the Codex (yet) and other information on the web is not always easy to understand or complete. So here’s my try to make you understand get_comment_meta and with it comes update_comment_meta.

  • update_comment_meta -> will allow us to update a comment meta entry and is also used to create a meta entry
  • get_comment_meta -> will alows us to retreive the meta entry for each comment

The metadata for the comments is stored in the database in its own table and the comment ID is required to link the comment to its metadata.

To add comment metadata, a simple call to it like this will make it work:

update_comment_meta($comment_id, 'key', 'value');

If you save the data when someone is adding a new comment, you would probably receive the $comment_id from a call to e.g. wp_new_comment.

Retrieving the comment metadata is a little different than expected, it has a small (and simple) twist. The trick is in the third parameter here:

get_comment_meta($comment_id, 'key', true);

This will return a single result (e.g. string) while the following will result in returing an array:

get_comment_meta($comment_id, 'key');

It’s as simple as this! In case you want the comment ID while retrieving comments, you can replace $comment_id with get_comment_ID();

Posted in Uncategorized | 1 Comment

Features to expect in WordPress 3.2 (to be released Q2/Q3 2011)

WordPress 3.1 has just been released and I, as a WordPress addict, am already searching for information on WordPress 3.2. This release is scheduled for the first half of 2011. One thing seems to be sure, WordPress 3.2 will no longer support PHP4 and MySQL4. Besides that I found other features that are scheduled to appear in WordPress 3.2. Here is a list of features that affect end-users:

  • Minimum version for PHP: 5.2
  • Minimum version for MySQL: 5.0.15
  • Download required translations from GlotPress – This means that WordPress itself, themes and plugins are able to download translations from one, group a collaborative, web-based software translation tool. This would help getting translations automatically without any manual searching and downloading .mo files
  • Administration menu revamp – For plugin developers the current setup of the administration menu is a lot of hassle. With a rewrite/restructuring of the code this is improved
  • User can register/login with e-mail address, no username required anymore, functionality currently available in this plugin
  • Timezone suggestion, based on IP address
  • To be updated when more comes available, tips are very welcome!
Posted in Uncategorized | Leave a comment

How to make WPML compatible with W3C Total Cache

If you’re a heavy user of WordPress and use WMPL together with W3C Total Cache then you might have found out that it doesn’t work properly when using alias domains for each language. The language switcher doesn’t work correctly anymore. It seems that it switches to the first cached page and/or sometimes a random page. It might work for all pages except the home, but can also affect all pages on the website.

The default setting for the disk cache on W3C Total Cache is enhanced. Simply by changing this option to basic, both plugins will work together flawlessly. In enhanced mode the caching plugin fiddles with the headers of the HTTP request, in basic mode it keeps them as they are.

Update: Added clarifications as per the comment of Richard

Posted in Wordpress | 2 Comments

Retrieve server/host Windows version

Not one of the easiest jobs, is retrieving the version information of your Windows computer with PHP. Other methods are available, but they don’t show you the exact version, usually just report WINNT or similair strings. The code below will print the full information on your computer, easy as that…

    $com_object = new COM ( 'winmgmts://localhost/root/CIMV2' );
    $os =  $com_object->ExecQuery("Select * from Win32_OperatingSystem");

    foreach ($os as $os_data )
    {
                //  Windows version information e.g. 6.1.7600  for Windows 7
		$windows_version = $os_data->Version; 
                // Full name of Windows version e.g. Microsoft Windows 7 Professional 
		$windows_caption = $os_data->Caption; 
                // Major Service Pack version (0 if not available)
		$windows_sp = $os_data->ServicePackMajorVersion; 
    }
   

Posted in Wordpress | Leave a comment

WordPress shortcode output buffer versus appending to string

When your develop a WordPress plugin there is a big chance that you will need to include a shortcode. If you simply echo each line, you will notice that your output will not appear on the right place. This is because WordPress will output your code as soon as it encounters the echo. Therefore you should use a different way to get your output on the page. This will ensure that the output will appear on the place where you’ve added the shortcode.

1) You can use the output buffer of PHP, by starting it with ob_start(). Then simply use echo to output your lines. Once you’ve defined your output you can collect your output to a variable, with ob_get_contents() and return this:

function my_shortcode() {
ob_start();
echo 'hello world';
echo 'This is a WordPress shortcode';
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;
}

This will ensure that all your output will be catched by the output buffer and returned. When using multiple shortcodes on a page, this can cause conflicts.

2) Another option is to append strings, this would mean we would rewrite the code above to:

function my_shortcode() {
$output_string = 'hello world';
$output_string .= 'This is a WordPress shortcode';
return $output_string;
}

This should solve any problems with the output of your WordPress shortcode appearing on the wrong place.

Posted in Wordpress | 4 Comments

WordPress footer no longer appearing

All of a sudden, the code included by WordPress Plugins dissapeared, the solution was easier than expected but took a lot of work to finally find out put

<?php wp_footer()?>
</body>

before the body closing tag. Without the tag, the code won’t be inserted. Ofcourse the body tag should be in your HTML page anyway, but if you somehow removed it, this can save you some work.

Posted in Wordpress | 1 Comment