View . files and directories in Netbeans

By default, Netbeans keeps dot files and directories hidden from the project tree. If you want to show them, never fear — there is a way.

Preferences > Miscellaneous > Files > Ignored Files Pattern

^(CVS|SCCS|vssver.?\.scc|#.*#|%.*%|_svn)$|~$|^\.(?!htaccess$)$

Basically, remove the .* at the end of the regular expression, and you’re good to go.

SLASH Architecture – My approach to building WordPress plugins

I’ve fallen into a routine when building WordPress plugins; a few general rules are:

  • Avoid creating new PHP globals.
  • Avoid executing PHP code in the global scope.
  • Generous use of Actions and Filters.

I’ve decided to name the pattern I use Slash, which stands for:

  • Singletons
  • Loaders
  • Actions
  • Screens
  • Handlers

Singletons

I didn’t love singletons in PHP at first, and I’m still not convinced they are ideal, but they work well at avoiding yet-another-WordPress-related Global variable. bbPress is a good example.

The benefit of using PHP singleton’s in WordPress is they don’t create an additional PHP global to worry about getting stomped. They also allow your plugin to always exist in memory, without another plugin being able to unset it, while still working like a traditional PHP class.

Loaders

These are basically bootstrap functions. Their only responsibility is to jumpstart a singleton, and put it in a place for easy access. See the bbpress() function in the above bbPress link. Loaders allow you to reference your Singleton without needing to use a global variable, or pass an instance around into functions and method calls. Used like: bbpress()->foo = 'bar';

Actions

By hooking everything into WordPress core actions, bbPress never runs any code inline in the global scope, other than the above loader function. Also, bbPress comes with it’s own sub-actions to piggyback WordPress’s, making writing bbPress specific plugins safe and simple.

This also includes WordPress Filters. The major difference with Filters is that they are generally more risky to use; you have to assume other plugins are already using them, and those same plugins aren’t designed to handle whatever you’re trying to do too.

Screens

Derived from BuddyPress, screens are basically “Views” if you’re familiar with MVC. They are how we output markup to the browser from inside PHP, WordPress, and our plugins. Screens can be modular (again, see bbPress) allowing them to work with shortcodes, widgets, and template parts. Screens typically contain all of the translatable strings and HTML markup, and sanitize any variables for output.

Handlers

Handlers are the equivalent of controllers in MVC. They are responsible for containing the logic that comes from requests like forms, AJAX, JSON, XML-RPC, etc… They “handle” whatever the request is, performing capability checks, validating input data, and also checking for nonces.

Why not use MVC?

Honestly? No reason. Slash isn’t intended to compete or replace anything, and like anything else it’s constantly evolved over time to become what it is today, and will likely change tomorrow too. MVC and other architectures work really well, and Slash is just an approach that’s worked well for me. Putting a name on the routine should help it grow, or educate me on better approaches.

It’s also worth noting that Slash isn’t really anything new, but rather an assembly of separate methodologies combined into a single process that helps me translate my thoughts into code.

The best way to see the Slash approach in action is to browse through the BuddyPress and bbPress codebases. If you’re an experienced developer, I’m always looking for feedback. If you’re just starting out, maybe give the Slash approach a try. Take what’s in bbPress and remix it for your own use, and let me know how it goes.

WordPress as an Environment

As WordPress has matured over the past few years, my perspective has shifted to think of it as the environment I develop in. I no longer really associate myself as being a PHP developer, a front-end or back-end developer, an architect, or a designer.

This both scares and delights me.

To be a good WordPress developer, it helps to understand how all of the skills come together to create the perspectives I just mentioned, and how they apply specifically to WordPress — far beyond the conventions of everyone’s favorite PHP stack.

  • Front-end WordPress development requires knowledge of WordPress’s theme options, template tags, template hierarchy, theme hierarchy, and action order.
  • Back-end WordPress development requires knowledge of WordPress’s object cache, action order, what filters to use when and why, when to use custom tables, and having a plan to scale beyond WordPress’s built in table schema.
  • Architecting for WordPress requires extensive knowledge of WordPress’s action order, WordPress’s included functions and APIs, the WordPress coding standards, and liberal use of phpdoc and inline documentation.
  • Designing WordPress themes requires an intimate knowledge of what WordPress is actually designed to do, and then being able to think outside of that box to create visually stunning sites that push WordPress to it’s limits.

Because of this, it’s safe to say WordPress is our environment now, and PHP is just the platform it runs on. WordPress is popular and complex enough now where it’s a great time to specialize on one area, and become the go-to person in that area. Taking this a step further, focusing on individual plugins or themes is actually where we are today.

Part of what makes being a WordPress developer so fun is being able to load-up a new installation and start creating new and amazing things in a matter of seconds. As WordPress evolves with smarter warnings, sandboxing of plugin activations, and doing_it_wrong() notices, we’re watching WordPress shape-shift from a bunch of PHP scripts on a server, into the environment we create, live inside of, build enhancements for, all while individually influencing it’s direction.

It’s at this point, WordPress and it’s community of contributors deserve much more recognition and thanks than they usually get.

Building an environment, is hard to do.

“WordPress as an Environment” is what comes next; a future where WordPress shields us from annoying things it can detect and protect us from, both as users and developers; an environment where WordPress can detect two plugins are trying to perform the same action, and safely prevent conflicts; one where several posts of different types will be allowed to have the same slug without colliding with each other. More over, I can’t wait until WordPress allows plugins to register template parts, so completely theme-agnostic features can be built with no additional effort. (BuddyPress, bbPress, Shopp, and WP eCommerce are making huge strides here.)

When you think of WordPress as an Environment, you realize how much we depend on WordPress core to protect us from ourselves and each other. A future where the correct safeguards are in place to help us not shoot our own feet or get caught in cross-fire is one I hugely look forward to.

Custom Plugin Header Image Label

Back in December of 2011, Matt and friends added the ability for WordPress plugins to have really pretty header images. For BuddyPress, I went through a few design iterations before settling on the header image pictured at the bottom of this post. I wanted it to be minimalistic and unique, so I took an hour to extend the label area with the buddies at the end. Below is the basic approach to make that happen:

  • Take a screen shot of the header image without the extended icon area.
  • Open that screen shot in Photoshop or your favorite image editor.
  • Make a new layer.
  • Fill the new layer with a black close to whatever the primary color of the label is. (#181818)
  • Hide that layer, select the background layer.
  • Magic wand the label.
  • Extend the selection to the size you want it to be (Usually 50px or so.)
  • Switch to your all black layer.
  • Right click; Select inverse; Delete.
  • Tweak the opacity of your black layer to match as closely as possible. Take your time with this; even if it’s the slightest bit off, it’s pretty noticeable.

Retina 2x downsampling

While working on some 2x retina images for WordPress.com, and the bbPress and WordPress open-source projects, I found an image rendering issue that I haven’t seen documented anywhere yet. Here’s the WordPress core retina ticket, for reference.

The first image highlights the difference between the WordPress core 2x icons, and the bbPress 2x icons. Notice how the icons next to Forums, Topics, and Replies have a slightly thicker black outline, specifically in 2x mode. The icons next to Posts, Pages, et all, are WordPress’s icon32 equivalents, with the same border thickness as the original 32px icons used in the 1x headers.

Using the original 32px icons was a great idea for a first-pass win at having 2x icons in WordPress core, and there are 64px equivalents now too! The difference between the WordPress and bbPress icons is subtle but important when you look at the second image in the gallery.

If the browser loads 2x images, but the display (for whatever reason) renders in 1x mode, you naturally end up with downsampled 2x images. To purposely duplicate this behavior:

  • Have a Retina MacBook Pro.
  • Connect Cinema Display.
  • Open Safari.
  • Move Safari 50% between the rMBP display, and the Cinema Display.
  • Watch any 2x images downsample to 1x size.

While edge case, the circumstances where a browsers’ calculated pixel ratio does not match the display are a new bug from a new convention. Arguably, operating systems and graphics cards should handle this more smoothly, and I suspect they will eventually. Until then, if the risk is providing a worse experience than plain-old 1x images, it’s our responsibility to include 2x images that will downsample to a usable state in 1x mode.

Weird, wild stuff!

Confessions of an Open Source Workaholic

Hi, my name is John, and I’m an Open Source Software workaholic. I touched on it a bit in my WPCandy interview, and I thought I’d finish the story here with a few added thoughts.

I live in a great neighborhood on the east side of Providence, RI. I work from home, rarely drive my car (ignore the frequent road trips), and enjoy the luxury of being walking distance from food, laundry, spirits, and anything else I might need to live a happy and comfortable life.

By day, I work for Automattic. I love my job. I love my colleagues. I love everything about what I do. To say it’s a dream job is an understatement. I work on some really awesome stuff going on around WordPress.com, Jetpack, Gravatar, and try to poke my head into other interesting social bits as much as possible.

By night, I’m the lead developer of bbPress, BuddyPress, and maintain both of the bbPress.org and BuddyPress.org sites. I believe both projects are two of the strongest spokes attached to the WordPress hub, and it’s my pleasure and privilege to be so closely involved with them. I am passionate about their success and enjoy iterating and improving them both equally, and love to help their users whenever I can.

That said, I’m in a unique and misunderstood position.

I work 40+ hours at a job that I love. Most days when I’m done with work I switch gears to my hobbies; usually that’s bbPress and BuddyPress. Other days, I enjoy going to the park with my dog Paul, watching Netflix, or enjoying a nice meal with friends.

In 2010 and 2011, I had the pleasure of mentoring some really bright individuals as part of the Google Summer of Code and the Google Code In projects. Gautam Gupta, a 15 year-old student from India, placed 6th by working closely with me contributing to the first major release of bbPress in two years; helping to totally refactor bbPress into a plugin for WordPress, skyrocket its popularity, and reinvigorate something great that hadn’t had much attention in a while.

My point, is that working on the bb’s is not something I am directly paid by Automattic to do. Instead, my job at Automattic enables me the means to keep my skills sharp *and* work on the software that I love, at the same time; it allows me to spend my free time giving as much back to the community as I am willing and able to. I choose to concentrate on bbPress and BuddyPress.

While Automattic does donate the time of several full-time people directly back into WordPress, and while it benefits Automattic as a business to be coupled so closely to its active development, it is not Automattic’s responsibility to staff anyone to contribute back to any open source project anymore than it is your own to do the same.

WordPress is free and open for anyone to build off of and dedicate resources towards. The bb’s are both free and open like WordPress is, with a lower barrier of entry to make a a much larger impact. If you’ve ever been intimidated by the amount of activity happening around the development of WordPress, or have been afraid your contributions aren’t good enough: 1. you’re wrong; 2. use the bb’s as your training ground.

If you choose to stick around and help work on the bb’s, your influence carries more weight because there are fewer people contributing. Dedicated contributors walk up the ranks quickly, earning core commit access like Boone Gorges, Paul Gibbs, and I with both BuddyPress and bbPress. We’re not the founding developers, we’re the currently active ones, and we would love to have your help. From code to codex, everything is an iterative work-in-progress.

Who knows, maybe eventually you’ll be an open source workaholic, too.

PHPUnit, MAMP Pro 2.0, Netbeans 7.1, OS X

At the time of this writing, MAMP Pro 2.0.5 comes with a corrupted pear.conf file for PHP version 5.3.6, so I had to do some digging to install PHPUnit. You should be able to open up terminal and safely run the following commands to get PHPUnit installed and working correctly:

rm /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf
/Applications/MAMP/bin/php/php5.3.6/bin/pear channel-update pear.php.net
/Applications/MAMP/bin/php/php5.3.6/bin/pear upgrade pear
/Applications/MAMP/bin/php/php5.3.6/bin/pear channel-discover pear.phpunit.de
/Applications/MAMP/bin/php/php5.3.6/bin/pear channel-discover pear.symfony-project.com
/Applications/MAMP/bin/php/php5.3.6/bin/pear install phpunit/PHPUnit

Now that it’s installed, give it a try and see if it responds:

/Applications/MAMP/bin/php/php5.3.6/bin/phpunit --version

To run phpunit directly:

mv /Applications/MAMP/bin/php/php5.3.6/bin/phpunit /usr/local/bin/phpunit

Note: *you may need to sudo to run the mv command, like so:

sudo mv /Applications/MAMP/bin/php/php5.3.6/bin/phpunit /usr/local/bin/phpunit

* after which you will be propted for you password

One last test for good measure:

phpunit --version

Great! You’ve successfully installed PHPUnit in OS X using pear bundled with MAMP Pro 2.0.5. What about Netbeans integration?

  1. Open Netbeans and visit your Preferences
  2. Select: PHP
  3. Select: Unit Testing
  4. Click: Browse
  5. Navigate to: /usr/local/bin/
  6. Select: phpunit

Boom. From here on in you’re all setup with Netbeans talking to PHPUnit safely installed via MAMP Pro’s pear. For more information on what Netbeans can do with PHPUnit, check out the knowledgebase page over at Netbeans.org.

Giving props is cool

I’m not really a business-man kind of guy. I’ve never really been able to wrap my head around the economic logistics of running a zillion dollar corporation, so I’ll preface this to say that I can’t really speak from that angle with first hand experience. What my perception of that kind of business is though, is cut-throat and viscous with a side of watch-your-back. Considering I’m generally a laid back, go with the flow kind of person (unless I’m sitting in traffic) it’s pretty natural and obvious that I’m just not cut out for that line of work.

What has worked pretty well for me though, is open source development. I think because it has that whole ‘pay it forward’ type of mentality to it… and because I get to prove myself everyday to my friends, my peers, and my clients and colleagues. It benefits not only me, but the people that I work and play with, to do a good job. I’m rewarded with natural thank-yous and random pats-on-the-back just for doing something that I would be doing anyhow, which lets me ‘make my own bed’ so to speak. It’s like having a commission based salary, except without the sales pitch and the getting ripped off by the sales guy.

I’m blessed and fortunate to be able to do what I do and be able to pay the bills with it. It’s a luxury that I’m not always sure I deserve yet, but I take advantage of the opportunities doing my best not to take them for granted any step of the way. Because of the WordPress community, I’ve met amazing people that I call my friends, even if we’ve physically met 3 times. I’ve gotten to work a lot on BuddyPress, and will be putting some efforts into bbPress now, all of which I’m happy and proud to be able to say that I am a small part of.

All of this, isn’t my doing.

If it wasn’t for the GPL, I wouldn’t have any of it. None of it would be possible.

If I wasn’t able to see other peoples work and reapply it for the task at hand, I would never have been able to learn LAMP development in the first place. The first thing I noticed is that open source developers are typically very generous, providing copious amounts of insight and example code with out asking for a penny in return. The general rule, of course, is that you credit the original author for their assistance, even if it was in a semi-anonymous fashion. I generally like to drop a comment in their blog if they have one thanking them for their help, but I digress…

This is all what made giving props cool.

Let me just say, that NOT crediting people for their help is usually uncool. I am of the opinion that anyone with a shred of moral fiber should thank the people that helped them get where they are. But in the open source development world, having a link in your footer to the engine that runs your site, is something you’re proud of; having a commented line of code inside yours that credits the original author is something you’re proud to do, and there’s a few reasons why I think that is:

  1. It shows you’re paying attention to other people and what their methods are.
  2. It shows that you respect them and their efforts.
  3. It lets the world know that you’re humble enough to thank the people that help you along the way.
  4. It proves that you can’t do it alone, and that you understand that no one expects you to.
  5. It goes a long way towards building good relationships and business practices.
  6. It means that when someone credits the hard work that you’ve done, you’ll get that warm, fuzzy feeling too.

I know that the GPL is a legal document that is meant to protect the rights and abilities of the developers that use it. Going back to the business-man thing, I can honestly say that in my beginnings (and sometimes even recently) I did not comprehend exactly what the GPL was or what it meant to believe in it as strongly as I do on this day. To me, today, the GPL is something that protects me and my rights as much as it is something that lets me safely distribute what I do for others to use, reuse, and share however they see fit in a respectable and ethical fashion.

The kicker about all this, is my feelings won’t be hurt if I don’t get ‘props’ even if it’s in the spirit of the GPL to provide them; even if it’s written in the license that you need to obey the original license. If I never get a thank you, and never get recognition for what I do, and my code shows up somewhere without a direct credit to me, I won’t even be mad… it isn’t something I need or want… but I will appreciate it. Like most things in life that can be appreciated, if they go totally unappreciated for too long… if they are used and abused to point of an obvious injustice being committed, be it moral, ethical, legal, or otherwise… there are and should be repercussions for that kind of behavior.

So… in short (but also very long), the GPL made props cool. It did that by giving everyone a perpetual and reciprocal way of helping each other get things done in a way that makes sure everyone is appreciated, everyone is treated fairly, and everyone gets recognized for their hard work and dedication. If you use a GPL licensed snippet of code, or an icon that someone has made available, or use open source software, by recognizing the hard work that went into those things, you’re silently appreciating and respecting the people that help make the internet awesome, and they do appreciate it. I know I do, and I appreciate all of you too. :D

The importance of a desk

A year ago this August, my girlfriend and I moved into our second place together. At our first place, I purchased us two very plain white tables from IKEA that we used as our L shaped shared office, and it worked out pretty well since we both use laptops as our primary machines and they don’t take up very much space. Once we moved into the new place (which is much nicer and fits the both of us better) I never got around to setting our workspace back up.

Instead, I confiscated the dining room area to use as my man space. On one end, proudly displayed are my turntables (Technics 1200 MKII’s + Rane SL57 + Serato, naturally) and on the other end I salvaged a friends TV stand and book shelf to use as my video game station. The space is awesome, it’s filled with toys and goodies, but I haven’t had much time since the move to actually use any of it.

Leading up to the point of this story… I’ve gone almost 1 calendar year without a desk at my home office, and it’s been a pretty bizarre experience. Using a laptop as my main (and only) development machine for the past 7 years or so, I’ve formed some bad habits like working from the couch, working from bed, and wanting to take my work with me everywhere I go.

These habits, are probably bad. I’d recommend avoiding them at most costs, if possible.

There’s something to be said for being able to work anywhere you want to… being able to lay down under a blanket, turn on some music, and get comfy on the couch with a good night of programming has been something I’ve taught myself to look forward to. But, it also makes me look and feel pretty retarded when the real world watches me, because what’s really happening is desecration of sacred relaxation space with the presence of work… all the time… everywhere I go.

So in the corner of our bedroom has sat one of those old tables I got from IKEA so long ago, having been converted from a respectable desk into an elevated clothes hamper for shirts and pants that just aren’t dirty enough to actually make it into the hamper itself, but still need a place to say to the world “I have been worn at least one time since I’ve been removed from the closet.” Jess was out-of-town no more than 3 hours by the time I decided to start nesting my work area again.

Couldn’t be happier so far.

Having a desk, if you don’t have one, makes work feel like a place where you can sit down to get stuff done, and then disconnect from it when you’re not there. I know it sounds really silly to say out loud, and probably even more silly to read since it’s such an obvious necessity in life, but it’s true at least for me. The past few days I’ve probably been more productive with my time than I have in a long while, both in part because my work space inspires my brain to click into ‘work mode’ and because I’m able to keep work where it belongs, and use the couch for what it’s really for… Napping.

I think especially when you work from home, being in a “work space” means people will more than likely not interrupt you when you’re working because you’re not just lounging on the couch or in a cushy chair trying to not glance over at reruns of Grey’s Anatomy. Not that I was sad when George died or anything… Just saying…

So, if you don’t have a desk, and you work from home, you should spend the $50 and buy a table from IKEA and set yourself a nice little spot in a corner somewhere. I think you’ll be glad you did.

I also think my next project is tricking out my desk with a rad external monitor swing-arm, and finding a nice iPhone and iPad charging dock to keep things nice and tidy.

TortoiseSVN and Windows 7, and how I made them play nice

I’ve been pulling my hair out for weeks with TortoiseSVN ever since I updated to Windows 7, and boy has it been a giant pain in the ass. Sometimes updates and check-outs worked, sometimes not. Sometimes I could commit, sometimes not. Sometimes the icons appeared, sometimes not. I’ve tried reinstalling TortoiseSVN, I’ve tried registry hacks, I’ve tried everything that Google told me to try and still no joy…

Here’s my setup, and here’s what fixed it…

Windows 7 Ultimate 64
TortoiseSVN 1.6.6
Netbeans 6.8
BitDefender2010

Wait… BitDefender? Why does that matter? Honestly, I have no idea… But switching off the firewall and real time protection, doing my updates, and turning them back on fixed my checkout/update/commit issues.

How did I figure this out?

In an act of desperation I booted my machine up in Safe Mode + Networking (most of you probably already know how to do this, if not let me help you.) Safe Mode + Networking loads Windows up in a bare bones environment plus allows internet access (but still used 800MB of RAM in my case, blech…)

Anyhow, I noticed right off the bat that BitDefender wasn’t running, and everything worked perfectly. A quick reboot back to reality, and disabling my anti-virus and TortoiseSVN was good-to-go. Well, almost… The icons are still screwy, and for me the only ones that appear in the file area are the changed ones. No green check boxes for me, but at least I can see changed files.

So for everyone out there that’s about to have a stroke this holiday season from not being able to commit code changes on time, try disabling your anti-virus and firewall before admitting total defeat and see if it helps.

I wonder how long it takes for self-inflicted bald spots to fill back in… Hmm…