PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
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 13.9.2 14.0.1 All 504 releases
← All changes | class-jetpack-stats-dashboard-widget.php +14 -35 12.5.2 → 16.3-a.1 View file →
@@ -4,12 +4,10 @@
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;
11 -use Automattic\Jetpack\Stats\Options as Stats_Options;
12 10 use Automattic\Jetpack\Stats_Admin\WP_Dashboard_Odyssey_Widget as Dashboard_Stats_Widget;
13 11 use Automattic\Jetpack\Status;
14 12
15 13 /**
@@ -42,9 +40,8 @@
42 40 /**
43 41 * Sets up the Jetpack Stats widget in the WordPress admin dashboard.
44 42 */
45 43 public static function wp_dashboard_setup() {
46 -
47 44 /**
48 45 * Filter whether the Jetpack Stats dashboard widget should be shown to the current user.
49 46 * By default, the dashboard widget is shown to users who can view_stats.
50 47 *
@@ -52,46 +49,28 @@
52 49 * @since 11.9
53 50 *
54 51 * @param bool Whether to show the widget to the current user.
55 52 */
56 - 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 ) ) {
57 57 return;
58 58 }
59 59
60 - if ( Jetpack::is_connection_ready() ) {
60 + if ( Jetpack::is_connection_ready() && Jetpack::is_module_active( 'stats' ) ) {
61 61 add_action( 'admin_head', array( static::class, 'admin_head' ) );
62 62
63 - $widget_title = sprintf(
64 - __( 'Jetpack Stats', 'jetpack' )
63 + // New widget implemented in Odyssey Stats.
64 + $stats_widget = new Dashboard_Stats_Widget();
65 + wp_add_dashboard_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' )
65 70 );
66 -
67 - if ( Stats_Options::get_option( 'enable_odyssey_stats' ) ) {
68 - // New widget implemented in Odyssey Stats.
69 - $stats_widget = new Dashboard_Stats_Widget();
70 - wp_add_dashboard_widget(
71 - 'jetpack_summary_widget',
72 - $widget_title,
73 - array( $stats_widget, 'render' )
74 - );
75 - $stats_widget->load_admin_scripts();
76 - } else {
77 - // Legacy widget.
78 - wp_add_dashboard_widget(
79 - 'jetpack_summary_widget',
80 - $widget_title,
81 - array( __CLASS__, 'render_widget' )
82 - );
83 - wp_enqueue_style(
84 - 'jetpack-dashboard-widget',
85 - Assets::get_file_url_for_environment(
86 - 'css/dashboard-widget.min.css',
87 - 'css/dashboard-widget.css'
88 - ),
89 - array(),
90 - JETPACK__VERSION
91 - );
92 - wp_style_add_data( 'jetpack-dashboard-widget', 'rtl', 'replace' );
93 - }
71 + // Only load scripts when the widget is not hidden
72 + $stats_widget->maybe_load_admin_scripts();
94 73 }
95 74 }
96 75
97 76 /**