Title: Instantiate a plugin class in theme
Last modified: August 21, 2016

---

# Instantiate a plugin class in theme

 *  [ColinD](https://wordpress.org/support/users/colind/)
 * (@colind)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/instantiate-a-plugin-class-in-theme/)
 * I’m trying to create a new instance of a plugin class from my theme and make 
   that globally available but its not working.
 * I modified a 5-star rating plugin to interact with a custom theme I’ve written.
   It no longer makes sense to have them separate. The plugin functionality should
   be rolled into the theme.
 * So I took the plugin and relocated it to
    wp-content/themes/mytheme/plugins/custom-
   5-star/
 * I then added
    `include_once('plugins/custom-5-star/custom-5-star.php');` in the
   theme’s functions.php.
 * custom-5-star.php is the standard plugin class definition follow by
    `$custom_star
   = new CustomStar();`
 * But if I do
    `global $custom_star; print_r($custom_star);` in functions.php or
   a template file I get null.
 * If I do
    `$custom_star = new CustomStar(); print_r($custom_star);` in functions.
   php or a template file it works fine. But seems likely to cause performance issues.
 * Do I need to instantiate my new plugin class at a different point in the WP execution?

The topic ‘Instantiate a plugin class in theme’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [ColinD](https://wordpress.org/support/users/colind/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/instantiate-a-plugin-class-in-theme/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
