| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Scan; |
| 9 | 9 | |
| 10 | +use Automattic\Jetpack\Admin_UI\Admin_Menu; | |
| 10 | 11 | use Automattic\Jetpack\My_Jetpack\Products\Backup; |
| 11 | 12 | use Automattic\Jetpack\Redirect; |
| 12 | 13 | use Automattic\Jetpack\Status\Host; |
| 13 | 14 | use Jetpack_Core_Json_Api_Endpoints; |
| @@ -67,43 +68,46 @@ | ||
| 67 | 68 | return; |
| 68 | 69 | } |
| 69 | 70 | |
| 70 | 71 | if ( $this->should_show_scan() ) { |
| 71 | - $menu_label = __( 'Scan', 'jetpack' ); | |
| 72 | - $url = Redirect::get_url( 'calypso-scanner' ); | |
| 73 | - add_submenu_page( 'jetpack', $menu_label, esc_html( $menu_label ) . ' <span class="dashicons dashicons-external"></span>', 'manage_options', esc_url( $url ), null, $this->get_link_offset() ); | |
| 72 | + Admin_Menu::add_menu( | |
| 73 | + /** "Scan" is a product name, do not translate. */ | |
| 74 | + 'Scan', | |
| 75 | + 'Scan <span aria-hidden="true">↗</span>', | |
| 76 | + 'manage_options', | |
| 77 | + esc_url( Redirect::get_url( 'cloud-scan-history-wp-menu' ) ), | |
| 78 | + null, | |
| 79 | + Admin_Menu::POSITION_EXTERNAL, | |
| 80 | + array( 'key' => 'jetpack-scan-cloud' ) | |
| 81 | + ); | |
| 74 | 82 | } |
| 75 | 83 | |
| 76 | - if ( $this->should_show_backup() ) { | |
| 77 | - $menu_label = __( 'VaultPress', 'jetpack' ); | |
| 78 | - $url = Redirect::get_url( 'calypso-backups' ); | |
| 79 | - add_submenu_page( 'jetpack', $menu_label, esc_html( $menu_label ) . ' <span class="dashicons dashicons-external"></span>', 'manage_options', esc_url( $url ), null, $this->get_link_offset() ); | |
| 84 | + // Add scan item which shows history page only. This is mutally exclusive from the scan item above and is only shown for Atomic sitse. | |
| 85 | + if ( $this->should_show_scan_history_only() ) { | |
| 86 | + Admin_Menu::add_menu( | |
| 87 | + /** "Scan" is a product name, do not translate. */ | |
| 88 | + 'Scan', | |
| 89 | + 'Scan <span aria-hidden="true">↗</span>', | |
| 90 | + 'manage_options', | |
| 91 | + esc_url( Redirect::get_url( 'cloud-scan-history-wp-menu' ) ), | |
| 92 | + null, | |
| 93 | + Admin_Menu::POSITION_EXTERNAL, | |
| 94 | + array( 'key' => 'jetpack-scan-cloud' ) | |
| 95 | + ); | |
| 80 | 96 | } |
| 81 | - } | |
| 82 | 97 | |
| 83 | - /** | |
| 84 | - * We create a menu offset by counting all the pages that have a jetpack_admin_page set as the capability. | |
| 85 | - * | |
| 86 | - * This makes it so that the highlight of the pages works as expected. When you click on the Setting or Dashboard. | |
| 87 | - * | |
| 88 | - * @return int Menu offset. | |
| 89 | - */ | |
| 90 | - private function get_link_offset() { | |
| 91 | - global $submenu; | |
| 92 | - $offset = 0; | |
| 93 | - | |
| 94 | - if ( ! array_key_exists( 'jetpack', $submenu ) ) { | |
| 95 | - return $offset; | |
| 98 | + if ( $this->should_show_backup() ) { | |
| 99 | + Admin_Menu::add_menu( | |
| 100 | + /** "VaultPress Backup" is a product name, do not translate. */ | |
| 101 | + 'VaultPress Backup', | |
| 102 | + 'VaultPress Backup <span aria-hidden="true">↗</span>', | |
| 103 | + 'manage_options', | |
| 104 | + esc_url( Redirect::get_url( 'calypso-backups' ) ), | |
| 105 | + null, | |
| 106 | + Admin_Menu::POSITION_EXTERNAL, | |
| 107 | + array( 'key' => 'jetpack-backup-cloud' ) | |
| 108 | + ); | |
| 96 | 109 | } |
| 97 | - | |
| 98 | - foreach ( $submenu['jetpack'] as $link ) { | |
| 99 | - if ( 'jetpack_admin_page' !== $link[1] ) { | |
| 100 | - break; | |
| 101 | - } | |
| 102 | - ++$offset; | |
| 103 | - } | |
| 104 | - | |
| 105 | - return $offset; | |
| 106 | 110 | } |
| 107 | 111 | |
| 108 | 112 | /** |
| 109 | 113 | * Refreshes the state cache via API call. Called via cron. |
| @@ -129,9 +133,9 @@ | ||
| 129 | 133 | if ( class_exists( 'VaultPress' ) ) { |
| 130 | 134 | return false; |
| 131 | 135 | } |
| 132 | 136 | |
| 133 | - return $this->should_show_scan() || $this->should_show_backup(); | |
| 137 | + return $this->should_show_scan() || $this->should_show_backup() || $this->should_show_scan_history_only(); | |
| 134 | 138 | } |
| 135 | 139 | |
| 136 | 140 | /** |
| 137 | 141 | * Check if we should display the Scan menu item. |
| @@ -141,8 +145,19 @@ | ||
| 141 | 145 | * @return boolean |
| 142 | 146 | */ |
| 143 | 147 | private function should_show_scan() { |
| 144 | 148 | return $this->has_scan() && ! $this->has_protect_plugin() && ! ( new Host() )->is_woa_site(); |
| 149 | + } | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * Check if we should display the Scan menu item history. | |
| 153 | + * | |
| 154 | + * It will only be displayed if site has Scan enabled, is an Atomic site. | |
| 155 | + * | |
| 156 | + * @return boolean | |
| 157 | + */ | |
| 158 | + private function should_show_scan_history_only() { | |
| 159 | + return $this->has_scan() && ( new Host() )->is_woa_site() && get_option( 'wpcom_admin_interface' ) === 'wp-admin'; | |
| 145 | 160 | } |
| 146 | 161 | |
| 147 | 162 | /** |
| 148 | 163 | * Check if we should display the Backup menu item. |