| @@ -40,19 +40,18 @@ | ||
| 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 | - * Filter whether the Jetpack Stats dashboard widget should be shown to the current user. | |
| 46 | - * By default, the dashboard widget is shown to users who can view_stats. | |
| 47 | - * | |
| 48 | - * @module stats | |
| 49 | - * @since 11.9 | |
| 50 | - * | |
| 51 | - * @param bool Whether to show the widget to the current user. | |
| 52 | - */ | |
| 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. | |
| 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 | + } | |
| 52 | + | |
| 53 | + /** This filter is documented in projects/packages/stats-admin/src/class-wp-dashboard-odyssey-widget.php */ | |
| 55 | 54 | $can_user_view_stats = current_user_can( 'manage_options' ) || current_user_can( 'view_stats' ); |
| 56 | 55 | if ( ! apply_filters( 'jetpack_stats_dashboard_widget_show_to_user', $can_user_view_stats ) ) { |
| 57 | 56 | return; |
| 58 | 57 | } |