| @@ -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,44 +40,36 @@ | ||
| 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 | + // WordPress.com Simple sites load this class next to the stats-admin copy in jetpack-mu-wpcom, which can predate register_widget(). | |
| 45 | + if ( method_exists( Dashboard_Stats_Widget::class, 'register_widget' ) ) { | |
| 46 | + // Atomic filters readiness to require a connected owner, which the package's own connection check does not see. | |
| 47 | + if ( Jetpack::is_connection_ready() && Dashboard_Stats_Widget::register_widget() ) { | |
| 48 | + add_action( 'admin_head', array( static::class, 'admin_head' ) ); | |
| 49 | + } | |
| 50 | + return; | |
| 51 | + } | |
| 44 | 52 | |
| 45 | - /** | |
| 46 | - * Filter whether the Jetpack Stats dashboard widget should be shown to the current user. | |
| 47 | - * By default, the dashboard widget is shown to users who can view_stats. | |
| 48 | - * | |
| 49 | - * @module stats | |
| 50 | - * @since 11.9 | |
| 51 | - * | |
| 52 | - * @param bool Whether to show the widget to the current user. | |
| 53 | - */ | |
| 54 | - if ( ! apply_filters( 'jetpack_stats_dashboard_widget_show_to_user', current_user_can( 'view_stats' ) ) ) { | |
| 53 | + /** This filter is documented in projects/packages/stats-admin/src/class-wp-dashboard-odyssey-widget.php */ | |
| 54 | + $can_user_view_stats = current_user_can( 'manage_options' ) || current_user_can( 'view_stats' ); | |
| 55 | + if ( ! apply_filters( 'jetpack_stats_dashboard_widget_show_to_user', $can_user_view_stats ) ) { | |
| 55 | 56 | return; |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | - if ( Jetpack::is_connection_ready() ) { | |
| 59 | + if ( Jetpack::is_connection_ready() && Jetpack::is_module_active( 'stats' ) ) { | |
| 59 | 60 | add_action( 'admin_head', array( static::class, 'admin_head' ) ); |
| 60 | 61 | |
| 61 | - $widget_title = sprintf( | |
| 62 | - __( 'Jetpack Stats', 'jetpack' ) | |
| 63 | - ); | |
| 64 | - | |
| 62 | + // New widget implemented in Odyssey Stats. | |
| 63 | + $stats_widget = new Dashboard_Stats_Widget(); | |
| 65 | 64 | wp_add_dashboard_widget( |
| 66 | - 'jetpack_summary_widget', | |
| 67 | - $widget_title, | |
| 68 | - array( __CLASS__, 'render_widget' ) | |
| 65 | + Dashboard_Stats_Widget::DASHBOARD_WIDGET_ID, | |
| 66 | + /** "Stats" is a product name, do not translate. */ | |
| 67 | + 'Jetpack Stats', | |
| 68 | + array( $stats_widget, 'render' ) | |
| 69 | 69 | ); |
| 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' ); | |
| 70 | + // Only load scripts when the widget is not hidden | |
| 71 | + $stats_widget->maybe_load_admin_scripts(); | |
| 80 | 72 | } |
| 81 | 73 | } |
| 82 | 74 | |
| 83 | 75 | /** |
| @@ -183,10 +175,10 @@ | ||
| 183 | 175 | 'jetpack_activate-protect' |
| 184 | 176 | ) |
| 185 | 177 | ); |
| 186 | 178 | ?> |
| 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' ); ?> | |
| 179 | + " class="button button-primary" title="<?php esc_attr_e( 'Jetpack helps to keep you secure from brute-force login attacks.', 'jetpack' ); ?>"> | |
| 180 | + <?php esc_html_e( 'Activate', 'jetpack' ); ?> | |
| 189 | 181 | </a> |
| 190 | 182 | <?php else : ?> |
| 191 | 183 | <?php esc_html_e( 'Brute force attack protection is inactive.', 'jetpack' ); ?> |
| 192 | 184 | <?php endif; ?> |
| @@ -214,10 +206,10 @@ | ||
| 214 | 206 | 'activate-plugin_akismet/akismet.php' |
| 215 | 207 | ) |
| 216 | 208 | ); |
| 217 | 209 | ?> |
| 218 | - " class="button button-jetpack"> | |
| 219 | - <?php esc_html_e( 'Activate Anti-spam', 'jetpack' ); ?> | |
| 210 | + " class="button button-primary"> | |
| 211 | + <?php esc_html_e( 'Activate', 'jetpack' ); ?> | |
| 220 | 212 | </a> |
| 221 | 213 | <?php else : ?> |
| 222 | 214 | <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 | 215 | <?php endif; ?> |