| @@ -13,9 +13,8 @@ | ||
| 13 | 13 | * |
| 14 | 14 | * @package automattic/jetpack |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -use Automattic\Jetpack\Admin_UI\Admin_Menu; | |
| 18 | 17 | use Automattic\Jetpack\Connection\Client; |
| 19 | 18 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 20 | 19 | use Automattic\Jetpack\Connection\XMLRPC_Async_Call; |
| 21 | 20 | use Automattic\Jetpack\Redirect; |
| @@ -21,9 +20,8 @@ | ||
| 21 | 20 | use Automattic\Jetpack\Redirect; |
| 22 | 21 | use Automattic\Jetpack\Stats\Main as Stats; |
| 23 | 22 | use Automattic\Jetpack\Stats\Options as Stats_Options; |
| 24 | 23 | use Automattic\Jetpack\Stats\Tracking_Pixel as Stats_Tracking_Pixel; |
| 25 | -use Automattic\Jetpack\Stats\WPCOM_Stats; | |
| 26 | 24 | use Automattic\Jetpack\Stats\XMLRPC_Provider as Stats_XMLRPC; |
| 27 | 25 | use Automattic\Jetpack\Stats_Admin\Dashboard as Stats_Dashboard; |
| 28 | 26 | use Automattic\Jetpack\Stats_Admin\Main as Stats_Main; |
| 29 | 27 | use Automattic\Jetpack\Stats_Admin\Notices as Stats_Notices; |
| @@ -241,18 +239,19 @@ | ||
| 241 | 239 | Stats_Main::update_new_stats_status( true ); |
| 242 | 240 | } |
| 243 | 241 | |
| 244 | 242 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 245 | - if ( ! Stats_Options::get_option( 'enable_odyssey_stats' ) || isset( $_GET['noheader'] ) ) { | |
| 243 | + if ( ( new Host() )->is_woa_site() || ! Stats_Options::get_option( 'enable_odyssey_stats' ) || isset( $_GET['noheader'] ) ) { | |
| 246 | 244 | // Show old Jetpack Stats interface for: |
| 245 | + // - Atomic sites. | |
| 247 | 246 | // - When the "enable_odyssey_stats" option is disabled. |
| 248 | 247 | // - When being shown in the adminbar outside of wp-admin. |
| 249 | - $hook = Admin_Menu::add_menu( __( 'Stats', 'jetpack' ), __( 'Stats', 'jetpack' ), 'view_stats', 'stats', 'jetpack_admin_ui_stats_report_page_wrapper' ); | |
| 248 | + $hook = add_submenu_page( 'jetpack', __( 'Stats', 'jetpack' ), __( 'Stats', 'jetpack' ), 'view_stats', 'stats', 'jetpack_admin_ui_stats_report_page_wrapper' ); | |
| 250 | 249 | add_action( "load-$hook", 'stats_reports_load' ); |
| 251 | 250 | } else { |
| 252 | 251 | // Enable the new Odyssey Stats experience. |
| 253 | 252 | $stats_dashboard = new Stats_Dashboard(); |
| 254 | - $hook = Admin_Menu::add_menu( __( 'Stats', 'jetpack' ), __( 'Stats', 'jetpack' ), 'view_stats', 'stats', array( $stats_dashboard, 'render' ) ); | |
| 253 | + $hook = add_submenu_page( 'jetpack', __( 'Stats', 'jetpack' ), __( 'Stats', 'jetpack' ), 'view_stats', 'stats', array( $stats_dashboard, 'render' ) ); | |
| 255 | 254 | add_action( "load-$hook", array( $stats_dashboard, 'admin_init' ) ); |
| 256 | 255 | } |
| 257 | 256 | } |
| 258 | 257 | |
| @@ -522,9 +521,9 @@ | ||
| 522 | 521 | } |
| 523 | 522 | } elseif ( null === $vals ) { |
| 524 | 523 | $q[ $var ] = ''; |
| 525 | 524 | } elseif ( 'data' === $vals ) { |
| 526 | - if ( str_starts_with( $val, 'index.php' ) ) { | |
| 525 | + if ( 'index.php' === substr( $val, 0, 9 ) ) { | |
| 527 | 526 | $q[ $var ] = $val; |
| 528 | 527 | } |
| 529 | 528 | } |
| 530 | 529 | } |
| @@ -549,9 +548,9 @@ | ||
| 549 | 548 | stats_print_wp_remote_error( $get, $url ); |
| 550 | 549 | } else { |
| 551 | 550 | if ( ! empty( $get['headers']['content-type'] ) ) { |
| 552 | 551 | $type = $get['headers']['content-type']; |
| 553 | - if ( str_starts_with( $type, 'image' ) ) { | |
| 552 | + if ( substr( $type, 0, 5 ) === 'image' ) { | |
| 554 | 553 | $img = $get['body']; |
| 555 | 554 | header( 'Content-Type: ' . $type ); |
| 556 | 555 | header( 'Content-Length: ' . strlen( $img ) ); |
| 557 | 556 | echo $img; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| @@ -1738,8 +1737,14 @@ | ||
| 1738 | 1737 | * @param array $stats_array The stats array. |
| 1739 | 1738 | * @return WP_Error|Object|null |
| 1740 | 1739 | */ |
| 1741 | 1740 | function convert_stats_array_to_object( $stats_array ) { |
| 1742 | - _deprecated_function( __FUNCTION__, 'jetpack-13.2', 'Automattic\Jetpack\Stats\WPCOM_Stats->convert_stats_array_to_object' ); | |
| 1743 | 1741 | |
| 1744 | - return ( new WPCOM_Stats() )->convert_stats_array_to_object( $stats_array ); | |
| 1742 | + if ( is_wp_error( $stats_array ) ) { | |
| 1743 | + return $stats_array; | |
| 1744 | + } | |
| 1745 | + $encoded_array = wp_json_encode( $stats_array ); | |
| 1746 | + if ( ! $encoded_array ) { | |
| 1747 | + return new WP_Error( 'stats_encoding_error', 'Failed to encode stats array' ); | |
| 1748 | + } | |
| 1749 | + return json_decode( $encoded_array ); | |
| 1745 | 1750 | } |