Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created October 13, 2016 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tommcfarlin/2003d0b6fcfe5acf9af4dd973cb0eb48 to your computer and use it in GitHub Desktop.
Save tommcfarlin/2003d0b6fcfe5acf9af4dd973cb0eb48 to your computer and use it in GitHub Desktop.
[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