So In my main plugin file I have this
class RegistrationHooks
{
/**
* @var string
*/
protected string $plugin_dir;
public function __construct()
{
$this->plugin_dir = WP_PLUGIN_DIR . '/invoices';
}
function active_invoices()
{
require_once $this->plugin_dir . '/includes/class-invoices.php';
new Invoices();
}
}
$hooksInstance = new RegistrationHooks();
register_activation_hook(__FILE__, array($hooksInstance, 'active_invoices'));
And inside My Invoices
class I have this:
class Invoices
{
public function __construct()
{
$this->load_dependencies();
$this->define_admin_hooks();
}
private function load_dependencies()
{
$path = WP_PLUGIN_DIR . '/invoices';
if ($path) {
require_once $path . '/admin/class-admin.php';
}
}
private function define_admin_hooks()
{
$plugin_admin = new Admin();
add_action('admin_menu', array($plugin_admin, 'add_plugin_admin_menu'));
}
}
And Inside my Admin
class I have simple method to add item to menu
class Admin {
public function add_plugin_admin_menu()
{
add_menu_page(
'Page Title',
'Menu Title',
'edit_posts',
'menu_slug',
);
}
}
But when I activate Plugin item doesnt get added to admin menu. When I Place my Invoices
class inside my main Plugin class it works.