Skip to content

Instantly share code, notes, and snippets.

@dlxsnippets
Created August 24, 2023 08:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlxsnippets/000b9af0d5f0051b6da56d64af51f70b to your computer and use it in GitHub Desktop.
Save dlxsnippets/000b9af0d5f0051b6da56d64af51f70b to your computer and use it in GitHub Desktop.
Demonstration of Creating a Fullscreen Admin
<?php
/**
* Plugin Name: Fullscreen Admin Panel.
* Plugin URI: https://dlxplugins.com
* Description: A demo plugin to create a fullscreen admin panel.
* Version: 1.0.0
* Requires at least: 6.0
* Requires PHP: 7.3
* Author: DLX Plugins
* Author URI: https://dlxplugins.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
* @package DLXPlugins\FullscreenAdmin
*/
namespace DLXPlugins\FullscreenAdmin;
/**
* Initialize the admin panel.
*/
add_action( 'admin_menu', __NAMESPACE__ . '\add_admin_menu' );
/**
* Add the admin menu.
*/
function add_admin_menu() {
add_dashboard_page(
'',
'',
'manage_options',
'my-admin-panel-slug',
'',
null
);
}
// Add the admin page for full-screen.
add_action( 'current_screen', __NAMESPACE__ . '\maybe_output_admin_page', 10 );
/**
* Output the dashboard admin page.
*/
function maybe_output_admin_page() {
// Exit if not in admin.
if ( ! is_admin() ) {
return;
}
// Make sure we're on the right screen.
$screen = get_current_screen();
if ( 'my-admin-panel-slug' !== $screen->id ) {
return;
}
get_admin_page_header();
/**
* Begin body content.
*/
?>
<main>
Hello there.
</main>
<?php
get_admin_page_footer();
exit;
}
/**
* Output landing page header.
*
* Credit: SliceWP Setup Wizard.
*/
function get_admin_page_header() {
// Output header HTML.
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Admin Page Title</title>
<?php
wp_register_script(
'my-plugin-admin-js',
plugins_url( 'assets/js/admin.js', __FILE__ ),
array(),
'1.0.0',
true
);
wp_register_style(
'my-plugin-admin-css',
plugins_url( 'assets/css/admin.css', __FILE__ ),
array(),
'1.0.0'
);
wp_print_styles( 'my-plugin-admin-css' );
wp_print_scripts( 'my-plugin-admin-js' );
?>
</head>
<body>
<?php
}
/**
* Output landing page footer.
*
* Credit: SliceWP Setup Wizard.
*/
function get_admin_page_footer() {
// Output footer HTML.
?>
</body>
</html>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment