Nenhuma Descrição

class-p2-admin-menu.php 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * P2 Admin Menu file.
  4. *
  5. * @package Jetpack
  6. */
  7. namespace Automattic\Jetpack\Dashboard_Customizations;
  8. require_once __DIR__ . '/class-wpcom-admin-menu.php';
  9. /**
  10. * Class P2_Admin_Menu.
  11. */
  12. class P2_Admin_Menu extends WPcom_Admin_Menu {
  13. /**
  14. * Slug for the "Appearance" menu item.
  15. *
  16. * @var string
  17. */
  18. private $appearance_slug = 'themes.php';
  19. /**
  20. * Slug for the "Jetpack" menu item.
  21. *
  22. * @var string
  23. */
  24. private $jetpack_slug = 'jetpack';
  25. /**
  26. * Slug for the "Upgrades" menu item.
  27. *
  28. * @var string
  29. */
  30. private $upgrades_slug = 'paid-upgrades.php';
  31. /**
  32. * Slug for the "Plugins" menu item.
  33. *
  34. * @var string
  35. */
  36. private $plugins_slug = 'plugins.php';
  37. /**
  38. * Slug for the "Tools" menu item.
  39. *
  40. * @var string
  41. */
  42. private $tools_slug = 'tools.php';
  43. /**
  44. * Whether or not the P2 is a hub.
  45. *
  46. * @var bool
  47. */
  48. private $is_hub = false;
  49. /**
  50. * P2_Admin_Menu constructor.
  51. */
  52. protected function __construct() {
  53. parent::__construct();
  54. if (
  55. defined( 'IS_WPCOM' ) && IS_WPCOM &&
  56. function_exists( 'require_lib' )
  57. ) {
  58. require_lib( 'wpforteams' );
  59. $this->is_hub = \WPForTeams\Workspace\is_workspace_hub( get_current_blog_id() );
  60. }
  61. // Appearance -> AMP. This needs to be called here in the constructor.
  62. // Running it from reregister_menu_items is not early enough.
  63. remove_action( 'admin_menu', 'amp_add_customizer_link' );
  64. }
  65. /**
  66. * Create the desired menu output.
  67. */
  68. public function reregister_menu_items() {
  69. parent::reregister_menu_items();
  70. if ( ! $this->is_hub ) {
  71. $this->remove_menus_for_p2_space();
  72. // Only add the P2 Editor menu on non-hubs.
  73. $this->add_p2_editor_menu();
  74. } else {
  75. $this->remove_menus_for_hub();
  76. }
  77. $this->remove_menus_for_all_p2s();
  78. }
  79. /**
  80. * Remove menu items that are not applicable for P2 workspace sites.
  81. */
  82. private function remove_menus_for_p2_space() {
  83. // Non-hub P2s can't have plans at all.
  84. remove_menu_page( $this->upgrades_slug );
  85. // Jetpack -> Backup.
  86. remove_submenu_page( $this->jetpack_slug, 'https://wordpress.com/backup/' . $this->domain );
  87. // Appearance -> Themes.
  88. remove_submenu_page( $this->appearance_slug, 'https://wordpress.com/themes/' . $this->domain );
  89. // Appearance -> Additional CSS.
  90. $customize_custom_css_url = add_query_arg(
  91. array( 'autofocus' => array( 'section' => 'css_nudge' ) ),
  92. 'https://wordpress.com/customize/' . $this->domain
  93. );
  94. remove_submenu_page( $this->appearance_slug, $customize_custom_css_url );
  95. }
  96. /**
  97. * Remove menu items that are not applicable for P2 hubs.
  98. */
  99. private function remove_menus_for_hub() {
  100. // Hubs can have plans, but not domain and email products.
  101. remove_submenu_page( $this->upgrades_slug, 'https://wordpress.com/domains/manage/' . $this->domain );
  102. remove_submenu_page( $this->upgrades_slug, 'https://wordpress.com/email/' . $this->domain );
  103. // Stats.
  104. remove_menu_page( 'https://wordpress.com/stats/day/' . $this->domain );
  105. // Hide all Jetpack for hubs.
  106. remove_menu_page( $this->jetpack_slug );
  107. // Hide posts.
  108. remove_menu_page( 'edit.php' );
  109. // Hide pages.
  110. remove_menu_page( 'edit.php?post_type=page' );
  111. // Hide media.
  112. remove_menu_page( 'https://wordpress.com/media/' . $this->domain );
  113. // Hide comments.
  114. remove_menu_page( 'https://wordpress.com/comments/all/' . $this->domain );
  115. // Hide appearance.
  116. remove_menu_page( $this->appearance_slug );
  117. // Tools.
  118. remove_menu_page( $this->tools_slug );
  119. }
  120. /**
  121. * Remove menu items that are not applicable for all P2s.
  122. */
  123. private function remove_menus_for_all_p2s() {
  124. // The following menu items are hidden for both hubs and P2 sites.
  125. remove_menu_page( 'link-manager.php' );
  126. remove_menu_page( 'feedback' );
  127. remove_menu_page( 'https://wordpress.com/beta-testing/' . $this->domain );
  128. remove_menu_page( $this->plugins_slug );
  129. remove_menu_page( 'https://wordpress.com/plugins/' . $this->domain );
  130. remove_submenu_page( $this->tools_slug, 'https://wordpress.com/marketing/tools/' . $this->domain );
  131. remove_submenu_page( $this->tools_slug, 'https://wordpress.com/earn/' . $this->domain );
  132. remove_submenu_page( 'https://wordpress.com/settings/general/' . $this->domain, 'sharing' );
  133. remove_submenu_page( 'https://wordpress.com/settings/general/' . $this->domain, 'polls&action=options' );
  134. remove_submenu_page( 'https://wordpress.com/settings/general/' . $this->domain, 'ratings&action=options' );
  135. remove_submenu_page(
  136. 'options-general.php',
  137. 'https://wordpress.com/hosting-config/' . $this->domain
  138. );
  139. remove_submenu_page(
  140. 'https://wordpress.com/settings/general/' . $this->domain,
  141. 'https://wordpress.com/marketing/sharing-buttons/' . $this->domain
  142. );
  143. }
  144. /**
  145. * Adds the P2 Editor menu.
  146. */
  147. private function add_p2_editor_menu() {
  148. /** This action is documented in `wp-content/plugins/p2-editor/classes/p2-editor-admin.php` */
  149. if ( apply_filters( 'p2tenberg_admin_patterns', apply_filters( 'p2editor_admin_patterns', true ) ) !== true ) {
  150. return;
  151. }
  152. // Add the menu only in Calypso (it already exists in WP Admin).
  153. if ( $this->is_api_request ) {
  154. add_menu_page(
  155. esc_attr__( 'P2 Editor', 'jetpack' ),
  156. __( 'P2 Editor', 'jetpack' ),
  157. 'manage_options',
  158. 'p2editor',
  159. '',
  160. 'dashicons-admin-multisite'
  161. );
  162. }
  163. }
  164. }