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

I'm trying to develop my WordPress skills a little. I've previously moved some of my functions.php that I use time and time again into a must-use plugin. I'm now trying to make that Object Oriented - with limited success. The code below is an excerpt of my overall code. The first section works perfectly, reducing the excerpt length, but the dashboard tidy doesn't. Both previously worked as procedural code.

Any help in solving this would really be appreciated. Also, I'm struggling to understand why it is recommended to use the init rather than putting my actions and filters into the constructor. Can anyone explain this for me?

class OOtest
    public function __construct()
        add_action( 'wp', array( $this, 'init' ) );

    public function init()
        //Tidy up the dashboard
        add_action('wp_dashboard_setup', array( $this, 'tidy_dashboard') );

        //Edit excerpt length
        add_filter('excerpt_length', array( $this,  'custom_excerpt_length') );

    public function tidy_dashboard()
        global $wp_meta_boxes, $current_user;

        // remove incoming links info for authors or editors
        if(in_array('author', $current_user->roles) || in_array('editor', $current_user->roles))
            unset($wp_meta_boxes['dashboard']['normal ']['core']['dashboard_incoming_links']);

        // remove the plugins info and news feeds for everyone
        //Wordpress Development Blog Feed
        //Other WordPress News Feed
        //Quick Press Form
        //Plugins - Popular, New and Recently updated WordPress Plugins

    // Add custom excerpt length
    public function custom_excerpt_length($length)
    { return 55; }
$foo = new OOtest;
share|improve this question
up vote 1 down vote accepted


add_action('wp_dashboard_setup', array( $this, 'tidy_dashboard') );

is getting added on the wp action, which is too late. Hook it to admin_init or in your constructor.

share|improve this answer
Really excellent, thank you. Can you explain why it is better to use an 'init' function rather than the constructor? – Jamie Wright Jan 12 '13 at 21:27

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.