Skip to content

Instantly share code, notes, and snippets.

@hakre
Created September 14, 2010 16:56
Show Gist options
  • Save hakre/579350 to your computer and use it in GitHub Desktop.
Save hakre/579350 to your computer and use it in GitHub Desktop.
<?php
/**
* Register an Admin Page - Example
*
* NOTE: MU Plugin.
*
* @author hakre <http://hakre.wordpress.com/>
* @link http://wordpress.stackexchange.com/questions/1778/admin-config-screen-without-menu
*/
return AdminPageDemo::bootstrap();
class AdminPageDemo {
static $identifier = 'adminpagedemo';
/**
* plugin initialisation
*/
static function bootstrap() {
//Admin Menu Hook
add_action($hook = 'admin_menu', array(__CLASS__, $hook));
}
/**
* admin_menu action
*/
static function admin_menu() {
$page_callback = array(__CLASS__, 'demo_page');
$url = self::register_admin_page($page_callback);
}
/**
* Register a Callback as an Admin Page
*
* This Page is not added to any menu.
*
* @param Callback $callback
* @param String $identifier (optional)
* @return string URL for the new page
*/
static function register_admin_page($callback, $identifier = false) {
//$identifier is optional.
$identifier || $identifier = is_array($callback) ? $callback[1] : $callback;
// Prefix Identifier
$identifier = sprintf('%s_%s', self::$identifier, $identifier);
// Wordpress Constant
$parent_slug = 'options-general.php';
// Get Hookname
$hookname = get_plugin_page_hookname( $identifier, $parent_slug);
// Assign Callback to hook
add_filter( $hookname, $callback );
// Register Hook as a Page-Hook
$GLOBALS['_registered_pages'][$hookname] = true;
$url = admin_url($parent_slug . '?page=' . $identifier);
return $url;
}
static function demo_page() {
echo 'This is your Demo Page.';
}
}
#EOF;
@NuarHaruha
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment