×
Portfolio Blog Sahaja Contact
Tony O'Rourke

How WordPress won the web (but may lose it)

Instead of looking down at WordPress (OMG, is PHP a real language?), why not look at things empirically and examine what exactly made WordPress so successful? What decisions about its design and architecture led it to gain such traction on the web?

WordPress won the web

Isn't it the plugins?

While the plugin architecture is clearly a contributor to WordPress' success, I think there is something deeper at play here. The plugins themselves are so powerful because of another feature of WordPress that makes it a real tour-de-force.

Extensibity Points

The long-term success of a platform depends on how it can be extended and how safely it can be extended. By 'safe' I mean can be upgraded without breaking stuff. In this regard the WordPress 'hook and filter' system is an extremely powerful and effective system of managing change that surely goes unappreciated from the non WordPress developer community.

A Filter Example in Gravity Forms

Hooks and filters are extension points that allow modification of the behavior of WordPress or a plugin without the need to modify core code, of either WordPress or the plugin that supplies the hook. The plugin or framework author provides 'hooks' at different points in the page lifecycle and then the 'consumer' of the hook (e.g. developer) can tap into these lifecycle events to change behavior. I've done a lot of customizations of Gravity Forms, so I will use that as an example. The plugin authors have created a 'prerender' hook that allows developers to tap into the value of the form at the stage in its lifecycle just before it renders. So this is an example of 'core' code that doesn't change, but allows others to tap into.

    
		//Fired right before the form rendering process. Allow users to manipulate the form object before it gets displayed in the front end
		$form = gf_apply_filters( array( 'gform_pre_render', $form_id ), $form, $ajax, $field_values );
 

As a consumer of the hook or filter, one has to register a function or method that will get called at the time the filter is applied. The example below is using the 'method syntax' ( as opposed to the simpler 'function syntax').

    
     add_filter("gform_pre_render",  array('MyClass', 'preRender'));
    

And then the custom code that actually gets executed at the 'prerender' stage of the form. Notice that the $form object, with any modifications made by the custom code, gets returned from the function. This way the calling 'core' code can continue its processing as needed, but it has allowed the values of the $form object to be changed.

    
        public static function preRender( $form ) {

            //do whatever is needed to modify the $form object that is passed into the filter

            foreach ( $form['fields'] as &$field ) {
            ...
            }
            //return the modified $form object passed in as a parameter
            return $form;
        }
    

I have found this to be a very powerful mechanism to provide custom functionality while leveraging a lot of the built in functionality that Gravity Forms provides. In general this is how WordPress as a platform has allowed for so much customization and extension without blocking upgrades and increases functionality without requiring any modifictions to 'core'.

But can WordPress lose this advantage?

With Gutenberg WordPress has changed its emphasis to the front end editor experience. The "hook and filter" extensibility is still deep in the DNA of WordPress but is no longer the main emphasis. Of course the web continues to evolve, and the rise of headless content managements systems and static site generators seem to be the direction the web is going. Doubtless WordPress with Gutenburg will play a large role especially for brochure style sites, but it is not clear if WordPress is being true to its roots of easy and safe extensibility.