WordPress and NetBeans

Here’s a few tips for how to make the most out of NetBeans for developing WordPress websites.

Making NetBeans aware of WordPress functions so it can suggest autocompletion

Working with WordPress, I often have to look up how to use a function I’ve used before, but have forgotten the order of parameters. The codex, and in particular the WordPress function reference and WordPress template tags reference pages are great places to look for such things. However, if you set up NetBeans to be aware of the WordPress functions, sometimes you can save yourself a trip to the codex. NetBeans is by default aware of any functions defined within any files in your PHP include path, as well as any functions you have defined in your project. One way to make NetBeans aware of the WordPress functions would be to have WordPress core within your project, but I would prefer to not have it there. When working on files on remote servers, main reason I would use NetBeans over vim, it is a little bit cumbersome to download all of WordPress core, and I usually only download what I need from wp-content. In such a scenario, you can teach NetBeans to also load a local copy of WordPress into memory. To teach it that, go to Tools -> Options, then PHP tab.

Code completion will then be enabled, and the PHPDocs in WordPress will be parsed shown when looking at the available functions. In the picture below, I typed ‘WP_Q’ and the autocomplete functions became available below it, as well as the documentation dialog above it.

WordPress Coding Style Adherence

The WordPress coding standard defines how your code should look so that it looks the same as the code in WordPress core. Adhering to a coding standard is a good idea because it promotes consistency and makes for easier reading of the code you write. I’ve prepared an export of the Netbeans configuration for the editor to adhere to the WordPress coding standard. I hope you find it useful! To import it, Click Tools -> Options in the top menu, then press the “Import” button in the dialog window that comes up and follow the instructions there.

What’s Next?

A nice feature that is not available to the extent of my knowledge would be templates for common WordPress files, like there are template for Java classes, and such. The way this would work is you could say “I’m going to make a new theme” and it would create all the files a theme requires. Or “I’d like to make a widget.”, “I’d like to write a shortcode.” and NetBeans would create the “boilerplate” code so you can get to coding right away.

Do you have any NetBeans tips you’d like to share with your fellow WordPress site builders? Do you know of a plugin for NetBeans that adds those templates I mention in the section above? Thanks for reading.

Patch for JWPlayer

I made a website for the Positive Parenting Program of the Manitoba Government while working at Canada’s Web Shop, and it had videos on one of the pages. Because the videos are self-hosted, I used the excellent JWPlayer for WordPress plugin, and it worked great except that when the staging site was brought down the videos stopped working.

It turns out that JWPlayer for WordPress is using WordPress guids instead of using the wp_get_attachment_url() function that makes it safe to move your WordPress website between domains. In short, the guid column in the posts table stores the original URL of the video, and if you change domains, the only way to get the correct URL is to use the aforementioned function.

I wrote a little patch, notified LongTail Video, and it is on its way to being included in the plugin.

Project Pier & Kamp Pro 2 on GitHub

I’m working with and on the Project Pier project management software again.

A colleague who was working as a project manager recently left Tactica, and I saw this as an opportunity to do more project management myself, which is what I’m always looking for opportunities for.

This week was really exciting for my project management efforts, but it also means I have to play a little bit of catch up with the development projects at work, since the project management work I do takes away time from development.

You can check out my GitHub fork of Project Pier to follow my development or get the latest version to use it for your project management needs. If you find a bug or have an idea for how to make the system better, I’d love to hear about it, and if I feel it would make the system better for me, it’s likely I will have a patch for it shortly.

For my needs, the part of project pier needing most attention is the UI. The architecture seems solid, and the project management paradigm is quite close to the one Basecamp implements.

To address the UI issues without forcing my ideas into the core, I’ve enabled the themes to overwrite any output of the system (HTML & Javascript), whereas they were only able to overwrite CSS & images before. You can follow my UI changes on my GitHub repository of the Kamp Pro 2 theme developed by the talented Andrew Dotson.

First Blog Post at Canada’s Web Shop

My new employer, Canada’s Web Shop, encourages its employees to blog and tweet through the company’s blog and twitter accounts. They encourage everyone to tweet twice a week, and we take turns blogging weekly. Some people tweet daily, and blog once each week. There is an opening for another weekly blogger, since an employee who was blogging weekly left recently. Is this a good opportunity for me?

Recently, it was my turn to blog, and I wrote an article about PHP development support tools that I like to use.

Mai V2

Mai decided to refresh the look of her portfolio site, and created another clean and crisp design, ready to be implemented into her website.

Mai is a visual designer originally from Japan, currently living in the U.S.A. We met through ProgrammerMeetDesigner.com

I’ve created a WordPress-based site and developed a WordPress theme based on the PSDs she provided.

Technologies used:  PHP, HTML, CSS, JavaScript, jQuery, MySQL, WordPress.

Wordpress theme developed for MaiKSDesign.com
Wordpress theme developed for MaiKSDesign.com

Refactoring PHP

Here are some common opportunities for improving the maintainability of code through refactoring that I find when reading code.

  1. Replace Duplicated HTML with Iterating Over an Array

    The purpose of most PHP code is to output HTML that the web server will send back to the browser. If you have a table that has 20 rows, and all those rows have the same structure, but the data in each row is different, you could write it 2 ways:

    1. Duplicated HTML

           <tr>
             <td align="center" valign="middle" class="messageFormTd3">2010-05-04</td>
             <td align="center" valign="middle" class="messageFormTd3">Copenhagen</td>
             <td align="left" valign="top" class="messageFormTd3">City Hall</td>
             <td align="center" class="messageFormTd5">10:15</td>
           </tr>
           <tr>
             <td align="center" valign="middle" class="messageFormTd3">2010-05-02</td>
             <td align="center" valign="middle" class="messageFormTd3">Zagreb</td>
             <td align="left" valign="top" class="messageFormTd3">Main Square</td>
             <td align="center" class="messageFormTd5">12:30</td>
           </tr>
    2. Iterating Over an Array

                 <?php foreach (array(
                   array('date' => '2010-05-04', 'city' => 'Copenhagen', 'venue' => 'City Hall', 'time' => '10:15'),
                   array('date' => '2010-05-02', 'city' => 'Zagreb', 'venue' => 'Main Square', 'time' => '12:30'),
                 ) as $event) { ?>
                 <tr>
                   <td align="center" valign="middle" class="messageFormTd3"><?php echo $event['date'] ?></td>
                   <td align="center" valign="middle" class="messageFormTd3"><?php echo $event['city'] ?></td>
                   <td align="left" valign="top" class="messageFormTd3"><?php echo $event['venue'] ?></td>
                   <td align="center" class="messageFormTd5"><?php echo $event['time'] ?></td>
                 </tr>
                 <?php } ?>