Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress] WordPress Menu Page (And A Submenu Page or Two, Too!)
<?php
add_action( 'plugins_loaded', 'acme_directory_importer' );
/**
* Starts the plugin.
*
* @since 1.0.0
*/
function acme_directory_importer() {
if ( ! is_admin() ) {
return;
}
// Start the machine...
}
<?php
class Menu {
private $settings;
private $import;
public function __construct( $container ) {
$this->settings = $container->get( 'settings-page' );
$this->import = $container->get( 'import-page' );
}
// Irrelevant code removed, for now.
}
<?php
public function display() {
add_menu_page(
'Settings',
'Settings',
'manage_options',
'acme-directory',
array( $this->settings, 'display' ),
'',
30
);
add_submenu_page(
'acme-directory',
'Settings',
'Settings',
'manage_options',
'acme-settings',
array( $this->settings, 'display' )
);
}
<?php
class Menu {
private $settings;
private $import;
public function __construct( $container ) {
$this->settings = $container->get( 'settings-page' );
$this->import = $container->get( 'import-page' );
}
public function init() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
public function admin_menu() {
add_menu_page(
'Settings',
'Settings',
'manage_options',
'acme-directory',
array( $this->settings, 'display' ),
'',
30
);
add_submenu_page(
'acme-directory',
'Settings',
'Settings',
'manage_options',
'acme-settings',
array( $this->settings, 'display' )
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment