Posted on

11 Ways NOT to write a WordPress Plugin

Sharing is caring!

I’ve been tinkering with WordPress, blogging, and Web Development on and off for the past 15 years. I would start it and then stop it. Never really sure where to go or what to do.

This past school year I created a WordPress site for use with my classroom and pioneered some WordPress features in an educational context, such as WordPress Hunts to analyze points-of-view and Web Quests, where I provide a list of links in a post for students to visit with questions at the bottom for students to answer.

During the summer I’ve been working on improving my WordPress and web development skills. I’ve really enjoyed the feedback from members of the WP community. Though, after speaking with a friend she suggested I try to make a WordPress plugin. I’m familiar with HTML/CSS and get the gist of PHP so I thought I might take a shot at.

While there are many websites that offer tutorials on how to write a plugin (for people at ALL levels: beginner to advanced) NONE of them (at least to my knowledge) offer a tutorial on HOW NOT to write a plugin.

Here 11 ways NOT to write a WordPress plugin:

11. Your plugin only works if you turn it on (activate it).

One does not

10. One Book to Rule Them All: For those who are not familiar with HTML/CSS or PHP pick one book.  Too many reference books on the same subject results in paralysis by analysis. Best to choose one book and stick with it as a reference. You can find a lot of reference materials online BUT the audience may not be written at level you need.

OMG too many choices!
OMG too many choices!
One choice is better
One choice is better

I also have a copy of: Professional WordPress Plugin Development

9. Code that you copy off the WordPress codex needs changes in order for it work:

echo '"' . plugins_url( 'images/wordpress.png' , __FILE__ ) . '" > ';

In the above code, I mistakenly thought I could just cut and paste and put it in my plugin. Nope.

8. Code you copy off the WordPress may not need changes in order for it work:

echo '"' . plugins_url( 'images/wordpress.png' , __FILE__ ) . '" > ';

In the above code, I mistakenly thought I needed to put my file path between the first double- quote (“) and the second single-quote (‘). After all, that is what you do in HTML. For example:

echo ‘<img src=”file path name here‘ . plugins_url ( ‘images/wordpress.png’, __FILE__) . ‘ “

It wasn’t until I interpreted the quote-scheme that I figured out that nothing goes there. Instead it should be:

echo ‘<img src=”‘ . plugins_url ( ‘file path name here‘, __FILE__) . ‘ “

Of course this is how I felt after I figured that out:


 7.  These are not variables you can function or echo. These are WordPress variables that WordPress puts in that it expects YOU to change so that you can function or echo them.

php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ); ?>

$parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function;   <======All these are what you change to YOUR variables.

6. Not all WordPress plugin tutorials are the same. Most tutorials are just lines of text, no video or explanation. Pippin Williamson of Pippins Plugins has an great Plugin Development 101 product that includes screencasts and explanations of what happens. It is designed for plugin beginners who have some knowledge of HTML/CSS and PHP.

5. The text editor that comes default with either Macs or Windows is awful. It lacks a visibility function which makes it hard to edit. I found that Sublime Text Editor is a much better piece of software that colorizes different aspects of your code to demonstrate which parts are working.

4. Writing the plugin script does not mean your done.

Not sure if

WordPress requires other ancillary materials such as screenshots, folders, and especially a readme. Fortunately, WordPress offers a Readme Validator that can be used to see analyze your Readme.txt file to see if meets submission requirements.

WordPress also requires you get approval after you submit and once you do get approved WordPress sends you a directory link to where you send your file to. WordPress uses Subversion and in order for you to access it you need to download a copy:

PC/Windows can use: TortiseSVN

Macs can use: SC Plugin     and click on “Installation” and then on the newest version which appears to be: “SCPlugin-0.8.2-SVN.1.6.5.dmg”.

I found a nice tutorial on how to install SC Plugin Here ; and used this tutorial on TortiseSVN as a general idea on how to use SC Plugin.

In using SC Plugin: I downloaded it, installed it, and then restarted my computer; Right-clicked on the SC Plugin Icon; Clicked on ‘Checkout’; put my WordPress directory link (that was emailed to me) in the URL of Repository box (at the top) and used the “Browse” button (at the bottom) to find the location of my plugin folder. I kept everything else the same and hit Ok. Another box popped-up, connected to the WordPress Repository, and told me that it was done. I then closed the pop-up box and that was that.

3. Copying and pasting code off the net sometimes just does not work. You end-up with whitespace, margin-misalignment, and other characters you don’t want.

2.  You cannot name the file “yourfilename.php” and expect to work in PHP. You need to specify

1. Specifying php at the top does not take a space:

php is GOOD because it does not have a space between the “?” and  “php”

<? php is BAD because it does have a space.

To paraphrase an Edison quote “I learned 11 ways NOT to write a plugin and 1 way how”

The plugin I wrote can be found on the WordPress Plugin site or at Willie and Joe Studios. The plugin itself is rather simple (it displays a Dr. Who theme upon a user login failure) BUT it demonstrates how I took existing plugin information, applied in a different context, and created something brand new. In doing so, I learned the WordPress plugin process from start to finish.