I’m Being Seduced…

… by Microsoft and their platform.

Please, allow me to explain. I’ve always been a fan of Microsoft products. Microsoft Office is awesome, and the 2007 platform really set the bar for my Best Upgrade Over a Previous Version award. Windows, in all its various versions, has been my operating system since I was a child. I remember using Windows 3.1 like it was yesterday.

However, what I’m talking about in this post is Microsoft’s development platform. Ever since I started programming I’ve been a PHP guy at heart. The dynamic nature, popularity, and ease in picking up the language all combined to make it my dominant tool over the past couple of years.

In school, I learned to use Java and Scheme. I also taught myself C# in my spare time (which in my opinion is basically Java done Right. I thought C# was nice but haven’t really gotten the chance to pursue development in it.

Over the last couple of weeks I’ve been checking out the resources available for .NET development. The amount of stuff out there has increased so much in the past couple of years that I am almost baffled. Where was all this when I needed to know how to work in .NET?

The quantity of tips, tricks, and tutorials doesn’t nearly approach the amount of stuff out there for PHP, JS, HTML, and CSS. However, for every 25 crappy, rewritten and repurposed PHP article out there, there is one awesome, well-written, and unique article on some part of the Microsoft platform.

Also, I recently downloaded the Visual Studio 2008 trial and it has to be the best IDE that I have ever used in my entire life. I mean, WOW. This thing is incredible and I can only imagine the productivity improvements I would experience if I was using it full time.

With the public releases of WPF, WCF, and .NET 3.5 in the last year, now is the time to be excited about Windows development. A few days ago the ASP.NET MVC beta was officially released, making it easy and intuitive to build web applications using C#. I’ve used various PHP frameworks over the past couple of years, but not a single one of them approaches the ease of use and capabilities provided by ASP.NET MVC.

I can’t say what I’ll be doing over the course of the next year, but I would be surprised if I didn’t start, both in my personal programming projects and client work, start a shift towards .NET development, both on the desktop and the web.


Problem with Amazon Reloaded for WordPress? Read This

Recently I’ve noticed that a great many people are having problems with my Amazon Reloaded for WordPress plugin.  This is, of course, not good.  I don’t want my plugins to stop working for my valuable clients?  Besides, it is bad press.

So, here is what I’ve determined the steps should be if you’re having problems.

  1. Do a fresh install — This one is pretty obvious, but I want to mention why you would want to. First, you need to make sure you have all the files on your server. I added some new things with this recent update and I’m not sure how good the auto-updater is about putting them up there for you. Second, it’s just good practice to reinstall at least once to see if something will work.
  2. Make sure the XSLT stylesheet is on your server and publicly accessible — In the latest version of Amazon Reloaded for WordPress, I moved the XSLT stylesheet that the plugin utilizes from my server to yours. That way, the speed of fetch is determined not by how slow or fast my server is, but by how slow or fast yours is. I think that’s fair. But, if the file isn’t publicly accessible, you won’t get the results you desire. A 0 will show up or it will be a bunch of gobbledy gook.
  3. You should be able to change the file to be publicly accessible, but if you need help, I can do my best.


WP-Amazon Reloaded Gets a New Name

I’ve had a lot of success with WP-Amazon Reloaded so far. People have been happy with the results of my development efforts thus far. As such, I am happy to announce that I finally received WordPress.org repository access today to host the plugin.

Unfortunately, WP-Amazon Reloaded was no longer available as a name for a plugin on the official WordPress.org plugins repository so I went ahead and renamed the plugin. From now on, WP-Amazon Reloaded is Amazon Reloaded for WordPress. You can view the official repository and download the latest version there.

If you have any feature requests, please don’t hesitate to ask.


WordPress Plugin — Restore Id

In the latest version of the WordPress blogging system, the administrative UI was completely revamped. One of the biggest differences comes with the manage posts screen. The Id column was removed from the posts table, making it somewhat ponderous to attempt to find the Id of a specific post. This is bad news for designers, as the Id of a post sometimes determines what kind of styling to apply to the content.

The WordPress community’s solution to this problem is the following:

Q. How can I find the Post ID or Page ID?

A. If your browser shows the URL in the status bar, when you mouse over a link, you can see the ID in the as part of the URL displayed in the browser status bar. In FireFox you can show the status bar by checking the Status bar choice under View. A more complicated method to finding the ID is to use something like phpMyAdmin to look at the database table wp_posts–look down the column of post_title to find your Post or Page Title. The ID field on that row will be your Post (or Page) ID.

(from WordPress 2.5 FAQ)

Someone on the WordPress ideas page suggested that the Id column be restored, and that’s exactly what this plugin does. You can download the plugin from it’s official plugin page on WordPress.org. Please let me know if you have any problems.


How-To: Load JavaScript Libraries in WordPress

Note: This is a modified version of my original post. A lot has changed since this was first written, and this is my second most popular blog page. As such, I’ve edited it to make certain that it is as up to date as possible.

Almost every plugin that I’ve written has some type of JavaScript in it. I generally separate all the JavaScript that I can out of pages that I expect to be displayed and include it in separate file(s). In WordPress, there is a right way and a wrong way to make sure these external files are linked to from the page being displayed. In this post, I’ll show you the right way to do things, and then expand on that by showing you what WordPress has out of the box for you to use.

WordPress Functions of Interest

WordPress has two particular functions of interest in this discussion. The first is wp_register_script. Its signature is as follows:

wp_register_script( $handle, $src, $dep = array(), $ver = false );

wp_register_script adds a new JavaScript file to a list of those that are recognized by WordPress. It will not cause the script to be displayed in output, but that’s what the next function is for. Also note that the variable $src must be a absolute URL path and not a server folder path. The server folder path won’t work here.

The next function of interest is wp_enqueue_script. Its signature is as follows:

wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false );

When you need to make sure that WordPress outputs an appropriate script tag, this is the function you use. Notice that $src is a optional argument. If the script has previously been registered with WordPress via wp_enqueue_script, you need pass only the handle because the source of the file is already known.

Now, that all leads us to a couple of questions. What are the benefits of these two functions? How do you use them? What scripts are already available?

Benefits

The main benefit of using wp_register_script and wp_enqueue_script is that you won’t have script collisions like you could if you linked to the the script files manually.

Also, if you were observant you noticed the $deps variable in both function signatures above. This denotes what other JavaScript your file relies on. If you need jQuery to be loaded for your JavaScript to work, you could do the following.

wp_register_script( 'my-handle', 'http://example.com', array( 'jquery' ) );

There is another distinct benefit to using wp_register_script. Say you are developing a plugin which adds multiple pages to the administrative and frontend interface. You have developed a custom JavaScript file that makes everything work, and you need to include it in these various places. You would register the script once, probably when your plugin is initialized, and then just enqueue it whenever you need to throughout your plugin.

Usage

I’m going to provide a very simple example below. This is a full plugin, but it doesn’t really do anything since some dependencies are missing (like the JavaScript file).

class Test_Enqueue {

	/**
	 * Adds action and filter hooks and registers our custom javascript file.
	 *
	 */
	function __construct() {
		add_action( 'admin_head', array( &$this, 'on_admin_head' ) );

		wp_register_script(
			'enqueue-test',
			plugin_dir_url( __FILE__ )  . '/enqueue-test.js',
			array( 'jquery' )
		);
	}

	/**
	 * Enqueues the necessary javascript file if this is the Write Page interface.
	 *
	 */
	function on_admin_head() {
		if( 'page.php' == basename( $_SERVER[ 'REQUEST_URI' ] ) ) {
			wp_register_script( 'enqueue-test' );
		}
	}
}

Pre-Registered Scripts

WordPress provides a ton of pre-registered scripts right out of the box. Here is a complete listing of them as of WordPress 2.6.1. The following scripts can be used anywhere:

  • common
  • sack
  • quicktags
  • colorpicker
  • editor
  • editor_functions
  • tiny_mce
  • prototype
  • wp-ajax-response
  • autosave
  • wp-lists
  • scriptaculous-root
  • scriptaculous-builder
  • scriptaculous-dragdrop
  • scriptaculous-effects
  • scriptaculous-slider
  • scriptaculous-sound
  • scriptaculous-controls
  • scriptaculous
  • cropper
  • jquery
  • jquery-form
  • jquery-color
  • interface
  • suggest
  • schedule
  • thickbox
  • swfupload
  • swfupload-degrade
  • swfupload-queue
  • swfupload-handlers
  • jquery-ui-core
  • jquery-ui-tabs
  • jquery-ui-sortable

The following scripts can only be used in the administrative area.

  • ajaxcat
  • admin-categories
  • admin-tags
  • admin-custom-fields
  • password-strength-meter
  • admin-comments
  • admin-users
  • admin-forms
  • xfn
  • upload
  • postbox
  • slug
  • post
  • page
  • link
  • comment
  • admin-gallery
  • media-upload
  • admin-widgets
  • word-count
  • wp-gears
  • theme-preview