I have a plugin like this:
<?php
/*
Plugin Name: MyPlugin
*/
class MyPlugin
{
public function __construct()
{
add_action('wp_enqueue_scripts', array($this, 'enqueueAssets'));
}
public function enqueueAssets()
{
wp_register_script('myplugin', plugins_url('myplugin.js', __FILE__), array('jquery'));
wp_enqueue_script('myplugin');
}
// More methods
}
The in a sidebar I create a new instance:
$plugin = new MyPlugin;
But when I open devtools in Chrome and go to "Sources" the assets are not being loaded. If I use a function outside the class it works:
add_action('wp_enqueue_scripts', 'enqueueAssets');
function enqueueAssets()
{
wp_register_script('myplugin', plugins_url('myplugin.js', __FILE__), array('jquery'));
wp_enqueue_script('myplugin');
}
class MyPlugin
{
Am I missing something here?