• Salih K

    (@salihkulangara)


    I am trying to extend a class that is inside a plugin from my theme, but if I check the class to be extended with if(class_exists('Hello_Class')) I can see the class is not available. The plugin structure is something like this:

    ` class PluginCore {
    public static $info;

    function __construct() {
    add_action( ‘after_setup_theme’, array( $this, ‘after_setup_theme’ ), 12 );
    }

    function after_setup_theme() {
    // the class I want extend
    require_once ‘/Hello_Class.php’;
    }

    }
    new PluginCore();`

    I want to extend the class “Hello_Class”, I tried to get this work using hook like after_setup_theme and init, but nothing works. Is there a way to make this work.

    • This topic was modified 5 years, 4 months ago by Salih K.
Viewing 1 replies (of 1 total)
  • Use the after_setup_theme action for yours, but make sure the priority is a bigger number than the theme.

    Plugins are loaded first, and then the theme. But the functions hooked to actions are run in the order of the priority argument.
    Also, if a file is required inside a function, it has the scope of that function. So you might want to require the file outside of a function, but don’t execute anything until the after_setup_theme action.

Viewing 1 replies (of 1 total)
  • The topic ‘How to extend a class in a wordpress plugin from theme?’ is closed to new replies.