Tag: WordPress

  • Calling Constructors

    Take a look at this code, found inside the Jetpack Post Views plugin: function Jetpack_Post_Views() { $this->__construct(); } Here an object is calling its own constructor. But what’s wrong with it? The General rule for calling __construct: The only occasion it is okay to call a constructor method directly, is in a child class that…

  • Use of mysql_connect in WordPress

  • &$this

    Take a look at this code, found inside a PHP class or object: add_action( &$this, ‘functionname’ ); This looks familiar, and can be found in many themes and plugins. But what’s wrong with it? It’s PHP4 code in a PHP5 world. General PHP rule for add_action: When creating a callable, never use &$this, use $this instead…

  • Code For The People

    I’m now working for Code For The People! As a WordPress developer, I’ll be working on a lot of new projects as I did at Interconnect/IT, but without an office to visit everyday. I’ll be swapping The Spectator and University of Nottingham Blogs, for Stephen Fry and The Rolling Stones. This does mean that Interconnect/IT are…

  • ComposerPress

    Curious about Composer but already have a WordPress site? Not to worry, I have you covered. Presenting Composerpress: Composerpress is a plugin that analyses your WordPress install, and generates a composer.json file you can then use retro-actively. This file acts as an inventory of dependencies, plugins, etc that are needed to set up a site, and…

  • add_action considered harmful

    I’m going to argue that add_action is actually a more elaborate version of goto hidden in  plain sight, an anti-pattern, that it encourages unstructured programming, and obscures dependencies between code by providing the illusion of structured code, and encouraging spaghetti architecture. The Dangers of Goto Firstly what is a goto statement? goto (GOTO, GO TO or other case combinations,…

  • Creating Objects on Hooks/Actions

    Lets say we had a class that set up some important things. These things needed to be added on the admin_init hook, and they were done in our classes constructor. How would we create our object so they get set up on the admin_init hook? View the code on Gist. Some people may try to…

  • WP_Query::get_posts()

    Every call to retrieve posts goes through WP_Query, and the bulk of the logic is in the method get_posts. Here’s some potentially useful information about the current state of what is arguably the most important function in WordPress. WP_Query::get_posts is 890 lines long, and has a cyclomatic complexity of 256. A good cyclomatic complexity is ~2-6,…

  • Alternative Post Loops

    We all know the standard post loop in every template, but what if we did something slightly different? Lets begin with the standard main loop we all know: View the code on Gist. There’s a lot of boilerplate there, what if we could reduce it down? Lets try using a feature of PHP 5 called…

  • Content Without Posts

    I’m going to demonstrate how to have a URL with content in WordPress that’s neither a post, page, or listing. Its contents can be anything you’d like! To do this we need to take the following steps: Add a custom query variable Add a rewrite rule that uses the new query variable On the template_redirect…

  • WordCamp Lancaster 2013

    I’m at WordCamp Lancaster, and I’ve given two talks. Here are my slides, and a selection of photos taken! A big shout out to: Chris Witham for lending me a VGA adaptor Jenny Wong for organising the massive Pizza order Marko Heijnen for another VGA adaptor Code Deodorant How to determine code quality by scientific…

  • Bulk Entry Plugin Release

    I’ve released a new plugin for bulk creation of posts! Other plugins on the wordpress.org repository handled a strict subset of functionality such as posts and categories ( but not pages or tags), while others simply didn’t work. I set out to build an alternative that was extendable, reliable, and could handle custom post types…

  • Clients Who Upload Huge Photos & Decompression Bombs

    Sometimes a client makes a blog post, and puts a photo in the middle. All good so far, until you realise the client has dragged an image from their brand new camera expecting a 10 Megapixel image to work. This is usually when people start talking about upload max file size limits, but this is…

  • Realisations

    Some pretty simple things people don’t realise when dealing with WordPress Nobody Remembers the API A lot of people worry that they don’t know the API, that it will take them a long time to memorise everything. Nobody memorises the API. It changes too fast, it’s too big, and it’s a waste of time when…

  • WordPress: Necessary Reading

    WordPress APIs In brief, WordPress hooks enable you to change how WordPress behaves without editing any core files. Because you leave the WordPress files untouched, you can painlessly upgrade your blog with each new version of WordPress. It’s this hooks architecture that makes WordPress the best blogging solution. – Adam Brown Adam Browns Hooks &…

  • WordPress Foundation & The GPL Issue

    There’s a problem that the WordPress Foundation & Core Team face, that puts them in unusual and awkward situations. It centers around a long running debate over the GPL and linking. A prime example being the recent situation of Jake Caputo: I've been blackballed from WordCamps: http://t.co/7vmV52Db — Jake Caputo (@jakecaputo) January 22, 2013 So…

  • WordPress 3.5-ness & what’s new

    I gave a talk at SWIG, an event ran by our company every last Thursday of the month. I talked about what changed and what’s new in WordPress v3.5, everything from what the usual blogposts cover and what hasn’t been covered but might affect developers. I’ve uploaded the slides to Slideshare, you can view them…

  • WordPress Flow Charts & Diagrams

    There’s a number of WordPress flow charts and diagrams in the community, to which the phrase worth their own weight in gold does no justice. For that adage to be true these charts would be so dense no light would reach them, rendering them utterly useless. So I’ve gathered a few of the more notable…

  • Tracking WordPress Site Updates Install in Google-Docs

    It’s important to keep WordPress up to date, but keeping track of all your sites can be a struggle. I recently had to list and check every site for updates, but I couldn’t use a service such as WP Remote. It had to be locally or private hosted. So I turned to Google Docs! Here…

  • WordPress Related Posts & Insanity

    I see a lot of attempts to do Related Posts using WordPress plugins. However, a lot of these plugins are attempting to automate the process by comparing content. This is madness. It’s: Error prone Slow Unreliable It’s also overlooking the glaringly obvious. Related posts are posts that are about the same or similar thing. We…