PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
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 | class-jetpack-stats-dashboard-widget.php +21 -44 13.3.3 → 16.3-a.5 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,57 +40,36 @@
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() {
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 + }
46 52
47 - /**
48 - * Filter whether the Jetpack Stats dashboard widget should be shown to the current user.
49 - * By default, the dashboard widget is shown to users who can view_stats.
50 - *
51 - * @module stats
52 - * @since 11.9
53 - *
54 - * @param bool Whether to show the widget to the current user.
55 - */
56 - 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 ) ) {
57 56 return;
58 57 }
59 58
60 - if ( Jetpack::is_connection_ready() ) {
59 + if ( Jetpack::is_connection_ready() && Jetpack::is_module_active( 'stats' ) ) {
61 60 add_action( 'admin_head', array( static::class, 'admin_head' ) );
62 61
63 - $widget_title = sprintf(
64 - __( 'Jetpack Stats', 'jetpack' )
62 + // New widget implemented in Odyssey Stats.
63 + $stats_widget = new Dashboard_Stats_Widget();
64 + wp_add_dashboard_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' )
65 69 );
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 - Dashboard_Stats_Widget::DASHBOARD_WIDGET_ID,
72 - $widget_title,
73 - array( $stats_widget, 'render' )
74 - );
75 - // Only load scripts when the widget is not hidden
76 - $stats_widget->maybe_load_admin_scripts();
77 - } else {
78 - // Legacy widget.
79 - wp_add_dashboard_widget(
80 - Dashboard_Stats_Widget::DASHBOARD_WIDGET_ID,
81 - $widget_title,
82 - array( __CLASS__, 'render_widget' )
83 - );
84 - wp_enqueue_style(
85 - 'jetpack-dashboard-widget',
86 - Assets::get_file_url_for_environment(
87 - 'css/dashboard-widget.min.css',
88 - 'css/dashboard-widget.css'
89 - ),
90 - array(),
91 - JETPACK__VERSION
92 - );
93 - wp_style_add_data( 'jetpack-dashboard-widget', 'rtl', 'replace' );
94 - }
70 + // Only load scripts when the widget is not hidden
71 + $stats_widget->maybe_load_admin_scripts();
95 72 }
96 73 }
97 74
98 75 /**