A few weeks ago we were at WordCamp Barcelona, where we talked to some of our colleagues and friends. As you may recall, we had the chance to share our experience in WordPress through 3 different talks. For those of you who couldn’t come to Barcelona during those days, I thought it’d be interesting to reproduce the contents of our talks. Today I’ll reproduce mine (which, spoiler alert, happens to be the best ?) here, but stay tuned for Ruth’s and Toni’s, which they’ll publish during the next few days!

Cómo haer el mal siendo desarrollador WordPress - WC Barcelona 2016
Cover slide of my presentation “Cómo hacer el mal siendo desarrollador WordPress” (How to Become an Evil WordPress Developer) at WordCamp Barcelona 2016.

How to Become an Evil WordPress Developer – Sinopsis

Most of the talks you can attend teach you how to be better—better developer, better blogger, better entrepreneur, better professional. But, who cares? Do we really want to be “better”? If your dream is to become evil, this is your talk. Here you’ll learn some of the most useful tips and tricks that’ll make your plugin the best while, at the same time, break your competitors’ and make them look ugly. Focus only on delivering the best user experience to your customers (who, by the way, are the ones who pay your salary), and don’t even think about being nice to other developers!

The World Has Gone Mad!

Have you looked around you lately? World’s completely crazy! And no, I’m not talking about president Donald J. Trump (someone who deserves a whole post about him)—I’m talking about our peers and, especially, what’s going on in the technological world.

Since the first PDAs came out, followed by iPhone’s first release in 2007, it looks like we’re super interested in making things smart. We want our phones to be smart, our TVs, our watches, our refrigerators… everything has to be smart. Except people, of course—they can be as dumb as ever.

In my opinion, there’s plenty of examples of stupid smart things targeted at stupid customers. Smart underwear, smart socks that never loose their partner, smart vessels, smart diapers that tweet when your baby peed itself! WTF?!

Let your sock don’t lose its partner sock! Keep them paired! Picture by Blacksocks.

I used to think all this technological madness didn’t affect WorPress developers. We’re above this worldliness—we’re interested in important stuff solely! The REST API, good support, customer care, making WooCommerce great again… we’re perfect beings focused on relevant tasks.

Well, as it turns out, I was completely wrong. WordPress developers are no better than anybody else—they get things wrong and they can even do evil stuff. On purpose. Remember these lines: WordPress developers are dangerous! Trust none!

WordPress Developers Are Dangerous

A few months ago I described a problem we had with our new plugin, Nelio Content. Basically, this is what happened: one of our users opened a support ticket complaining because he couldn’t see the plugin as it appeared in our screenshots:

Screenshot of Nelio Content's Dialog for Adding new Social Messages
Screenshot of Nelio Content‘s Dialog for adding new social messages.

That’s what he saw instead (what a mess!):

Broken Dialog because of a Third-Party Plugin
Nelio Content’s Dialog is rendered completely unusable because of an incompatibility issue with a third-party plugin.

That was completely unusable! After investigating the problem and studying what the hell was going on, we discovered that the offender was another plugin. In Nelio we are super nice people, that’s why we decided to get in touch with the developer of the other plugin and explain not only the problem that we found, but also how to fix it. As you can see in the previous link, we tried to contact him/her almost 5 months ago and … well, we’re still unanswered. The feeling that remained after that silence was similar to this:

Falta en un partido de fútbol femenino
WordPress developers, like in soccer, also know how to play dirty when necessary. Picture by joshjdss (source).

It always makes us proud to talk about the WordPress community, to say that we are all friends and we help each other… but when a problem like this happens –a problem that can cause your customers to leave away from you– the only thing that I got from that community (or, better said, from that soulless developer) was silence.

Not anymore! ?

Best Worst Practices to Do Evil Things

After that bad experience, I decided to explore the dark side and be the one who makes the wrong things to end up breaking the plugins and themes of others. After all, if they can do it, why shouldn’t I?

If you want to be good at something you must learn from the best, and that’s what I did. For a few days, I reviewed all the support tickets I had received over the last few years and collected the reasons causing the errors for which our customers had contacted us. I got a good list of tricks and “good bad” practices with which to do evil on my own. These are the three easiest tips to implement and that will work best for you, little monster.

#1. Use CSS Viciously

If you’ve read the previous post where I explained the problem we had with Nelio Content and the other plugin, you know that it was all due to misuse of CSS stylesheets. As you know, the appearance of the components we add to an HTML page is defined through CSS styles. If someone modifies those styles, overriding the rules that come by default in WordPress or those that others have defined, you can break the appearance of the components that used those styles. For example, the problem that made Nelio Content look ugly was (in part) generated by the following CSS rules:

Using a global style reset, we make an HTML node to have the default properties we want. In this example, the damage is maximum because it applies a totally global reset. Note that you are not only resetting all span or div tags. No! Those rules are completely resetting all tags (and even some pseudo-elements) using the selectors :before, :after and *.

The next thing you can do if you want to guarantee the destruction of other plugins is to use CSS classes with generic names and specify the rules that suit you. If you’re a good person, your CSS rules most likely include some type of prefix so that they only affect the elements you’ve added. So, for example, if you want to define a “column” somewhere in your plugin, instead of using the column class you would use something like nc-column, where nc- is the prefix of your plugin (Nelio Content, in our case). But, of course, here we are not talking about doing things right, we want to blow up everything, so let’s use generic rules:

If you use generic names, you risk having another developer add their own rules after you and that these ones override yours. Avoid this with the !important directive:

And to be even a worse developer, follow the advice that Dario Balbontin gave me. Be sure to set Comic Sans everywhere:

Doing this you go straight to hell… but there you’ll become the bro of Lucifer!

#2. Cheat with JavaScript

Another element that we can modify with relative ease to harm others are the JavaScripts. There are many things we can do with them, but it is about being subtle when it comes to doing evil; Make our intentions not too noticeable. What can we do here? Very simple! First of all, forget about the usual way of adding scripts in WordPress:

The best thing you can do (especially if you’re a theme developer) is to include the scripts directly into the page, typing the script tag inside the HTML and forgetting about the crap that WordPress requires. Also, I don’t know if you know that WordPress includes a lot of scripts that you can use. In addition to the well-known jQuery, there are several libraries like jQuery UI, Backbone, underscore,… ready to be used by any developer. Well, don’t waste your time looking at what WordPress offers; when you need anything, pack it in your own plugin and ignore the old and outdated versions that are in WordPress:

Even better, suppose you’re going to use the latest version of jQuery, which is the most cool. Why are you allowing other plugins to enqueue the default version of jQuery? Best thing is to make sure that version is not available using the wp_deregister_script function that includes WordPress:

By doing so, we make sure that the WordPress version of jQuery does not collide with yours. Okay, okay, we agree that doing this will cause all other plugins that depend on jQuery to fail, since jQuery will no longer appear as available (you just deleted it). But… who cares? It’s all about doing evil, remember?

Our Nelio Content plugin depends on several scripts. As you can see, one of the requirements is jQuery. If we remove it from the list of available scripts... Nelio Content would not work! I love doing evil...
Our Nelio Content plugin depends on several scripts. As you can see, one of the requirements is jQuery. If we remove it from the list of available scripts… Nelio Content would not work! I love doing evil…

#3. Expand Your Evilness

Finally, my last tip today is that you apply the previous tricks on as many pages as possible. For example, it is quite common for plugins to define their own admin pages. Some examples admin pages of Nelio Content could be the settings page or the editorial calendar:

Editorial Calendar in Nelio Content
Editorial Calendar. The Editorial Calendar shows all your published and scheduled posts, as well as other elements related to your marketing strategy.

Usually, you only add the scripts and styles that these pages need when the user is visiting them, and avoid adding them when users are in other locations:

But, of course, let’s not forget that we are trying to harm other developers work, so better don’t add any control on this. If you don’t worry about adding these controls, your productivity at work will escalate, since you will no longer have to waste time writing code that “prevents” your things from appearing on other people’s pages.

In Summary

Doing things wrong in WordPress is very simple. All you have to do is to ignore the guidelines and do everything as you want, without worrying at all about the consequences of your actions. So, remember:

  • write CSS rules in the most general way you can,
  • include scripts without WordPress complexities (forget about registering, enqueuing or specifying dependencies…),
  • and try to do all of this on as many WordPress pages as possible.

For things to go well, all developers need to be good people and act by following the WordPress rules. But doing evil is so easy and tempting…

By the way, notice the irony throughout the whole article. Please, follow the style guidelines and WordPress rules! Seriously, don’t be evil developers!

Featured image by Charles Rodstrom.

2 responses to “How to Become an Evil WordPress Developer”

  1. Collins Agbonghama Avatar

    Great post David. I admit to enqueuing my plugin js and css files without first checking if the current page is one of my plugin settings page. However to mitigate against conflict with other plugins, all css and js code are uniquely namespaced.

    1. David Aguilera Avatar

      Thanks for commenting Collins! Namespacing your plugins is a great solution and I’d expect it to prevent all common compatibility issues from occurring. Nonetheless, I’d also recommend you check you enqueue your scripts/styles when you need them — even if there aren’t any compat. issues, reducing the number of scripts/styles to process is nice 😉

Leave a Reply

Your email address will not be published. Required fields are marked *

I have read and agree to the Nelio Software Privacy Policy

Your personal data will be located on SiteGround and will be treated by Nelio Software with the sole purpose of publishing this comment here. The legitimation is carried out through your express consent. Contact us to access, rectify, limit, or delete your data.