Title: Object Oriented Plugin
Last modified: August 20, 2016

---

# Object Oriented Plugin

 *  [wright_jamie](https://wordpress.org/support/users/wright_jamie/)
 * (@wright_jamie)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/object-oriented-plugin/)
 * Hi,
 * 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
               unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
               //Other WordPress News Feed
               unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
               //Quick Press Form
               unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
               //Plugins - Popular, New and Recently updated WordPress Plugins
               unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
           }
   
           // Add custom excerpt length
           public function custom_excerpt_length($length)
           { return 55; }
       }
       $foo = new OOtest;
       ?>
       ```
   

The topic ‘Object Oriented Plugin’ is closed to new replies.

## Tags

 * [action](https://wordpress.org/support/topic-tag/action/)
 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [object oriented](https://wordpress.org/support/topic-tag/object-oriented/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [wright_jamie](https://wordpress.org/support/users/wright_jamie/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/object-oriented-plugin/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
