Permalink
Browse files

Introduce WordPress_Admin_Menu_Page class.

  • Loading branch information...
felixarntz committed Jan 14, 2018
1 parent 3f73ca4 commit 76281736965958e01446abcdf1031b277530a4e6
Showing with 43 additions and 0 deletions.
  1. +43 −0 src/Admin_Page/WordPress_Admin_Menu_Page.php
@@ -0,0 +1,43 @@
<?php
/**
* WordPress_Admin_Menu_Page class
*
* @package Leaves_And_Love\OOP_Admin_Pages\Admin_Page
* @since 1.0.0
*/
namespace Leaves_And_Love\OOP_Admin_Pages\Admin_Page;
/**
* Class representing a WordPress admin page that also has a top-level menu entry.
*
* @since 1.0.0
*/
class WordPress_Admin_Menu_Page extends WordPress_Admin_Page {
const MENU_TITLE = 'menu_title';
const ICON_URL = 'icon_url';
const POSITION = 'position';
/**
* Gets the callback to use to register the admin page within WordPress.
*
* @since 1.0.0
*
* @return callable Callback to hook into the respective menu action.
*/
protected function get_register_hook_callback() {
return function() {
$slug = $this->getConfigKey( self::SLUG );
$title = $this->getConfigKey( self::TITLE );
$capability = $this->getConfigKey( self::CAPABILITY );
$menu_title = $this->hasConfigKey( self::MENU_TITLE ) ? $this->getConfigKey( self::MENU_TITLE ) : $title;
$icon_url = $this->hasConfigKey( self::ICON_URL ) ? $this->getConfigKey( self::ICON_URL ) : '';
$position = $this->hasConfigKey( self::POSITION ) ? $this->getConfigKey( self::POSITION ) : null;
$hook_suffix = add_menu_page( $title, $menu_title, $capability, $slug, array( $this, 'render' ), $icon_url, $position );
add_action( "load-{$hook_suffix}", array( $this, 'initialize' ) );
};
}
}

1 comment on commit 7628173

@felixarntz

This comment has been minimized.

Owner

felixarntz commented on 7628173 Jan 20, 2018

This is the more specific admin page implementation that also adds a toplevel menu item.

Please sign in to comment.