Trapping WordPress errors with output buffering.

If you have tried to use AJAX with WordPress, most likely you have stumbled upon the wp_die() function which completely kills the response you expect to get. However, we can trap the wp_die() by using PHP’s output buffering and the ob_start callback function to process the output of wp_die() even though a die() is called. This is a very special case, and will only work when you are able to ensure output buffering can be called before the die is called.

The easiest way to get a non-fatal wp_die() error (an error that shouldn’t cause the entire application to stop) is when submitting comments: non-fatal errors occur whenever someone posts too quickly or submits a duplicate comment, so this can be a problem when creating an AJAX app to submit comments (I ran into this problem with INAP.)

Since AJAX makes the entire submit process very quick, so it is easy to trigger the “Posting too quickly” error if the user make short comments, and when this happens an entire page –complete with CSS and headers– is returned as the AJAX response.

Continue reading. »

INAP 3.0 Progress

Aside from a brief flirtation with a couple payed projects, I’ve been heavily focusing on rewriting the code for INAP 3.0, and it has almost reached the point of a private beta (which means I start running it on this site.) I have selected the new name for INAP 3.0, but I’m not going to reveal it just yet. Here is a small preview of what you can expect from INAP 3.0:

INAP 3.0 is now truly modular with a main Javascript/PHP core that other features hook into to function. This core is easily extensible and the new structure of a main project with many smaller projects will make bugfixes and upgrades less painful, and will allow the user to upgrade the plugin section by section as most changes in the modules won’t effect the core.

For the users:

  1. INAP 3.0 will make upgrades far less painful.

Continue reading. »

WordPress 2.3 is looking good.

I’ve been playing around with WordPress 2.3 Alpha and so far I like it.

Good Things:

  1. I like the new post status “Pending Review” and the ability to sort posts by status. Somone posted pictures here.
  2. Tags are looking good..
  3. A UTW tag importer is built in; of course, I realized this only after I created one.
  4. The “categories” database tables have been retired and everything is tag based (categories are a type of tag similar to the ways pages are just a form of post). I’m almost giddy at the possibilities.
  5. Major features of INAP still work. Pheww.
  6. Not finished yet, but hopefully, searches organized by relevance instead of date will also be released.

Bad things (that will probably be fixed soon):

  1. It seems you can’t add child categories in the July 28 Trunk, but I assume this will be fixed.
  2. No “Manage Tags” page yet.

Multi-plugin Plugin

Multi-plugin is a very simple script that allows you to add small bits of PHP scripts, such as WordPress filters, without having to make a plugin for them.

Download Multi-plugin

Installation is as simple as renaming the file to .php, uploading it to your server, activating it, and adding some script to the textbox (for example, I use the following code to remove the nofollow attribute from comments.)

< ?php
add_filter('get_comment_author_link', 'aoi_follow');
add_filter('comment_text', 'aoi_follow');
function aoi_follow($link){
   return preg_replace('/(<a.*?rel[^>]*)nofollow(.*?)/','${1}${2}',$link);
}

?>

You can also use the following to add the trailing slash back onto feeds, categories, pages, etc. in WordPress 2.2+.

< ?php
add_filter('user_trailingslashit', 'aoi_slashit',10,2);
function aoi_slashit($string, $type=''){
  if($type == 'page' || $type == 'category'|| $type == 'month'|| $type == 'day'|| $type == 'paged'|| $type == 'feed'){
    return trailingslashit($string);
  }else{
   return $string;
  }
}
?>

Sneak Peeks Widget

Updated June 23 2007 — added WP 2.2 Support, removed 2.0 support, added ability to restrict sneak peeks to specific categories.

The Sneak Peaks widget allows you to list some of the upcoming posts on your site to allow visitors to get a glimpse of what is coming and encourage them to return. The widget is very simple, but allows you to customize the title, number of posts shown and the display text of each sneak peek using some simple tags.

You can download it here:
Sneak Peaks Widget 1.7 (WordPress 2.1+)
Sneak Peaks Widget 1.6 (WordPress 2.0, 2.1)

Installation is very simple. Just unzip the .zip file and upload the .php file to your plugins/widgets folder. Activate it in your plugins menu and then go to your Presentation>Sidebar Widgets menu and customize to your heart’s content.

WordPress Code Escape

Here is another small modified plugin that auto-escapes your code, nicely displays line numbers and uses valid XHTML. This plugin is based off of SemCodeFix, and adds many of the features I wanted in my code plugin.

Download:
WordPress Code Escape

Directions:
Download the file and save it as a .php file.
Upload to your plugins directory.
Activate it.
You may optionally choose to add the following style information to your theme’s style.css.

.code_child {
	font-family:"Courier New", Courier, monospace;
	white-space:pre;
	width:90%;
	background-color: #F4F4F4 !important;
	overflow:auto;
	border:1px inset;
 	margin:10px;
}
ol.code_child li{
 	margin:0;
 	padding:0 !important;
 	line-height:100% !important;
 	margin-bottom: -8px;
 	margin-bottom: expression(5 +"px");
 	margin-left:  expression(35 + "px");
}