Nav apraksta

class-admin-menu.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <?php
  2. /**
  3. * Admin Menu file.
  4. *
  5. * @package automattic/jetpack
  6. */
  7. namespace Automattic\Jetpack\Dashboard_Customizations;
  8. use Automattic\Jetpack\Redirect;
  9. require_once __DIR__ . '/class-base-admin-menu.php';
  10. /**
  11. * Class Admin_Menu.
  12. */
  13. class Admin_Menu extends Base_Admin_Menu {
  14. /**
  15. * Create the desired menu output.
  16. */
  17. public function reregister_menu_items() {
  18. // Remove separators.
  19. remove_menu_page( 'separator1' );
  20. $this->add_stats_menu();
  21. $this->add_upgrades_menu();
  22. $this->add_posts_menu();
  23. $this->add_media_menu();
  24. $this->add_page_menu();
  25. $this->add_testimonials_menu();
  26. $this->add_portfolio_menu();
  27. $this->add_comments_menu();
  28. $this->add_appearance_menu();
  29. $this->add_plugins_menu();
  30. $this->add_users_menu();
  31. $this->add_tools_menu();
  32. $this->add_options_menu();
  33. $this->add_jetpack_menu();
  34. $this->add_gutenberg_menus();
  35. // Remove Links Manager menu since its usage is discouraged. https://github.com/Automattic/wp-calypso/issues/51188.
  36. // @see https://core.trac.wordpress.org/ticket/21307#comment:73.
  37. if ( $this->should_disable_links_manager() ) {
  38. remove_menu_page( 'link-manager.php' );
  39. }
  40. ksort( $GLOBALS['menu'] );
  41. }
  42. /**
  43. * Get the preferred view for the given screen.
  44. *
  45. * @param string $screen Screen identifier.
  46. * @param bool $fallback_global_preference (Optional) Whether the global preference for all screens should be used
  47. * as fallback if there is no specific preference for the given screen.
  48. * Default: true.
  49. * @return string
  50. */
  51. public function get_preferred_view( $screen, $fallback_global_preference = true ) {
  52. // When no preferred view has been set for "Users > All Users" or "Settings > General", keep the previous
  53. // behavior that forced the default view regardless of the global preference.
  54. if (
  55. $fallback_global_preference &&
  56. in_array( $screen, array( 'users.php', 'options-general.php' ), true )
  57. ) {
  58. $preferred_view = parent::get_preferred_view( $screen, false );
  59. if ( self::UNKNOWN_VIEW === $preferred_view ) {
  60. return self::DEFAULT_VIEW;
  61. }
  62. return $preferred_view;
  63. }
  64. return parent::get_preferred_view( $screen, $fallback_global_preference );
  65. }
  66. /**
  67. * Check if Links Manager is being used.
  68. */
  69. public function should_disable_links_manager() {
  70. // The max ID number of the auto-generated links.
  71. // See /wp-content/mu-plugins/wpcom-wp-install-defaults.php in WP.com.
  72. $max_default_id = 10;
  73. // We are only checking the latest entry link_id so are limiting the query to 1.
  74. $link_manager_links = get_bookmarks(
  75. array(
  76. 'orderby' => 'link_id',
  77. 'order' => 'DESC',
  78. 'limit' => 1,
  79. 'hide_invisible' => 0,
  80. )
  81. );
  82. // Ordered links by ID descending, check if the first ID is more than $max_default_id.
  83. if ( count( $link_manager_links ) > 0 && $link_manager_links[0]->link_id > $max_default_id ) {
  84. return false;
  85. }
  86. return true;
  87. }
  88. /**
  89. * Adds My Home menu.
  90. */
  91. public function add_my_home_menu() {
  92. $this->update_menu( 'index.php', 'https://wordpress.com/home/' . $this->domain, __( 'My Home', 'jetpack' ), 'manage_options', 'dashicons-admin-home' );
  93. }
  94. /**
  95. * Adds upsell nudge as a menu.
  96. *
  97. * @param object $nudge The $nudge object containing the content, CTA, link and tracks.
  98. */
  99. public function add_upsell_nudge( $nudge ) {
  100. $message = '
  101. <div class="upsell_banner">
  102. <div class="banner__info">
  103. <div class="banner__title">%1$s</div>
  104. </div>
  105. <div class="banner__action">
  106. <button type="button" class="button">%2$s</button>
  107. </div>
  108. </div>';
  109. $message = sprintf(
  110. $message,
  111. wp_kses( $nudge['content'], array() ),
  112. wp_kses( $nudge['cta'], array() )
  113. );
  114. add_menu_page( 'site-notices', $message, 'read', 'https://wordpress.com' . $nudge['link'], null, null, 1 );
  115. add_filter( 'add_menu_classes', array( $this, 'set_site_notices_menu_class' ) );
  116. }
  117. /**
  118. * Adds a custom element class and id for Site Notices's menu item.
  119. *
  120. * @param array $menu Associative array of administration menu items.
  121. * @return array
  122. */
  123. public function set_site_notices_menu_class( array $menu ) {
  124. foreach ( $menu as $key => $menu_item ) {
  125. if ( 'site-notices' !== $menu_item[3] ) {
  126. continue;
  127. }
  128. $classes = ' toplevel_page_site-notices';
  129. if ( isset( $menu_item[4] ) ) {
  130. $menu[ $key ][4] = $menu_item[4] . $classes;
  131. $menu[ $key ][5] = 'toplevel_page_site-notices';
  132. break;
  133. }
  134. }
  135. return $menu;
  136. }
  137. /**
  138. * Adds Inbox menu.
  139. */
  140. public function add_inbox_menu() {
  141. /**
  142. * Whether to show the WordPress.com Inbox menu under Upgrades menu.
  143. *
  144. * @use add_filter( 'jetpack_show_wpcom_inbox_menu', '__return_true' );
  145. * @module masterbar
  146. *
  147. * @since 9.7.0
  148. *
  149. * @param bool $jetpack_show_wpcom_inbox_menu Load the WordPress.com Inbox menu item. Default to false.
  150. */
  151. if ( apply_filters( 'jetpack_show_wpcom_inbox_menu', false ) ) {
  152. add_menu_page( __( 'Inbox', 'jetpack' ), __( 'Inbox', 'jetpack' ), 'edit_posts', 'https://wordpress.com/inbox/' . $this->domain, null, 'dashicons-email', '4.64424' );
  153. }
  154. }
  155. /**
  156. * Adds Stats menu.
  157. */
  158. public function add_stats_menu() {
  159. add_menu_page( __( 'Stats', 'jetpack' ), __( 'Stats', 'jetpack' ), 'view_stats', 'https://wordpress.com/stats/day/' . $this->domain, null, 'dashicons-chart-bar', 3 );
  160. }
  161. /**
  162. * Adds Upgrades menu.
  163. *
  164. * @param string $plan The current WPCOM plan of the blog.
  165. */
  166. public function add_upgrades_menu( $plan = null ) {
  167. global $menu;
  168. $menu_exists = false;
  169. foreach ( $menu as $item ) {
  170. if ( 'paid-upgrades.php' === $item[2] ) {
  171. $menu_exists = true;
  172. break;
  173. }
  174. }
  175. if ( ! $menu_exists ) {
  176. if ( $plan ) {
  177. // Add display:none as a default for cases when CSS is not loaded.
  178. $site_upgrades = '%1$s<span class="inline-text" style="display:none">%2$s</span>';
  179. $site_upgrades = sprintf(
  180. $site_upgrades,
  181. __( 'Upgrades', 'jetpack' ),
  182. $plan
  183. );
  184. } else {
  185. $site_upgrades = __( 'Upgrades', 'jetpack' );
  186. }
  187. add_menu_page( __( 'Upgrades', 'jetpack' ), $site_upgrades, 'manage_options', 'paid-upgrades.php', null, 'dashicons-cart', 4 );
  188. }
  189. add_submenu_page( 'paid-upgrades.php', __( 'Plans', 'jetpack' ), __( 'Plans', 'jetpack' ), 'manage_options', 'https://wordpress.com/plans/my-plan/' . $this->domain, null, 1 );
  190. add_submenu_page( 'paid-upgrades.php', __( 'Purchases', 'jetpack' ), __( 'Purchases', 'jetpack' ), 'manage_options', 'https://wordpress.com/purchases/subscriptions/' . $this->domain, null, 2 );
  191. if ( ! $menu_exists ) {
  192. // Remove the submenu auto-created by Core.
  193. $this->hide_submenu_page( 'paid-upgrades.php', 'paid-upgrades.php' );
  194. }
  195. }
  196. /**
  197. * Adds Posts menu.
  198. */
  199. public function add_posts_menu() {
  200. $submenus_to_update = array();
  201. if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'edit.php' ) ) {
  202. $submenus_to_update['edit.php'] = 'https://wordpress.com/posts/' . $this->domain;
  203. $submenus_to_update['post-new.php'] = 'https://wordpress.com/post/' . $this->domain;
  204. }
  205. if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'edit-tags.php?taxonomy=category' ) ) {
  206. $submenus_to_update['edit-tags.php?taxonomy=category'] = 'https://wordpress.com/settings/taxonomies/category/' . $this->domain;
  207. }
  208. if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'edit-tags.php?taxonomy=post_tag' ) ) {
  209. $submenus_to_update['edit-tags.php?taxonomy=post_tag'] = 'https://wordpress.com/settings/taxonomies/post_tag/' . $this->domain;
  210. }
  211. $this->update_submenus( 'edit.php', $submenus_to_update );
  212. }
  213. /**
  214. * Adds Media menu.
  215. */
  216. public function add_media_menu() {
  217. if ( self::CLASSIC_VIEW === $this->get_preferred_view( 'upload.php' ) ) {
  218. return;
  219. }
  220. $this->hide_submenu_page( 'upload.php', 'media-new.php' );
  221. $this->update_menu( 'upload.php', 'https://wordpress.com/media/' . $this->domain );
  222. }
  223. /**
  224. * Adds Page menu.
  225. */
  226. public function add_page_menu() {
  227. if ( self::CLASSIC_VIEW === $this->get_preferred_view( 'edit.php?post_type=page' ) ) {
  228. return;
  229. }
  230. $submenus_to_update = array(
  231. 'edit.php?post_type=page' => 'https://wordpress.com/pages/' . $this->domain,
  232. 'post-new.php?post_type=page' => 'https://wordpress.com/page/' . $this->domain,
  233. );
  234. $this->update_submenus( 'edit.php?post_type=page', $submenus_to_update );
  235. }
  236. /**
  237. * Adds Testimonials menu.
  238. */
  239. public function add_testimonials_menu() {
  240. $this->add_custom_post_type_menu( 'jetpack-testimonial' );
  241. }
  242. /**
  243. * Adds Portfolio menu.
  244. */
  245. public function add_portfolio_menu() {
  246. $this->add_custom_post_type_menu( 'jetpack-portfolio' );
  247. }
  248. /**
  249. * Adds a custom post type menu.
  250. *
  251. * @param string $post_type Custom post type.
  252. */
  253. public function add_custom_post_type_menu( $post_type ) {
  254. if ( self::CLASSIC_VIEW === $this->get_preferred_view( 'edit.php?post_type=' . $post_type ) ) {
  255. return;
  256. }
  257. $submenus_to_update = array(
  258. 'edit.php?post_type=' . $post_type => 'https://wordpress.com/types/' . $post_type . '/' . $this->domain,
  259. 'post-new.php?post_type=' . $post_type => 'https://wordpress.com/edit/' . $post_type . '/' . $this->domain,
  260. );
  261. $this->update_submenus( 'edit.php?post_type=' . $post_type, $submenus_to_update );
  262. }
  263. /**
  264. * Adds Comments menu.
  265. */
  266. public function add_comments_menu() {
  267. if ( self::CLASSIC_VIEW === $this->get_preferred_view( 'edit-comments.php' ) ) {
  268. return;
  269. }
  270. $this->update_menu( 'edit-comments.php', 'https://wordpress.com/comments/all/' . $this->domain );
  271. }
  272. /**
  273. * Adds Appearance menu.
  274. *
  275. * @return string The Customizer URL.
  276. */
  277. public function add_appearance_menu() {
  278. $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
  279. $default_customize_slug = add_query_arg( 'return', rawurlencode( remove_query_arg( wp_removable_query_args(), $request_uri ) ), 'customize.php' );
  280. $default_customize_header_slug_1 = add_query_arg( array( 'autofocus' => array( 'control' => 'header_image' ) ), $default_customize_slug );
  281. // TODO: Remove WPCom_Theme_Customizer::modify_header_menu_links() and WPcom_Custom_Header::modify_admin_menu_links().
  282. $default_customize_header_slug_2 = admin_url( 'themes.php?page=custom-header' );
  283. $default_customize_background_slug_1 = add_query_arg( array( 'autofocus' => array( 'control' => 'background_image' ) ), $default_customize_slug );
  284. // TODO: Remove Colors_Manager::modify_header_menu_links() and Colors_Manager_Common::modify_header_menu_links().
  285. $default_customize_background_slug_2 = add_query_arg( array( 'autofocus' => array( 'section' => 'colors_manager_tool' ) ), admin_url( 'customize.php' ) );
  286. if ( $this->is_api_request ) {
  287. // In case this is an api request we will have to add the 'return' querystring via JS.
  288. $customize_url = 'customize.php';
  289. } else {
  290. $customize_url = $default_customize_slug;
  291. }
  292. $submenus_to_update = array(
  293. $default_customize_slug => $customize_url,
  294. $default_customize_header_slug_1 => add_query_arg( array( 'autofocus' => array( 'control' => 'header_image' ) ), $customize_url ),
  295. $default_customize_header_slug_2 => add_query_arg( array( 'autofocus' => array( 'control' => 'header_image' ) ), $customize_url ),
  296. $default_customize_background_slug_1 => add_query_arg( array( 'autofocus' => array( 'section' => 'colors_manager_tool' ) ), $customize_url ),
  297. $default_customize_background_slug_2 => add_query_arg( array( 'autofocus' => array( 'section' => 'colors_manager_tool' ) ), $customize_url ),
  298. 'widgets.php' => add_query_arg( array( 'autofocus' => array( 'panel' => 'widgets' ) ), $customize_url ),
  299. 'gutenberg-widgets' => add_query_arg( array( 'autofocus' => array( 'panel' => 'widgets' ) ), $customize_url ),
  300. 'nav-menus.php' => add_query_arg( array( 'autofocus' => array( 'panel' => 'nav_menus' ) ), $customize_url ),
  301. );
  302. if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'themes.php' ) ) {
  303. $submenus_to_update['themes.php'] = 'https://wordpress.com/themes/' . $this->domain;
  304. }
  305. $this->update_submenus( 'themes.php', $submenus_to_update );
  306. $this->hide_submenu_page( 'themes.php', 'custom-header' );
  307. $this->hide_submenu_page( 'themes.php', 'custom-background' );
  308. return $customize_url;
  309. }
  310. /**
  311. * Adds Plugins menu.
  312. */
  313. public function add_plugins_menu() {
  314. if ( self::CLASSIC_VIEW === $this->get_preferred_view( 'plugins.php' ) ) {
  315. return;
  316. }
  317. $this->hide_submenu_page( 'plugins.php', 'plugin-install.php' );
  318. $this->hide_submenu_page( 'plugins.php', 'plugin-editor.php' );
  319. $this->update_menu( 'plugins.php', 'https://wordpress.com/plugins/' . $this->domain );
  320. }
  321. /**
  322. * Adds Users menu.
  323. */
  324. public function add_users_menu() {
  325. $submenus_to_update = array(
  326. 'profile.php' => 'https://wordpress.com/me',
  327. );
  328. if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'users.php' ) ) {
  329. $submenus_to_update['users.php'] = 'https://wordpress.com/people/team/' . $this->domain;
  330. $submenus_to_update['user-new.php'] = 'https://wordpress.com/people/new/' . $this->domain;
  331. }
  332. $slug = current_user_can( 'list_users' ) ? 'users.php' : 'profile.php';
  333. $this->update_submenus( $slug, $submenus_to_update );
  334. add_submenu_page( $slug, esc_attr__( 'Account Settings', 'jetpack' ), __( 'Account Settings', 'jetpack' ), 'read', 'https://wordpress.com/me/account' );
  335. }
  336. /**
  337. * Adds Tools menu.
  338. */
  339. public function add_tools_menu() {
  340. $submenus_to_update = array();
  341. if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'import.php' ) ) {
  342. $submenus_to_update['import.php'] = 'https://wordpress.com/import/' . $this->domain;
  343. }
  344. if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'export.php' ) ) {
  345. $submenus_to_update['export.php'] = 'https://wordpress.com/export/' . $this->domain;
  346. }
  347. $this->update_submenus( 'tools.php', $submenus_to_update );
  348. $this->hide_submenu_page( 'tools.php', 'tools.php' );
  349. $this->hide_submenu_page( 'tools.php', 'delete-blog' );
  350. add_submenu_page( 'tools.php', esc_attr__( 'Marketing', 'jetpack' ), __( 'Marketing', 'jetpack' ), 'publish_posts', 'https://wordpress.com/marketing/tools/' . $this->domain, null, 0 );
  351. add_submenu_page( 'tools.php', esc_attr__( 'Earn', 'jetpack' ), __( 'Earn', 'jetpack' ), 'manage_options', 'https://wordpress.com/earn/' . $this->domain, null, 1 );
  352. }
  353. /**
  354. * Adds Settings menu.
  355. */
  356. public function add_options_menu() {
  357. $submenus_to_update = array();
  358. $this->hide_submenu_page( 'options-general.php', 'sharing' );
  359. if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'options-general.php' ) ) {
  360. $submenus_to_update['options-general.php'] = 'https://wordpress.com/settings/general/' . $this->domain;
  361. }
  362. if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'options-writing.php' ) ) {
  363. $submenus_to_update['options-writing.php'] = 'https://wordpress.com/settings/writing/' . $this->domain;
  364. }
  365. if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'options-discussion.php' ) ) {
  366. $submenus_to_update['options-discussion.php'] = 'https://wordpress.com/settings/discussion/' . $this->domain;
  367. }
  368. $this->update_submenus( 'options-general.php', $submenus_to_update );
  369. add_submenu_page( 'options-general.php', esc_attr__( 'Performance', 'jetpack' ), __( 'Performance', 'jetpack' ), 'manage_options', 'https://wordpress.com/settings/performance/' . $this->domain, null, 1 );
  370. }
  371. /**
  372. * Adds Jetpack menu.
  373. */
  374. public function add_jetpack_menu() {
  375. $this->add_admin_menu_separator( 50, 'manage_options' );
  376. // TODO: Replace with proper SVG data url.
  377. $icon = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 40 40' %3E%3Cpath fill='%23a0a5aa' d='M20 0c11.046 0 20 8.954 20 20s-8.954 20-20 20S0 31.046 0 20 8.954 0 20 0zm11 17H21v19l10-19zM19 4L9 23h10V4z'/%3E%3C/svg%3E";
  378. $is_menu_updated = $this->update_menu( 'jetpack', null, null, null, $icon, 51 );
  379. if ( ! $is_menu_updated ) {
  380. add_menu_page( esc_attr__( 'Jetpack', 'jetpack' ), __( 'Jetpack', 'jetpack' ), 'manage_options', 'jetpack', null, $icon, 51 );
  381. }
  382. add_submenu_page( 'jetpack', esc_attr__( 'Activity Log', 'jetpack' ), __( 'Activity Log', 'jetpack' ), 'manage_options', 'https://wordpress.com/activity-log/' . $this->domain, null, 2 );
  383. add_submenu_page( 'jetpack', esc_attr__( 'Backup', 'jetpack' ), __( 'Backup', 'jetpack' ), 'manage_options', 'https://wordpress.com/backup/' . $this->domain, null, 3 );
  384. /* translators: Jetpack sidebar menu item. */
  385. add_submenu_page( 'jetpack', esc_attr__( 'Search', 'jetpack' ), __( 'Search', 'jetpack' ), 'manage_options', 'https://wordpress.com/jetpack-search/' . $this->domain, null, 4 );
  386. $this->hide_submenu_page( 'jetpack', 'jetpack#/settings' );
  387. $this->hide_submenu_page( 'jetpack', 'stats' );
  388. $this->hide_submenu_page( 'jetpack', esc_url( Redirect::get_url( 'calypso-backups' ) ) );
  389. $this->hide_submenu_page( 'jetpack', esc_url( Redirect::get_url( 'calypso-scanner' ) ) );
  390. if ( ! $is_menu_updated ) {
  391. // Remove the submenu auto-created by Core just to be sure that there no issues on non-admin roles.
  392. remove_submenu_page( 'jetpack', 'jetpack' );
  393. }
  394. }
  395. /**
  396. * Update Site Editor menu item's link and position.
  397. */
  398. public function add_gutenberg_menus() {
  399. if ( self::CLASSIC_VIEW === $this->get_preferred_view( 'admin.php?page=gutenberg-edit-site' ) ) {
  400. return;
  401. }
  402. $this->update_menu( 'gutenberg-edit-site', 'https://wordpress.com/site-editor/' . $this->domain, null, null, null, 59 );
  403. }
  404. /**
  405. * Adds Beta Testing link.
  406. */
  407. public function add_beta_testing_menu() {
  408. $icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTgiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxOCAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTE1LjE5MDEgMTAuODU2N0MxNC45NTc0IDEwLjYyNCAxNC42NjExIDEwLjQ2NTQgMTQuMzM4NCAxMC40MDA4TDEyLjM0OTMgMTAuMDAzM0MxMS4yNTkgOS43ODUzIDEwLjEyNzEgOS45MzY5IDkuMTMyNjIgMTAuNDM0Mkw4Ljg2NzYxIDEwLjU2NThDNy44NzMxMiAxMS4wNjMxIDYuNzQxMjUgMTEuMjE0NyA1LjY1MDk1IDEwLjk5NjdMNC4wNDE3OCAxMC42NzVDMy43NzI3OCAxMC42MjEzIDMuNDk0NjggMTAuNjM0OCAzLjIzMjE0IDEwLjcxNDNDMi45Njk2MSAxMC43OTM4IDIuNzMwNzYgMTAuOTM2OSAyLjUzNjc4IDExLjEzMDhNNC42NjY3OCAxLjMzMzM0SDEzLjMzMzRMMTEuNTAwMSAyLjE2NjY4VjYuNDc2NjhDMTEuNTAwMiA2LjkxODY3IDExLjY3NTkgNy4zNDI1MiAxMS45ODg0IDcuNjU1MDFMMTYuMTU1MSAxMS44MjE3QzE3LjIwNTEgMTIuODcxNyAxNi40NjA5IDE0LjY2NjcgMTQuOTc1OSAxNC42NjY3SDMuMDIzNDVDMS41Mzg0NSAxNC42NjY3IDAuNzk1MTE2IDEyLjg3MTcgMS44NDUxMiAxMS44MjE3TDYuMDExNzggNy42NTUwMUM2LjMyNDM2IDcuMzQyNTIgNi41MDAwMiA2LjkxODY3IDYuNTAwMTEgNi40NzY2OFYyLjE2NjY4TDQuNjY2NzggMS4zMzMzNFoiIHN0cm9rZT0id2hpdGUiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InNxdWFyZSIgc3Ryb2tlLWxpbmVqb2luPSJiZXZlbCIvPgo8cmVjdCB4PSIxLjcyNzU0IiB5PSIxMC43MjczIiB3aWR0aD0iMTQuNTQ1NSIgaGVpZ2h0PSIzLjYzNjM2IiBmaWxsPSJ3aGl0ZSIvPgo8L3N2Zz4K';
  409. add_menu_page( 'beta-testing', __( 'Beta Testing', 'jetpack' ), 'manage_options', 'https://wordpress.com/beta-testing/' . $this->domain, null, $icon, null );
  410. }
  411. /**
  412. * Prepend a dashboard swithcer to the "Screen Options" box of the current page.
  413. * Callback for the 'screen_settings' filter (available in WP 3.0 and up).
  414. *
  415. * @param string $current The currently added panels in screen options.
  416. *
  417. * @return string The HTML code to append to "Screen Options"
  418. */
  419. public function register_dashboard_switcher( $current ) {
  420. $menu_mappings = require __DIR__ . '/menu-mappings.php';
  421. $screen = $this->get_current_screen();
  422. // Let's show the switcher only in screens that we have a Calypso mapping to switch to.
  423. if ( ! isset( $menu_mappings[ $screen ] ) ) {
  424. return;
  425. }
  426. $contents = sprintf(
  427. '<div id="dashboard-switcher"><h5>%s</h5><p class="dashboard-switcher-text">%s</p><a class="button button-primary dashboard-switcher-button" href="%s">%s</a></div>',
  428. __( 'Screen features', 'jetpack' ),
  429. __( 'Currently you are seeing the classic WP-Admin view of this page. Would you like to see the default WordPress.com view?', 'jetpack' ),
  430. $menu_mappings[ $screen ] . $this->domain,
  431. __( 'Use WordPress.com view', 'jetpack' )
  432. );
  433. // Prepend the Dashboard swither to the other custom panels.
  434. $current = $contents . $current;
  435. return $current;
  436. }
  437. }