Submenu.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * WordPress Menu Page Base Class
  4. */
  5. abstract class NF_Abstracts_Submenu
  6. {
  7. /**
  8. * (required) The slug name for the parent menu (or the file name of a standard WordPress admin page)
  9. *
  10. * @var string
  11. */
  12. public $parent_slug = '';
  13. /**
  14. * (required) The text to be displayed in the title tags of the page when the menu is selected
  15. *
  16. * @var string
  17. */
  18. public $page_title = '';
  19. /**
  20. * (required) The on-screen name text for the menu
  21. *
  22. * @var string
  23. */
  24. public $menu_title = '';
  25. /**
  26. * (required) The capability required for this menu to be displayed to the user.
  27. *
  28. * @var string
  29. */
  30. public $capability = 'manage_options';
  31. /**
  32. * (required) The slug name to refer to this menu by (should be unique for this menu).
  33. *
  34. * @var string
  35. */
  36. public $menu_slug = '';
  37. /**
  38. * (optional) The function that displays the page content for the menu page.
  39. *
  40. * @var string
  41. */
  42. public $function = 'display';
  43. public $priority = 10;
  44. /**
  45. * Constructor
  46. *
  47. * Translate text and add the 'admin_menu' action.
  48. */
  49. public function __construct()
  50. {
  51. add_action( 'admin_menu', array( $this, 'register' ), $this->priority );
  52. }
  53. /**
  54. * Register the menu page.
  55. */
  56. public function register()
  57. {
  58. $function = ( $this->function ) ? array( $this, $this->function ) : NULL;
  59. add_submenu_page(
  60. $this->parent_slug,
  61. $this->get_page_title(),
  62. $this->get_menu_title(),
  63. apply_filters( 'ninja_forms_submenu_' . $this->get_menu_slug() . '_capability', $this->get_capability() ),
  64. $this->get_menu_slug(),
  65. $function
  66. );
  67. }
  68. public function get_page_title()
  69. {
  70. return $this->page_title;
  71. }
  72. public function get_menu_title()
  73. {
  74. return ( $this->menu_title ) ? $this->menu_title : $this->get_page_title();
  75. }
  76. public function get_menu_slug()
  77. {
  78. return ( $this->menu_slug ) ? $this->menu_slug : 'nf-' . strtolower( preg_replace( '/[^A-Za-z0-9-]+/', '-', $this->get_menu_title() ) );
  79. }
  80. public function get_capability()
  81. {
  82. return $this->capability;
  83. }
  84. /**
  85. * Display the menu page.
  86. */
  87. public abstract function display();
  88. }