| @@ -4,11 +4,11 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package jetpack |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -use Automattic\Jetpack\Assets; | |
| 9 | 8 | use Automattic\Jetpack\Assets\Logo as Jetpack_Logo; |
| 10 | 9 | use Automattic\Jetpack\Redirect; |
| 10 | +use Automattic\Jetpack\Stats_Admin\WP_Dashboard_Odyssey_Widget as Dashboard_Stats_Widget; | |
| 11 | 11 | use Automattic\Jetpack\Status; |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Class that adds the Jetpack stats widget to the WordPress admin dashboard. |
| @@ -40,9 +40,8 @@ | ||
| 40 | 40 | /** |
| 41 | 41 | * Sets up the Jetpack Stats widget in the WordPress admin dashboard. |
| 42 | 42 | */ |
| 43 | 43 | public static function wp_dashboard_setup() { |
| 44 | - | |
| 45 | 44 | /** |
| 46 | 45 | * Filter whether the Jetpack Stats dashboard widget should be shown to the current user. |
| 47 | 46 | * By default, the dashboard widget is shown to users who can view_stats. |
| 48 | 47 | * |
| @@ -50,34 +49,28 @@ | ||
| 50 | 49 | * @since 11.9 |
| 51 | 50 | * |
| 52 | 51 | * @param bool Whether to show the widget to the current user. |
| 53 | 52 | */ |
| 54 | - if ( ! apply_filters( 'jetpack_stats_dashboard_widget_show_to_user', current_user_can( 'view_stats' ) ) ) { | |
| 53 | + // Temporarily show the widget to administrators for Simple sites as the view_stats capability is not available. | |
| 54 | + // TODO: Grant the view_stats capability to corresponding users for Simple sites. | |
| 55 | + $can_user_view_stats = current_user_can( 'manage_options' ) || current_user_can( 'view_stats' ); | |
| 56 | + if ( ! apply_filters( 'jetpack_stats_dashboard_widget_show_to_user', $can_user_view_stats ) ) { | |
| 55 | 57 | return; |
| 56 | 58 | } |
| 57 | 59 | |
| 58 | - if ( Jetpack::is_connection_ready() ) { | |
| 60 | + if ( Jetpack::is_connection_ready() && Jetpack::is_module_active( 'stats' ) ) { | |
| 59 | 61 | add_action( 'admin_head', array( static::class, 'admin_head' ) ); |
| 60 | 62 | |
| 61 | - $widget_title = sprintf( | |
| 62 | - __( 'Jetpack Stats', 'jetpack' ) | |
| 63 | - ); | |
| 64 | - | |
| 63 | + // New widget implemented in Odyssey Stats. | |
| 64 | + $stats_widget = new Dashboard_Stats_Widget(); | |
| 65 | 65 | wp_add_dashboard_widget( |
| 66 | - 'jetpack_summary_widget', | |
| 67 | - $widget_title, | |
| 68 | - array( __CLASS__, 'render_widget' ) | |
| 66 | + Dashboard_Stats_Widget::DASHBOARD_WIDGET_ID, | |
| 67 | + /** "Stats" is a product name, do not translate. */ | |
| 68 | + 'Jetpack Stats', | |
| 69 | + array( $stats_widget, 'render' ) | |
| 69 | 70 | ); |
| 70 | - wp_enqueue_style( | |
| 71 | - 'jetpack-dashboard-widget', | |
| 72 | - Assets::get_file_url_for_environment( | |
| 73 | - 'css/dashboard-widget.min.css', | |
| 74 | - 'css/dashboard-widget.css' | |
| 75 | - ), | |
| 76 | - array(), | |
| 77 | - JETPACK__VERSION | |
| 78 | - ); | |
| 79 | - wp_style_add_data( 'jetpack-dashboard-widget', 'rtl', 'replace' ); | |
| 71 | + // Only load scripts when the widget is not hidden | |
| 72 | + $stats_widget->maybe_load_admin_scripts(); | |
| 80 | 73 | } |
| 81 | 74 | } |
| 82 | 75 | |
| 83 | 76 | /** |
| @@ -183,10 +176,10 @@ | ||
| 183 | 176 | 'jetpack_activate-protect' |
| 184 | 177 | ) |
| 185 | 178 | ); |
| 186 | 179 | ?> |
| 187 | - " class="button button-jetpack" title="<?php esc_attr_e( 'Protect helps to keep you secure from brute-force login attacks.', 'jetpack' ); ?>"> | |
| 188 | - <?php esc_html_e( 'Activate brute force attack protection', 'jetpack' ); ?> | |
| 180 | + " class="button button-primary" title="<?php esc_attr_e( 'Jetpack helps to keep you secure from brute-force login attacks.', 'jetpack' ); ?>"> | |
| 181 | + <?php esc_html_e( 'Activate', 'jetpack' ); ?> | |
| 189 | 182 | </a> |
| 190 | 183 | <?php else : ?> |
| 191 | 184 | <?php esc_html_e( 'Brute force attack protection is inactive.', 'jetpack' ); ?> |
| 192 | 185 | <?php endif; ?> |
| @@ -214,10 +207,10 @@ | ||
| 214 | 207 | 'activate-plugin_akismet/akismet.php' |
| 215 | 208 | ) |
| 216 | 209 | ); |
| 217 | 210 | ?> |
| 218 | - " class="button button-jetpack"> | |
| 219 | - <?php esc_html_e( 'Activate Anti-spam', 'jetpack' ); ?> | |
| 211 | + " class="button button-primary"> | |
| 212 | + <?php esc_html_e( 'Activate', 'jetpack' ); ?> | |
| 220 | 213 | </a> |
| 221 | 214 | <?php else : ?> |
| 222 | 215 | <p><a href="<?php echo esc_url( 'https://akismet.com/?utm_source=jetpack&utm_medium=link&utm_campaign=Jetpack%20Dashboard%20Widget%20Footer%20Link' ); ?>"><?php esc_html_e( 'Anti-spam can help to keep your blog safe from spam!', 'jetpack' ); ?></a></p> |
| 223 | 216 | <?php endif; ?> |