From ffeae75dc454f74ac83eb2783903d0483c0f76e7 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Wed, 1 Feb 2017 17:01:36 -0500 Subject: [PATCH] Add user tracking for disconnecting site (#6248) --- class.jetpack-xmlrpc-server.php | 17 ++++++++++++++--- class.jetpack.php | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/class.jetpack-xmlrpc-server.php b/class.jetpack-xmlrpc-server.php index a3717fc2992f1..f1d6a493f46ad 100644 --- a/class.jetpack-xmlrpc-server.php +++ b/class.jetpack-xmlrpc-server.php @@ -9,6 +9,11 @@ class Jetpack_XMLRPC_Server { */ public $error = null; + /** + * The current user + */ + public $user = null; + /** * Whitelist of the XML-RPC methods available to the Jetpack Server. If the * user is not authenticated (->login()) then the methods are never added, @@ -20,9 +25,9 @@ function xmlrpc_methods( $core_methods ) { 'jetpack.verifyAction' => array( $this, 'verify_action' ), ); - $user = $this->login(); + $this->user = $this->login(); - if ( $user ) { + if ( $this->user ) { $jetpack_methods = array_merge( $jetpack_methods, array( 'jetpack.testConnection' => array( $this, 'test_connection' ), 'jetpack.testAPIUserCode' => array( $this, 'test_api_user_code' ), @@ -48,7 +53,7 @@ function xmlrpc_methods( $core_methods ) { * @param array $core_methods Available core XML-RPC methods. * @param WP_User $user Information about a given WordPress user. */ - $jetpack_methods = apply_filters( 'jetpack_xmlrpc_methods', $jetpack_methods, $core_methods, $user ); + $jetpack_methods = apply_filters( 'jetpack_xmlrpc_methods', $jetpack_methods, $core_methods, $this->user ); } /** @@ -321,6 +326,12 @@ function test_api_user_code( $args ) { * @return boolean */ function disconnect_blog() { + + // For tracking + if ( ! empty( $this->user->ID ) ) { + wp_set_current_user( $this->user->ID ); + } + Jetpack::log( 'disconnect' ); Jetpack::disconnect(); diff --git a/class.jetpack.php b/class.jetpack.php index a9b4ce3ce3077..43b8f96c4f4ec 100644 --- a/class.jetpack.php +++ b/class.jetpack.php @@ -2753,6 +2753,7 @@ public static function disconnect( $update_activated_state = true ) { // If the site is in an IDC because sync is not allowed, // let's make sure to not disconnect the production site. if ( ! self::validate_sync_error_idc_option() ) { + JetpackTracking::record_user_event( 'disconnect_site', array() ); Jetpack::load_xml_rpc_client(); $xml = new Jetpack_IXR_Client(); $xml->query( 'jetpack.deregister' );