|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * WordPress.com Site Menu |
| 4 | + * |
| 5 | + * Add's a WordPress.com menu item to the admin menu linking back to the sites WordPress.com home page. |
| 6 | + * |
| 7 | + * @package automattic/jetpack-mu-wpcom |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * Add a WordPress.com menu item to the wp-admin sidebar menu. |
| 12 | + */ |
| 13 | +function wpcom_add_wpcom_menu_item() { |
| 14 | + if ( function_exists( 'wpcom_is_nav_redesign_enabled' ) && wpcom_is_nav_redesign_enabled() ) { |
| 15 | + $domain = wp_parse_url( home_url(), PHP_URL_HOST ); |
| 16 | + add_menu_page( |
| 17 | + esc_attr__( 'WordPress.com', 'jetpack-mu-wpcom' ), |
| 18 | + esc_attr__( 'WordPress.com', 'jetpack-mu-wpcom' ), |
| 19 | + 'manage_options', |
| 20 | + "https://wordpress.com/home/$domain", |
| 21 | + null, |
| 22 | + 'dashicons-arrow-left-alt2', |
| 23 | + 0 |
| 24 | + ); |
| 25 | + |
| 26 | + // Position a separator below the WordPress.com menu item. |
| 27 | + // Inspired by https://github.com/Automattic/jetpack/blob/b6b6e86c5491869782857141ca48168dfa195635/projects/plugins/jetpack/modules/masterbar/admin-menu/class-base-admin-menu.php#L239 |
| 28 | + global $menu; |
| 29 | + $separator = array( |
| 30 | + '', // Menu title (ignored). |
| 31 | + 'manage_options', // Required capability. |
| 32 | + wp_unique_id( 'separator-custom-' ), // URL or file (ignored, but must be unique). |
| 33 | + '', // Page title (ignored). |
| 34 | + 'wp-menu-separator', // CSS class. Identifies this item as a separator. |
| 35 | + ); |
| 36 | + $position = 0; |
| 37 | + if ( isset( $menu[ "$position" ] ) ) { |
| 38 | + $position = $position + substr( base_convert( md5( $separator[2] . $separator[0] ), 16, 10 ), -5 ) * 0.00001; |
| 39 | + $menu[ "$position" ] = $separator; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 40 | + } else { |
| 41 | + $menu[ "$position" ] = $separator; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | +add_action( 'admin_menu', 'wpcom_add_wpcom_menu_item' ); |
0 commit comments