class-network-admin-menu.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Menu
  6. */
  7. /**
  8. * Network Admin Menu handler.
  9. */
  10. class WPSEO_Network_Admin_Menu extends WPSEO_Base_Menu {
  11. /**
  12. * Registers all hooks to WordPress.
  13. *
  14. * @return void
  15. */
  16. public function register_hooks() {
  17. // Needs the lower than default priority so other plugins can hook underneath it without issue.
  18. add_action( 'network_admin_menu', [ $this, 'register_settings_page' ], 5 );
  19. }
  20. /**
  21. * Register the settings page for the Network settings.
  22. *
  23. * @return void
  24. */
  25. public function register_settings_page() {
  26. if ( ! $this->check_manage_capability() ) {
  27. return;
  28. }
  29. add_menu_page(
  30. __( 'Network Settings', 'wordpress-seo' ) . ' - Yoast SEO',
  31. __( 'SEO', 'wordpress-seo' ),
  32. $this->get_manage_capability(),
  33. $this->get_page_identifier(),
  34. [ $this, 'network_config_page' ],
  35. WPSEO_Utils::get_icon_svg()
  36. );
  37. $submenu_pages = $this->get_submenu_pages();
  38. $this->register_submenu_pages( $submenu_pages );
  39. }
  40. /**
  41. * Returns the list of registered submenu pages.
  42. *
  43. * @return array List of registered submenu pages.
  44. */
  45. public function get_submenu_pages() {
  46. // Submenu pages.
  47. $submenu_pages = [
  48. $this->get_submenu_page(
  49. __( 'General', 'wordpress-seo' ),
  50. $this->get_page_identifier(),
  51. [ $this, 'network_config_page' ]
  52. ),
  53. ];
  54. if ( WPSEO_Utils::allow_system_file_edit() === true ) {
  55. $submenu_pages[] = $this->get_submenu_page( __( 'Edit Files', 'wordpress-seo' ), 'wpseo_files' );
  56. }
  57. $submenu_pages[] = $this->get_submenu_page( __( 'Extensions', 'wordpress-seo' ), 'wpseo_licenses' );
  58. return $submenu_pages;
  59. }
  60. /**
  61. * Loads the form for the network configuration page.
  62. *
  63. * @return void
  64. */
  65. public function network_config_page() {
  66. require_once WPSEO_PATH . 'admin/pages/network.php';
  67. }
  68. /**
  69. * Checks whether the current user has capabilities to manage all options.
  70. *
  71. * @return bool True if capabilities are sufficient, false otherwise.
  72. */
  73. protected function check_manage_capability() {
  74. return current_user_can( $this->get_manage_capability() );
  75. }
  76. /**
  77. * Returns the capability that is required to manage all options.
  78. *
  79. * @return string Capability to check against.
  80. */
  81. protected function get_manage_capability() {
  82. return 'wpseo_manage_network_options';
  83. }
  84. }