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 +30 -77 13.6.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,56 +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 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.
77 86 if ( $this->should_show_scan_history_only() ) {
78 - $menu_label = __( 'Scan', 'jetpack' );
79 - $url = Redirect::get_url( 'cloud-scan-history-wp-menu' );
80 - 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() );
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 + );
81 97 }
82 -
83 - if ( $this->should_show_backup() ) {
84 - $menu_label = __( 'VaultPress', 'jetpack' );
85 - $url = Redirect::get_url( 'calypso-backups' );
86 - 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() );
87 - }
88 98 }
89 99
90 100 /**
91 - * 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.
92 102 *
93 - * This makes it so that the highlight of the pages works as expected. When you click on the Setting or Dashboard.
94 - *
95 - * @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.
96 105 */
97 - private function get_link_offset() {
98 - global $submenu;
99 - $offset = 0;
100 -
101 - if ( ! array_key_exists( 'jetpack', $submenu ) ) {
102 - return $offset;
103 - }
104 -
105 - foreach ( $submenu['jetpack'] as $link ) {
106 - if ( 'jetpack_admin_page' !== $link[1] ) {
107 - break;
108 - }
109 - ++$offset;
110 - }
111 -
112 - return $offset;
113 - }
114 -
115 - /**
116 - * Refreshes the state cache via API call. Called via cron.
117 - */
118 106 public function refresh_state_cache() {
119 107 Jetpack_Core_Json_Api_Endpoints::get_scan_state();
120 108 Jetpack_Core_Json_Api_Endpoints::get_rewind_data();
121 109 }
@@ -125,9 +113,9 @@
125 113 *
126 114 * @return boolean
127 115 */
128 116 private function should_show_link() {
129 - // Jetpack Scan/Backup is currently not supported on multisite.
117 + // Jetpack Scan is currently not supported on multisite.
130 118 if ( is_multisite() ) {
131 119 return false;
132 120 }
133 121
@@ -136,9 +124,9 @@
136 124 if ( class_exists( 'VaultPress' ) ) {
137 125 return false;
138 126 }
139 127
140 - return $this->should_show_scan() || $this->should_show_backup() || $this->should_show_scan_history_only();
128 + return $this->should_show_scan() || $this->should_show_scan_history_only();
141 129 }
142 130
143 131 /**
144 132 * Check if we should display the Scan menu item.
@@ -162,19 +150,8 @@
162 150 return $this->has_scan() && ( new Host() )->is_woa_site() && get_option( 'wpcom_admin_interface' ) === 'wp-admin';
163 151 }
164 152
165 153 /**
166 - * Check if we should display the Backup menu item.
167 - *
168 - * 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.
169 - *
170 - * @return boolean
171 - */
172 - private function should_show_backup() {
173 - return $this->has_backup() && ! $this->has_backup_plugin();
174 - }
175 -
176 - /**
177 154 * Detects if Scan is enabled.
178 155 *
179 156 * @return boolean
180 157 */
@@ -194,32 +171,8 @@
194 171 * @return boolean
195 172 */
196 173 private function has_protect_plugin() {
197 174 return class_exists( 'Jetpack_Protect' );
198 - }
199 -
200 - /**
201 - * Detects if Backup is enabled.
202 - *
203 - * @return boolean
204 - */
205 - private function has_backup() {
206 - $this->maybe_refresh_transient_cache();
207 - $rewind_state = get_transient( 'jetpack_rewind_state' );
208 - if ( ! $rewind_state ) {
209 - return false;
210 - }
211 -
212 - return isset( $rewind_state->state ) && 'unavailable' !== $rewind_state->state;
213 - }
214 -
215 - /**
216 - * Detects if Backup plugin is active.
217 - *
218 - * @return boolean
219 - */
220 - private function has_backup_plugin() {
221 - return Backup::is_standalone_plugin_active();
222 175 }
223 176
224 177 /**
225 178 * Triggers a cron job to refresh the Scan and Rewind state cache.