WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I restrict my theme framework to 5.4+ (min 5.4) php how much of the average community am I cutting out? All just so I can use traits to help with some inheritance issues I ran into in this question I asked.

I am concerned that if I take the trait approach, close to 70% or higher of the community will be cut out. As most free hosting sites or "shared hosting" do not upgrade their php on a "omg 5.5.x is out lets upgrade" basis.

share|improve this question
up vote 3 down vote accepted

In contrast to Ben, I think you can use traits if you have to. Make sure to check for PHP version during plugin installation. Do not let your users run into some obscure PHP errors.

And don't look at the wp.org stats too long. The version stats include abandoned installations which don't matter for new plugins. Only 15% are actually kept up to date. The old sites influence the statistics heavily.


Traits are rarely the proper solution for an architectural problem. If you need access to the same methods in multiple objects, use dependency injection and/or a factory.

A very simple example: Let's say you need access to to the header data of your plugin in multiple classes. You could use a trait for that. But you shouldn't. It is better to separate this out and create a new class.

interface Plugin_Info_Interface
    public function set_file( $plugin_file );

    public function __get( $name );
class Plugin_Info implements Plugin_Info_Interface
    protected $plugin_file, $data = array();

    public function set_file( $plugin_file )
        $this->plugin_file = $plugin_file;

    public function __get( $name )
        if ( isset ( $this->data[ $name ] ) )
            return $this->data[ $name ];

        $this->data = array_merge( 
            get_file_data( $this->plugin_file, array( $name ) ) 

        if ( isset ( $this->data[ $name ] ) )
            return $this->data[ $name ];

        return '';

And now, in a class for extra information in the plugin list table you just use an instance of this separate class to get the data:

class Plugin_Table_Extra
    protected $plugin_info;

    public function set_header_data( Plugin_Info_Interface $plugin_info )
        $this->plugin_info = $plugin_info;

    public function show_git_repo()
        $repo_url = $this->plugin_info->repo_url;

        if ( empty ( $repo_url ) )

        // create a link

Easier to read, to test and to keep backwards compatible.

share|improve this answer
I built a mixin class instead which uses my new concept of "the bridge" ill accept your answer for others who might find this useful. – TheWebs Oct 10 '13 at 14:24

The official requirements for WordPress call for PHP 5.2.4 or greater. When I create a plugin or theme, I make sure it works on 5.2.4.

By using traits and restricting your users to PHP 5.4+, you are eliminating about 94% of the installed WordPress base.
enter image description here

When you distribute your theme or plugin, there is no mechanism on WordPress.org to specify a minimum PHP version; it is assumed that your minimum requirements are the same as WordPress. Therefore, if your theme is on WordPress.org, PHP 5.2 users will be able to install and activate your theme, crash their sites, then come to you for support. And not everyone is able to simply update their PHP installation.

share|improve this answer
Do you have any links to back up your statistics of how many users I will lock out? – TheWebs Oct 7 '13 at 19:53
@TheWebs Yes, the link is already there. Click on the 94% number in my answer. – Ben Miller Oct 7 '13 at 19:54
Oh Sorry I didnt see that – TheWebs Oct 7 '13 at 19:56
Looks like ill be using mixins then – TheWebs Oct 7 '13 at 19:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.