PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3 16.3-beta 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 All 508 releases
← All changes | modules/stats.php +97 -23 16.3 → 16.3-a.1 View file →
@@ -21,9 +21,8 @@
21 21 use Automattic\Jetpack\Stats\Options as Stats_Options;
22 22 use Automattic\Jetpack\Stats\Tracking_Pixel as Stats_Tracking_Pixel;
23 23 use Automattic\Jetpack\Stats\WPCOM_Stats;
24 24 use Automattic\Jetpack\Stats\XMLRPC_Provider as Stats_XMLRPC;
25 -use Automattic\Jetpack\Stats_Admin\Admin_Bar as Stats_Admin_Bar;
26 25 use Automattic\Jetpack\Stats_Admin\Admin_Post_List_Column;
27 26 use Automattic\Jetpack\Stats_Admin\Dashboard as Stats_Dashboard;
28 27 use Automattic\Jetpack\Stats_Admin\Main as Stats_Main;
29 28 use Automattic\Jetpack\Status\Host;
@@ -56,13 +55,21 @@
56 55 */
57 56 function stats_load() {
58 57 Jetpack::enable_module_configurable( __FILE__ );
59 58
60 - Stats_Admin_Bar::init();
59 + // Only run the callback for those who can see the stats.
60 + if ( is_user_logged_in() && current_user_can( 'view_stats' ) ) {
61 + add_action( 'admin_head', 'stats_admin_bar_head', 100 );
62 + add_action( 'wp_head', 'stats_admin_bar_head', 100 );
63 + }
64 +
61 65 Admin_Post_List_Column::register();
62 66
63 67 add_action( 'jetpack_admin_menu', 'stats_admin_menu' );
68 + add_action( 'wp_before_admin_bar_render', 'stats_add_link_to_admin_bar_site_menu' );
64 69
70 + add_filter( 'pre_option_db_version', 'stats_ignore_db_version' );
71 +
65 72 // Filter for adding the Jetpack plugin version to tracking stats.
66 73 add_filter( 'stats_array', 'filter_stats_array_add_jp_version' );
67 74
68 75 require_once __DIR__ . '/stats/class-jetpack-stats-upgrade-nudges.php';
@@ -81,18 +88,24 @@
81 88 }
82 89
83 90 /**
84 91 * Prevent sparkline img requests being redirected to upgrade.php.
92 + * See wp-admin/admin.php where it checks $wp_db_version.
85 93 *
86 - * @deprecated 16.3
87 - *
88 94 * @access public
89 95 * @param mixed $version Version.
90 96 * @return string $version.
91 97 */
92 98 function stats_ignore_db_version( $version ) {
93 - _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Stats_Admin\Admin_Bar::ignore_db_version' );
94 - return Stats_Admin_Bar::ignore_db_version( $version );
99 + if (
100 + is_admin() &&
101 + isset( $_GET['page'] ) && 'stats' === $_GET['page'] && // phpcs:ignore WordPress.Security.NonceVerification.Recommended
102 + isset( $_GET['chart'] ) && strpos( $_GET['chart'], 'admin-bar-hours' ) === 0 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput
103 + ) {
104 + global $wp_db_version;
105 + return $wp_db_version;
106 + }
107 + return $version;
95 108 }
96 109
97 110 /**
98 111 * Maps view_stats cap to read cap as needed.
@@ -494,9 +507,9 @@
494 507 $i18n_headers = jetpack_get_module_i18n( 'stats' );
495 508 ?>
496 509 <a
497 510 style="font-size:13px;"
498 - href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack-settings#/settings?term=' . rawurlencode( $i18n_headers['name'] ?? '' ) ) ); ?>"
511 + href="<?php echo esc_url( admin_url( 'admin.php?page=jetpack#/settings?term=' . rawurlencode( $i18n_headers['name'] ?? '' ) ) ); ?>"
499 512 >
500 513 <?php esc_html_e( 'Configure', 'jetpack' ); ?>
501 514 </a>
502 515 <?php
@@ -725,30 +738,68 @@
725 738
726 739 /**
727 740 * Stats Admin Bar Head.
728 741 *
729 - * @deprecated 16.3
730 - *
731 742 * @access public
732 743 * @return void
733 744 */
734 745 function stats_admin_bar_head() {
735 - _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Stats_Admin\Admin_Bar::maybe_add_chart' );
736 - Stats_Admin_Bar::maybe_add_chart();
746 + // Let's not show the stats admin bar to users who are not logged in.
747 + if ( ! is_user_logged_in() ) {
748 + return;
749 + }
750 +
751 + if ( ! Stats_Options::get_option( 'admin_bar' ) ) {
752 + return;
753 + }
754 +
755 + if ( ! current_user_can( 'view_stats' ) ) {
756 + return;
757 + }
758 +
759 + if ( ! is_admin_bar_showing() ) {
760 + return;
761 + }
762 +
763 + add_action( 'admin_bar_menu', 'stats_admin_bar_menu', 100 );
764 + ?>
765 +
766 +<style data-ampdevmode type='text/css'>
767 +#wpadminbar .quicklinks li#wp-admin-bar-stats {
768 + height: 32px;
737 769 }
770 +#wpadminbar .quicklinks li#wp-admin-bar-stats a {
771 + height: 32px;
772 + padding: 0;
773 +}
774 +#wpadminbar .quicklinks li#wp-admin-bar-stats a div {
775 + height: 32px;
776 + width: 95px;
777 + overflow: hidden;
778 + margin: 0 10px;
779 +}
780 +#wpadminbar .quicklinks li#wp-admin-bar-stats a:hover div {
781 + width: auto;
782 + margin: 0 8px 0 10px;
783 +}
784 +#wpadminbar .quicklinks li#wp-admin-bar-stats a img {
785 + height: 24px;
786 + margin: 4px 0;
787 + max-width: none;
788 + border: none;
789 +}
790 +</style>
791 + <?php
792 +}
738 793
739 794 /**
740 795 * Gets the image source of the given stats chart.
741 796 *
742 - * @deprecated 16.3
743 - *
744 797 * @param string $chart Name of the chart.
745 798 * @param array $args Extra list of argument to use in the image source.
746 799 * @return string An image source.
747 800 */
748 801 function stats_get_image_chart_src( $chart, $args = array() ) {
749 - _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Stats_Admin\Admin_Bar::get_chart_src' );
750 -
751 802 $url = add_query_arg( 'page', 'stats', admin_url( 'admin.php' ) );
752 803
753 804 return add_query_arg(
754 805 array_merge(
@@ -765,30 +816,53 @@
765 816
766 817 /**
767 818 * Stats AdminBar.
768 819 *
769 - * @deprecated 16.3
770 - *
771 820 * @access public
772 821 * @param mixed $wp_admin_bar WPAdminBar.
773 822 * @return void
774 823 */
775 824 function stats_admin_bar_menu( &$wp_admin_bar ) {
776 - _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Stats_Admin\Admin_Bar::add_chart_node' );
777 - Stats_Admin_Bar::add_chart_node( $wp_admin_bar );
825 + $img_src = esc_attr( stats_get_image_chart_src( 'admin-bar-hours-scale' ) );
826 + $img_src_2x = esc_attr( stats_get_image_chart_src( 'admin-bar-hours-scale-2x' ) );
827 + $alt = esc_attr( __( 'Stats', 'jetpack' ) );
828 + $title = esc_attr( __( 'Views over 48 hours. Click for more Jetpack Stats.', 'jetpack' ) );
829 +
830 + $menu = array(
831 + 'id' => 'stats',
832 + 'href' => add_query_arg( 'page', 'stats', admin_url( 'admin.php' ) ), // no menu_page_url() blog-side.
833 + 'title' => "<div><img fetchpriority='low' loading='lazy' decoding='async' src='$img_src' srcset='$img_src 1x, $img_src_2x 2x' width='112' height='24' alt='$alt' title='$title'></div>",
834 + );
835 +
836 + $wp_admin_bar->add_menu( $menu );
778 837 }
779 838
780 839 /**
781 840 * Adds a Stats link to the site-name admin bar submenu, alongside Dashboard.
782 841 *
783 - * @deprecated 16.3
784 - *
785 842 * @access public
786 843 * @return void
787 844 */
788 845 function stats_add_link_to_admin_bar_site_menu() {
789 - _deprecated_function( __FUNCTION__, 'jetpack-16.3', 'Automattic\Jetpack\Stats_Admin\Admin_Bar::add_site_menu_link' );
790 - Stats_Admin_Bar::add_site_menu_link();
846 + global $wp_admin_bar;
847 +
848 + if (
849 + ! is_object( $wp_admin_bar ) ||
850 + ! $wp_admin_bar->get_node( 'dashboard' ) ||
851 + ! current_user_can( 'view_stats' ) ||
852 + ( new Host() )->is_wpcom_platform()
853 + ) {
854 + return;
855 + }
856 +
857 + $wp_admin_bar->add_node(
858 + array(
859 + 'parent' => 'site-name',
860 + 'id' => 'jetpack-stats',
861 + 'title' => __( 'Stats', 'jetpack' ),
862 + 'href' => admin_url( 'admin.php?page=stats' ),
863 + )
864 + );
791 865 }
792 866
793 867 /**
794 868 * Stats Get Blog.