From 4e1a49a55bc3f639f85da79c0b8aef8b5b127c86 Mon Sep 17 00:00:00 2001 From: Michael D Adams Date: Tue, 27 Aug 2019 01:13:29 -0700 Subject: [PATCH] Add Stats to XML-RPC Errors (#13335) * Add `xmlrpc_errors` to Jetpack (non-compact) Options [not verified] * Send XML-RPC errors via heartbeat. Track unique error codes in `xmlrpc_errors` option. --- class.jetpack-heartbeat.php | 6 ++++ class.jetpack.php | 31 +++++++++++++++++++ .../options/legacy/class.jetpack-options.php | 1 + 3 files changed, 38 insertions(+) diff --git a/class.jetpack-heartbeat.php b/class.jetpack-heartbeat.php index 500b59e5ecbc6..64054e13ac789 100644 --- a/class.jetpack-heartbeat.php +++ b/class.jetpack-heartbeat.php @@ -120,6 +120,12 @@ public static function generate_stats_array( $prefix = '' ) { $return["{$prefix}plugins"] = implode( ',', Jetpack::get_active_plugins() ); $return["{$prefix}manage-enabled"] = true; + $xmlrpc_errors = Jetpack_Options::get_option( 'xmlrpc_errors', array() ); + if ( $xmlrpc_errors ) { + $return["{$prefix}xmlrpc-errors"] = implode( ',', array_keys( $xmlrpc_errors ) ); + Jetpack_Options::delete_option( 'xmlrpc_errors' ); + } + // Missing the connection owner? $connection_manager = new Manager(); $return["{$prefix}missing-owner"] = $connection_manager->is_missing_connection_owner(); diff --git a/class.jetpack.php b/class.jetpack.php index 346b85c6e6498..320bf852e56bc 100644 --- a/class.jetpack.php +++ b/class.jetpack.php @@ -574,6 +574,8 @@ private function __construct() { }; } ); + add_action( 'jetpack_verify_signature_error', array( $this, 'track_xmlrpc_error' ) ); + $this->connection_manager = new Connection_Manager(); $this->connection_manager->init(); @@ -4306,6 +4308,35 @@ function admin_notices() { get_error_code() + : 'should-not-happen'; + + $xmlrpc_errors = Jetpack_Options::get_option( 'xmlrpc_errors', array() ); + if ( isset( $xmlrpc_errors[ $code ] ) && $xmlrpc_errors[ $code ] ) { + // No need to update the option if we already have + // this code stored. + return; + } + $xmlrpc_errors[ $code ] = true; + + Jetpack_Options::update_option( 'xmlrpc_errors', $xmlrpc_errors, false ); + } + /** * Record a stat for later output. This will only currently output in the admin_footer. */ diff --git a/packages/options/legacy/class.jetpack-options.php b/packages/options/legacy/class.jetpack-options.php index 21c0fe95000e8..289b6c873c3de 100644 --- a/packages/options/legacy/class.jetpack-options.php +++ b/packages/options/legacy/class.jetpack-options.php @@ -61,6 +61,7 @@ public static function get_option_names( $type = 'compact' ) { 'static_asset_cdn_files', // (array) An nested array of files that we can swap out for cdn versions. 'mapbox_api_key', // (string) Mapbox API Key, for use with Map block. 'mailchimp', // (string) Mailchimp keyring data, for mailchimp block. + 'xmlrpc_errors', // (array) Keys are XML-RPC signature error codes. Values are truthy. ); case 'private':