How to register a menu using WPPB (WordPress Plugin Boilerplate)

First up let’s add As an example my Plugin is called Puri. Replace that with your Plugin name. First up let’s add the following to the puri.php (yourplugin.php) file in the first level.

define( 'PURI_PATH', plugin_dir_path( __FILE__ ) );

Once defined let’s register the WordPr ess menu. Go inside the admin folder and find

/**
* Register Overview Page (Top-Level Page)
*/
public function register_overview_page() {
add_menu_page(
__( 'WordPress Admin Patterns Overview', $this->plugin_name ),
__( 'Puri', $this->plugin_name ),
'read',
'admin-puri',
array( $this, 'include_overview_partial' ),
'dashicons-wordpress-alt',
9999
);
}

/**
* Include Overview Partial
*/
public function include_overview_partial() {
include_once( PURI_PATH . 'admin/partials/puri-overview.php' );
}

Now our page for the plugin will be located at 'admin/partials/puri-overview.php'. You should make sure you file isn’t empty when testing. Head back out of the admin folder and enter the includes folder. open up the class-puri.php file. Around line 153 you should see

private function define_admin_hooks() {

Inside the define_admin_hooks we will add the action to display the menu.

$this->loader->add_action( 'admin_menu', $plugin_admin, 'register_overview_page' );

There you go! You have registered your first admin page using the WordPress Plugin Boilerplate.

Newsletter

I’ll be creating more content about starting and running WordPress plugin businesses. You can follow the journey by joining my mail list.

Leave a Comment