PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
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 +36 -65 12.5.2 → 16.3-a.7 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * A class that adds a scan and backup link to the admin sidebar.
3 + * A class that adds a scan link to the admin sidebar.
4 4 *
5 5 * @package automattic/jetpack
6 6 */
7 7
@@ -6,9 +6,9 @@
6 6 */
7 7
8 8 namespace Automattic\Jetpack\Scan;
9 9
10 -use Automattic\Jetpack\My_Jetpack\Products\Backup;
10 +use Automattic\Jetpack\Admin_UI\Admin_Menu;
11 11 use Automattic\Jetpack\Redirect;
12 12 use Automattic\Jetpack\Status\Host;
13 13 use Jetpack_Core_Json_Api_Endpoints;
14 14
@@ -59,9 +59,9 @@
59 59 add_action( self::SCHEDULE_ACTION_HOOK, array( $this, 'refresh_state_cache' ) );
60 60 }
61 61
62 62 /**
63 - * Adds a link to the Scan and Backup page.
63 + * Adds a link to the Scan page.
64 64 */
65 65 public function maybe_add_admin_link() {
66 66 if ( ! $this->should_show_link() ) {
67 67 return;
@@ -66,49 +66,44 @@
66 66 if ( ! $this->should_show_link() ) {
67 67 return;
68 68 }
69 69
70 + $position = defined( Admin_Menu::class . '::POSITION_EXTERNAL' ) ? Admin_Menu::POSITION_EXTERNAL : 100;
71 +
70 72 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() );
73 + Admin_Menu::add_menu(
74 + /** "Scan" is a product name, do not translate. */
75 + 'Scan',
76 + 'Scan <span aria-hidden="true">↗</span>',
77 + 'manage_options',
78 + esc_url( Redirect::get_url( 'cloud-scan-history-wp-menu' ) ),
79 + null,
80 + $position,
81 + array( 'key' => 'jetpack-scan-cloud' )
82 + );
74 83 }
75 84
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() );
85 + // Add scan item which shows history page only. This is mutally exclusive from the scan item above and is only shown for Atomic sitse.
86 + if ( $this->should_show_scan_history_only() ) {
87 + Admin_Menu::add_menu(
88 + /** "Scan" is a product name, do not translate. */
89 + 'Scan',
90 + 'Scan <span aria-hidden="true">↗</span>',
91 + 'manage_options',
92 + esc_url( Redirect::get_url( 'cloud-scan-history-wp-menu' ) ),
93 + null,
94 + $position,
95 + array( 'key' => 'jetpack-scan-cloud' )
96 + );
80 97 }
81 98 }
82 99
83 100 /**
84 - * We create a menu offset by counting all the pages that have a jetpack_admin_page set as the capability.
101 + * Refreshes the state cache via API call. Called via cron.
85 102 *
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.
103 + * Still warms the rewind state, which this class no longer reads itself:
104 + * Jetpack_Core_Json_Api_Endpoints::rewind_data() serves it from that cache.
89 105 */
90 - private function get_link_offset() {
91 - global $submenu;
92 - $offset = 0;
93 -
94 - if ( ! array_key_exists( 'jetpack', $submenu ) ) {
95 - return $offset;
96 - }
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 - }
107 -
108 - /**
109 - * Refreshes the state cache via API call. Called via cron.
110 - */
111 106 public function refresh_state_cache() {
112 107 Jetpack_Core_Json_Api_Endpoints::get_scan_state();
113 108 Jetpack_Core_Json_Api_Endpoints::get_rewind_data();
114 109 }
@@ -118,9 +113,9 @@
118 113 *
119 114 * @return boolean
120 115 */
121 116 private function should_show_link() {
122 - // Jetpack Scan/Backup is currently not supported on multisite.
117 + // Jetpack Scan is currently not supported on multisite.
123 118 if ( is_multisite() ) {
124 119 return false;
125 120 }
126 121
@@ -129,9 +124,9 @@
129 124 if ( class_exists( 'VaultPress' ) ) {
130 125 return false;
131 126 }
132 127
133 - return $this->should_show_scan() || $this->should_show_backup();
128 + return $this->should_show_scan() || $this->should_show_scan_history_only();
134 129 }
135 130
136 131 /**
137 132 * Check if we should display the Scan menu item.
@@ -144,16 +139,16 @@
144 139 return $this->has_scan() && ! $this->has_protect_plugin() && ! ( new Host() )->is_woa_site();
145 140 }
146 141
147 142 /**
148 - * Check if we should display the Backup menu item.
143 + * Check if we should display the Scan menu item history.
149 144 *
150 - * 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.
145 + * It will only be displayed if site has Scan enabled, is an Atomic site.
151 146 *
152 147 * @return boolean
153 148 */
154 - private function should_show_backup() {
155 - return $this->has_backup() && ! $this->has_backup_plugin();
149 + private function should_show_scan_history_only() {
150 + return $this->has_scan() && ( new Host() )->is_woa_site() && get_option( 'wpcom_admin_interface' ) === 'wp-admin';
156 151 }
157 152
158 153 /**
159 154 * Detects if Scan is enabled.
@@ -176,32 +171,8 @@
176 171 * @return boolean
177 172 */
178 173 private function has_protect_plugin() {
179 174 return class_exists( 'Jetpack_Protect' );
180 - }
181 -
182 - /**
183 - * Detects if Backup is enabled.
184 - *
185 - * @return boolean
186 - */
187 - private function has_backup() {
188 - $this->maybe_refresh_transient_cache();
189 - $rewind_state = get_transient( 'jetpack_rewind_state' );
190 - if ( ! $rewind_state ) {
191 - return false;
192 - }
193 -
194 - return isset( $rewind_state->state ) && 'unavailable' !== $rewind_state->state;
195 - }
196 -
197 - /**
198 - * Detects if Backup plugin is active.
199 - *
200 - * @return boolean
201 - */
202 - private function has_backup_plugin() {
203 - return Backup::is_active();
204 175 }
205 176
206 177 /**
207 178 * Triggers a cron job to refresh the Scan and Rewind state cache.