PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | modules/scan/class-admin-sidebar-link.php +49 -32 12.7.3 → 16.3-a.5 View file →
@@ -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;
@@ -66,44 +67,49 @@
66 67 if ( ! $this->should_show_link() ) {
67 68 return;
68 69 }
69 70
71 + $position = defined( Admin_Menu::class . '::POSITION_EXTERNAL' ) ? Admin_Menu::POSITION_EXTERNAL : 100;
72 +
70 73 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() );
74 + Admin_Menu::add_menu(
75 + /** "Scan" is a product name, do not translate. */
76 + 'Scan',
77 + 'Scan <span aria-hidden="true">↗</span>',
78 + 'manage_options',
79 + esc_url( Redirect::get_url( 'cloud-scan-history-wp-menu' ) ),
80 + null,
81 + $position,
82 + array( 'key' => 'jetpack-scan-cloud' )
83 + );
74 84 }
75 85
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() );
86 + // Add scan item which shows history page only. This is mutally exclusive from the scan item above and is only shown for Atomic sitse.
87 + if ( $this->should_show_scan_history_only() ) {
88 + Admin_Menu::add_menu(
89 + /** "Scan" is a product name, do not translate. */
90 + 'Scan',
91 + 'Scan <span aria-hidden="true">↗</span>',
92 + 'manage_options',
93 + esc_url( Redirect::get_url( 'cloud-scan-history-wp-menu' ) ),
94 + null,
95 + $position,
96 + array( 'key' => 'jetpack-scan-cloud' )
97 + );
80 98 }
81 - }
82 99
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;
100 + if ( $this->should_show_backup() ) {
101 + Admin_Menu::add_menu(
102 + /** "VaultPress Backup" is a product name, do not translate. */
103 + 'VaultPress Backup',
104 + 'VaultPress Backup <span aria-hidden="true">↗</span>',
105 + 'manage_options',
106 + esc_url( Redirect::get_url( 'calypso-backups' ) ),
107 + null,
108 + $position,
109 + array( 'key' => 'jetpack-backup-cloud' )
110 + );
96 111 }
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 112 }
107 113
108 114 /**
109 115 * Refreshes the state cache via API call. Called via cron.
@@ -129,9 +135,9 @@
129 135 if ( class_exists( 'VaultPress' ) ) {
130 136 return false;
131 137 }
132 138
133 - return $this->should_show_scan() || $this->should_show_backup();
139 + return $this->should_show_scan() || $this->should_show_backup() || $this->should_show_scan_history_only();
134 140 }
135 141
136 142 /**
137 143 * Check if we should display the Scan menu item.
@@ -144,8 +150,19 @@
144 150 return $this->has_scan() && ! $this->has_protect_plugin() && ! ( new Host() )->is_woa_site();
145 151 }
146 152
147 153 /**
154 + * Check if we should display the Scan menu item history.
155 + *
156 + * It will only be displayed if site has Scan enabled, is an Atomic site.
157 + *
158 + * @return boolean
159 + */
160 + private function should_show_scan_history_only() {
161 + return $this->has_scan() && ( new Host() )->is_woa_site() && get_option( 'wpcom_admin_interface' ) === 'wp-admin';
162 + }
163 +
164 + /**
148 165 * Check if we should display the Backup menu item.
149 166 *
150 167 * It will only be displayed if site has Backup enabled and the stand-alone Backup plugin is not active, because it will have a menu item of its own.
151 168 *
@@ -199,9 +216,9 @@
199 216 *
200 217 * @return boolean
201 218 */
202 219 private function has_backup_plugin() {
203 - return Backup::is_active();
220 + return Backup::is_standalone_plugin_active();
204 221 }
205 222
206 223 /**
207 224 * Triggers a cron job to refresh the Scan and Rewind state cache.