From d7f1eccafc8013b20a5f23e5b5c97df458ea6081 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 21 Feb 2021 14:34:14 +0100 Subject: Add top level menu to WordPress admin menu. Currently nothing useful on the page, but a placeholder for a more useful page later, and possibly submenus for other functionality. The menu is placed right below the 'Media' menu for now, and is available to anyone with the 'upload_files' capability. Both of these may be adjusted later if there's a better location or other capabilities fit better. --- giglogadmin.php | 17 +++++++++++++++++ includes/admin/views/giglog_admin_page.php | 26 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 includes/admin/views/giglog_admin_page.php diff --git a/giglogadmin.php b/giglogadmin.php index 1157d73..091cdcf 100644 --- a/giglogadmin.php +++ b/giglogadmin.php @@ -24,6 +24,7 @@ if ( !class_exists( 'GiglogAdmin_Plugin' ) ) { require_once __DIR__ . '/includes/public/shortcodes/giglog_display_unprocessed.php'; require_once __DIR__ . '/includes/public/shortcodes/giglog_photographers.php'; require_once __DIR__ . '/includes/public/shortcodes/giglog_process_files.php'; + require_once __DIR__ . '/includes/admin/views/giglog_admin_page.php'; class GiglogAdmin_Plugin { @@ -34,6 +35,7 @@ if ( !class_exists( 'GiglogAdmin_Plugin' ) ) { add_shortcode('giglog_upload', 'giglogadmin_upload_files'); add_shortcode('giglog_photog', 'giglogadmin_photographers'); + add_action( 'admin_menu', array( 'GiglogAdmin_Plugin', 'add_admin_pages' )); add_filter( 'wp_nav_menu_args', array( 'GiglogAdmin_Plugin', 'nav_menu_args' )); } @@ -44,6 +46,21 @@ if ( !class_exists( 'GiglogAdmin_Plugin' ) ) { static function deactivate() { } + /** + * Adds the 'Giglog' top level menu to the left side WordPress admin + * menu. Other subpages will come later. + */ + static function add_admin_pages() { + add_menu_page( + "Giglog", // Page title + "Giglog", // Menu title + "upload_files", // Will show for users with this capability + "giglog", // menu slug + array( 'GiglogAdmin_AdminPage', 'render_html' ), // callable + 'dashicons-tickets-alt', // Icon url + 11); // Position, just below 'Media' + } + /* * Show menus based on whether user is logged in or not. * diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php new file mode 100644 index 0000000..45a9f3f --- /dev/null +++ b/includes/admin/views/giglog_admin_page.php @@ -0,0 +1,26 @@ +. + */ + +if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { + class GiglogAdmin_AdminPage { + static function render_html() { + echo '

Hi there admin!

'; + } + } +} +?> -- cgit v1.2.3