• 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.