Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 60 |
|
0.00% |
0 / 2 |
CRAP | n/a |
0 / 0 |
|
| wpcom_p2_admin_menu_init | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| wpcom_remove_menus_for_p2_sites | |
0.00% |
0 / 54 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Handle the admin menu on P2 sites. |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Initializes the admin menu hooks for P2 sites. |
| 10 | */ |
| 11 | function wpcom_p2_admin_menu_init() { |
| 12 | $blog_id = get_current_blog_id(); |
| 13 | require_once WP_CONTENT_DIR . '/lib/wpforteams/functions.php'; |
| 14 | if ( \WPForTeams\is_wpforteams_site( $blog_id ) ) { |
| 15 | add_action( 'admin_menu', 'wpcom_remove_menus_for_p2_sites', 999999 ); |
| 16 | } |
| 17 | } |
| 18 | add_action( 'init', 'wpcom_p2_admin_menu_init' ); |
| 19 | add_action( 'rest_api_switched_to_blog', 'wpcom_p2_admin_menu_init' ); |
| 20 | |
| 21 | /** |
| 22 | * Removes a bunch of menus that shouldn't be visible on P2 sites. |
| 23 | */ |
| 24 | function wpcom_remove_menus_for_p2_sites() { |
| 25 | $domain = ( new \Automattic\Jetpack\Status() )->get_site_suffix(); |
| 26 | |
| 27 | remove_menu_page( 'jetpack' ); |
| 28 | remove_menu_page( 'link-manager.php' ); |
| 29 | remove_menu_page( 'feedback' ); |
| 30 | remove_menu_page( 'plugins.php' ); |
| 31 | remove_menu_page( 'https://wordpress.com/plugins/' . $domain ); |
| 32 | remove_submenu_page( 'tools.php', 'tools.php' ); |
| 33 | remove_submenu_page( 'tools.php', 'wpcom-marketing-tools' ); |
| 34 | remove_submenu_page( 'tools.php', 'wpcom-site-health' ); |
| 35 | remove_submenu_page( 'tools.php', 'wpcom-export-personal-data' ); |
| 36 | remove_submenu_page( 'tools.php', 'wpcom-erase-personal-data' ); |
| 37 | remove_submenu_page( 'tools.php', 'theme-editor' ); |
| 38 | remove_submenu_page( 'tools.php', 'plugin-editor' ); |
| 39 | remove_submenu_page( 'options-general.php', 'options-permalink' ); |
| 40 | remove_submenu_page( 'options-general.php', 'options-privacy' ); |
| 41 | remove_submenu_page( 'options-general.php', 'sharing' ); |
| 42 | remove_submenu_page( 'options-general.php', 'crowdsignal-settings' ); |
| 43 | remove_submenu_page( 'options-general.php', 'ratingsettings' ); |
| 44 | remove_submenu_page( 'options-general.php', 'activitypub' ); |
| 45 | |
| 46 | require_once WP_CONTENT_DIR . '/lib/wpforteams/functions.php'; |
| 47 | |
| 48 | $blog_id = get_current_blog_id(); |
| 49 | $is_hub = \WPForTeams\Workspace\is_workspace_hub( $blog_id ); |
| 50 | |
| 51 | if ( $is_hub ) { |
| 52 | remove_menu_page( 'index.php' ); |
| 53 | remove_menu_page( "https://wordpress.com/home/$domain" ); |
| 54 | remove_menu_page( 'stats' ); |
| 55 | remove_submenu_page( 'paid-upgrades.php', "https://wordpress.com/domains/manage/$domain" ); |
| 56 | remove_submenu_page( 'paid-upgrades.php', "https://wordpress.com/email/$domain" ); |
| 57 | remove_submenu_page( 'wpcom-hosting-menu', "https://wordpress.com/overview/$domain" ); |
| 58 | remove_submenu_page( 'wpcom-hosting-menu', "https://wordpress.com/email/$domain" ); |
| 59 | remove_submenu_page( 'wpcom-hosting-menu', "https://wordpress.com/domains/manage/$domain" ); |
| 60 | remove_menu_page( 'edit.php' ); |
| 61 | remove_menu_page( 'edit.php?post_type=page' ); |
| 62 | remove_menu_page( 'upload.php' ); |
| 63 | remove_menu_page( 'edit-comments.php' ); |
| 64 | remove_menu_page( 'themes.php' ); |
| 65 | remove_submenu_page( 'tools.php', 'import.php' ); |
| 66 | remove_submenu_page( 'tools.php', 'export.php' ); |
| 67 | remove_submenu_page( 'tools.php', 'export-media-files' ); |
| 68 | remove_submenu_page( 'options-general.php', 'options-reading.php' ); |
| 69 | remove_submenu_page( 'options-general.php', 'options-writing.php' ); |
| 70 | remove_submenu_page( 'options-general.php', 'options-discussion.php' ); |
| 71 | remove_submenu_page( 'options-general.php', 'options-media.php' ); |
| 72 | |
| 73 | // TODO: Untangle this screen |
| 74 | // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539. |
| 75 | add_submenu_page( 'tools.php', __( 'Integrations', 'jetpack-mu-wpcom' ), __( 'Integrations', 'jetpack-mu-wpcom' ), 'manage_options', "https://wordpress.com/marketing/connections/$domain", null, 0 ); |
| 76 | } else { |
| 77 | remove_menu_page( 'paid-upgrades.php' ); |
| 78 | remove_menu_page( 'wpcom-hosting-menu' ); |
| 79 | |
| 80 | $is_api_request = defined( 'REST_REQUEST' ) && REST_REQUEST; |
| 81 | if ( $is_api_request ) { |
| 82 | $customize_url = 'customize.php'; |
| 83 | } else { |
| 84 | $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; |
| 85 | $customize_url = add_query_arg( 'return', rawurlencode( remove_query_arg( wp_removable_query_args(), $request_uri ) ), 'customize.php' ); |
| 86 | } |
| 87 | $additional_css_url = add_query_arg( array( 'autofocus' => array( 'section' => 'jetpack_custom_css' ) ), $customize_url ); |
| 88 | |
| 89 | remove_submenu_page( 'themes.php', "https://wordpress.com/themes/$domain?ref=wpcom-themes-menu" ); |
| 90 | remove_submenu_page( 'themes.php', esc_url( $additional_css_url ) ); |
| 91 | } |
| 92 | } |