Skip to content

Commit

Permalink
Add user tracking for disconnecting site
Browse files Browse the repository at this point in the history
  • Loading branch information
dereksmart committed Feb 1, 2017
1 parent 8e87a5e commit 5a2f655
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions class.jetpack-xmlrpc-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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' ),
Expand All @@ -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 );
}

/**
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down

0 comments on commit 5a2f655

Please sign in to comment.