I have a parent class, which contains the following:
use app\My_Dashboard;
class My_Class {
public function __construct() {
add_action('admin_menu', array($this, 'setup_dashboard_page'));
}
public function setup_dashboard_page() {
My_Dashboard::add_dashboard_page();
}
}
And the class which has the admin page functions:
class My_Dashboard {
public static function add_dashboard_page() {
add_menu_page('My Settings', 'My Settings', 'my-settings', array($this, 'dashboard_page_cb'));
}
public function dashboard_page_cb() {
//The markup
}
}
This approach doesn’t work, and I cannot see my admin menu item and page added. The second approach I tried:
use app\My_Dashboard;
class My_Class {
public function __construct() {
add_action('admin_menu', array($this, 'setup_dashboard_page'));
}
public function setup_dashboard_page() {
//Not very sure of the syntax, bad at OOP
add_menu_page('My Settings', 'My Settings', 'my-settings', 'My_Dashboard::dashboard_page_cb');
}
}
How do I get it to work? My idea is to separate all the dashboard related stuff to the other class.
Update:
The first approach worked, and the menu item is added. But the callback function that outputs the page markup doesn’t seem to work. I checked for typos but everything seems okay.