Posted By

suibhne on 08/25/10


Tagged

php wordpress menus


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

g33kish
convergine
PM-Webdesign


Wordpress Administration Menus


 / Published in: PHP
 

Something simple to add all levels of Wordpress menus to a plugin in the admin area.

  1. <?php
  2. /*
  3. Plugin Name: Jiltin Plugin Menuadd
  4. Plugin URI: http://www.notesbit.com
  5. Description: Jiltin Plugin Menuadd
  6. Author: Jay
  7. Author URI: http://www.notesbit.com
  8. */
  9. // Hook for adding admin menus
  10. add_action(‘admin_menu’, ‘mt_add_pages’);
  11.  
  12. // action function for above hook
  13. function mt_add_pages() {
  14. // Add a new submenu under Options:
  15. add_options_page(‘Test Page title Options’, ‘Test menu title Options’, 8, ‘test_file_options’, ‘mt_options_page’);
  16.  
  17. // Add a new submenu under Manage:
  18. add_management_page(‘Test Manage’, ‘Test Manage’, 8, ‘testmanage’, ‘mt_manage_page’);
  19.  
  20. // Add a new top-level menu (ill-advised):
  21. add_menu_page(‘Test Toplevel’, ‘Test Toplevel’, 8, __FILE__, ‘mt_toplevel_page’);
  22.  
  23. // Add a new top-level menu (ill-advised):
  24. // add_menu_page(’Test Toplevel2′, ‘Test Toplevel2′, 8, __FILE__, ‘mt_toplevel_page’);
  25.  
  26. // Add a submenu to the custom top-level menu:
  27. add_submenu_page(__FILE__, ‘Test Sublevel’, ‘Test Sublevel’, 8, ’sub-page’, ‘mt_sublevel_page’);
  28.  
  29. // Add a second submenu to the custom top-level menu:
  30. add_submenu_page(__FILE__, ‘Test Sublevel 2, ‘Test Sublevel 2, 8, ’sub-page2′, ‘mt_sublevel_page2′);
  31. }
  32.  
  33. // mt_options_page() displays the page content for the Test Options submenu
  34. function mt_options_page() {
  35. echo "<h2>Test Options</h2>";
  36. }
  37.  
  38. // mt_manage_page() displays the page content for the Test Manage submenu
  39. function mt_manage_page() {
  40. echo "<h2>Test Manage</h2>";
  41. }
  42.  
  43. // mt_toplevel_page() displays the page content for the custom Test Toplevel menu
  44. function mt_toplevel_page() {
  45. echo "<h2>Test Toplevel</h2>";
  46. }
  47.  
  48. // mt_sublevel_page() displays the page content for the first submenu
  49. // of the custom Test Toplevel menu
  50. function mt_sublevel_page() {
  51. echo "<h2>Test Sublevel</h2>";
  52. }
  53.  
  54. // mt_sublevel_page2() displays the page content for the second submenu
  55. // of the custom Test Toplevel menu
  56. function mt_sublevel_page2() {
  57. echo "<h2>Test Sublevel 2</h2>";
  58. }
  59.  
  60. ?>

Report this snippet  

You need to login to post a comment.