Created
September 14, 2010 16:56
-
-
Save hakre/579350 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks