Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/src
File: class-tracking.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Tracks class.
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
namespace Automattic\Jetpack\Plugin;
[7] Fix | Delete
[8] Fix | Delete
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
[9] Fix | Delete
use Automattic\Jetpack\Tracking as Tracks;
[10] Fix | Delete
use IXR_Error;
[11] Fix | Delete
use WP_Error;
[12] Fix | Delete
use WP_User;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Tracks class.
[16] Fix | Delete
*/
[17] Fix | Delete
class Tracking {
[18] Fix | Delete
/**
[19] Fix | Delete
* Tracking object.
[20] Fix | Delete
*
[21] Fix | Delete
* @var Tracks
[22] Fix | Delete
*
[23] Fix | Delete
* @access private
[24] Fix | Delete
*/
[25] Fix | Delete
private $tracking;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Prevents the Tracking from being initialized more than once.
[29] Fix | Delete
*
[30] Fix | Delete
* @var bool
[31] Fix | Delete
*/
[32] Fix | Delete
private static $initialized = false;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Initialization function.
[36] Fix | Delete
*/
[37] Fix | Delete
public function init() {
[38] Fix | Delete
if ( static::$initialized ) {
[39] Fix | Delete
return;
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
static::$initialized = true;
[43] Fix | Delete
$this->tracking = new Tracks( 'jetpack' );
[44] Fix | Delete
[45] Fix | Delete
// For tracking stuff via js/ajax.
[46] Fix | Delete
add_action( 'admin_enqueue_scripts', array( $this->tracking, 'enqueue_tracks_scripts' ) );
[47] Fix | Delete
[48] Fix | Delete
add_action( 'jetpack_activate_module', array( $this, 'jetpack_activate_module' ), 1, 1 );
[49] Fix | Delete
add_action( 'jetpack_deactivate_module', array( $this, 'jetpack_deactivate_module' ), 1, 1 );
[50] Fix | Delete
add_action( 'jetpack_user_authorized', array( $this, 'jetpack_user_authorized' ) );
[51] Fix | Delete
[52] Fix | Delete
// Tracking XMLRPC server events.
[53] Fix | Delete
add_action( 'jetpack_xmlrpc_server_event', array( $this, 'jetpack_xmlrpc_server_event' ), 10, 4 );
[54] Fix | Delete
[55] Fix | Delete
// Track that we've begun verifying the previously generated secret.
[56] Fix | Delete
add_action( 'jetpack_verify_secrets_begin', array( $this, 'jetpack_verify_secrets_begin' ), 10, 2 );
[57] Fix | Delete
add_action( 'jetpack_verify_secrets_success', array( $this, 'jetpack_verify_secrets_success' ), 10, 2 );
[58] Fix | Delete
add_action( 'jetpack_verify_secrets_fail', array( $this, 'jetpack_verify_secrets_fail' ), 10, 3 );
[59] Fix | Delete
[60] Fix | Delete
add_action( 'jetpack_verify_api_authorization_request_error_double_encode', array( $this, 'jetpack_verify_api_authorization_request_error_double_encode' ) );
[61] Fix | Delete
add_action( 'jetpack_connection_register_fail', array( $this, 'jetpack_connection_register_fail' ), 10, 2 );
[62] Fix | Delete
add_action( 'jetpack_connection_register_success', array( $this, 'jetpack_connection_register_success' ) );
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* Track that a specific module has been activated.
[67] Fix | Delete
*
[68] Fix | Delete
* @access public
[69] Fix | Delete
*
[70] Fix | Delete
* @param string $module Module slug.
[71] Fix | Delete
*/
[72] Fix | Delete
public function jetpack_activate_module( $module ) {
[73] Fix | Delete
$this->tracking->record_user_event( 'module_activated', array( 'module' => $module ) );
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Track that a specific module has been deactivated.
[78] Fix | Delete
*
[79] Fix | Delete
* @access public
[80] Fix | Delete
*
[81] Fix | Delete
* @param string $module Module slug.
[82] Fix | Delete
*/
[83] Fix | Delete
public function jetpack_deactivate_module( $module ) {
[84] Fix | Delete
$this->tracking->record_user_event( 'module_deactivated', array( 'module' => $module ) );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Track that the user has successfully received an auth token.
[89] Fix | Delete
*
[90] Fix | Delete
* @access public
[91] Fix | Delete
*/
[92] Fix | Delete
public function jetpack_user_authorized() {
[93] Fix | Delete
$user_id = get_current_user_id();
[94] Fix | Delete
$anon_id = get_user_meta( $user_id, 'jetpack_tracks_anon_id', true );
[95] Fix | Delete
[96] Fix | Delete
if ( $anon_id ) {
[97] Fix | Delete
$this->tracking->record_user_event( '_aliasUser', array( 'anonId' => $anon_id ) );
[98] Fix | Delete
delete_user_meta( $user_id, 'jetpack_tracks_anon_id' );
[99] Fix | Delete
if ( ! headers_sent() ) {
[100] Fix | Delete
setcookie( 'tk_ai', 'expired', time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), false ); // phpcs:ignore Jetpack.Functions.SetCookie -- Want this accessible.
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
$connection_manager = new Connection_Manager();
[105] Fix | Delete
$wpcom_user_data = $connection_manager->get_connected_user_data( $user_id );
[106] Fix | Delete
if ( isset( $wpcom_user_data['ID'] ) ) {
[107] Fix | Delete
update_user_meta( $user_id, 'jetpack_tracks_wpcom_id', $wpcom_user_data['ID'] );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
$this->tracking->record_user_event( 'wpa_user_linked', array() );
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Track that we've begun verifying the secrets.
[115] Fix | Delete
*
[116] Fix | Delete
* @access public
[117] Fix | Delete
*
[118] Fix | Delete
* @param string $action Type of secret (one of 'register', 'authorize', 'publicize').
[119] Fix | Delete
* @param WP_User $user The user object.
[120] Fix | Delete
*/
[121] Fix | Delete
public function jetpack_verify_secrets_begin( $action, $user ) {
[122] Fix | Delete
$this->tracking->record_user_event( "jpc_verify_{$action}_begin", array(), $user );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Track that we've succeeded in verifying the secrets.
[127] Fix | Delete
*
[128] Fix | Delete
* @access public
[129] Fix | Delete
*
[130] Fix | Delete
* @param string $action Type of secret (one of 'register', 'authorize', 'publicize').
[131] Fix | Delete
* @param WP_User $user The user object.
[132] Fix | Delete
*/
[133] Fix | Delete
public function jetpack_verify_secrets_success( $action, $user ) {
[134] Fix | Delete
$this->tracking->record_user_event( "jpc_verify_{$action}_success", array(), $user );
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Track that we've failed verifying the secrets.
[139] Fix | Delete
*
[140] Fix | Delete
* @access public
[141] Fix | Delete
*
[142] Fix | Delete
* @param string $action Type of secret (one of 'register', 'authorize', 'publicize').
[143] Fix | Delete
* @param WP_User $user The user object.
[144] Fix | Delete
* @param WP_Error $error Error object.
[145] Fix | Delete
*/
[146] Fix | Delete
public function jetpack_verify_secrets_fail( $action, $user, $error ) {
[147] Fix | Delete
$this->tracking->record_user_event(
[148] Fix | Delete
"jpc_verify_{$action}_fail",
[149] Fix | Delete
array(
[150] Fix | Delete
'error_code' => $error->get_error_code(),
[151] Fix | Delete
'error_message' => $error->get_error_message(),
[152] Fix | Delete
),
[153] Fix | Delete
$user
[154] Fix | Delete
);
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Track a failed login attempt.
[159] Fix | Delete
*
[160] Fix | Delete
* @deprecated 13.9 Method is not longer in use.
[161] Fix | Delete
*/
[162] Fix | Delete
public function wp_login_failed() {
[163] Fix | Delete
_deprecated_function( __METHOD__, '13.9' );
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Track a connection failure at the registration step.
[168] Fix | Delete
*
[169] Fix | Delete
* @access public
[170] Fix | Delete
*
[171] Fix | Delete
* @param string|int $error The error code.
[172] Fix | Delete
* @param WP_Error $registered The error object.
[173] Fix | Delete
*/
[174] Fix | Delete
public function jetpack_connection_register_fail( $error, $registered ) {
[175] Fix | Delete
$this->tracking->record_user_event(
[176] Fix | Delete
'jpc_register_fail',
[177] Fix | Delete
array(
[178] Fix | Delete
'error_code' => $error,
[179] Fix | Delete
'error_message' => $registered->get_error_message(),
[180] Fix | Delete
)
[181] Fix | Delete
);
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
/**
[185] Fix | Delete
* Track that the registration step of the connection has been successful.
[186] Fix | Delete
*
[187] Fix | Delete
* @access public
[188] Fix | Delete
*
[189] Fix | Delete
* @param string $from The 'from' GET parameter.
[190] Fix | Delete
*/
[191] Fix | Delete
public function jetpack_connection_register_success( $from ) {
[192] Fix | Delete
$this->tracking->record_user_event(
[193] Fix | Delete
'jpc_register_success',
[194] Fix | Delete
array(
[195] Fix | Delete
'from' => $from,
[196] Fix | Delete
)
[197] Fix | Delete
);
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Handles the jetpack_xmlrpc_server_event action that combines several types of events that
[202] Fix | Delete
* happen during request serving.
[203] Fix | Delete
*
[204] Fix | Delete
* @param String $action the action name, i.e., 'remote_authorize'.
[205] Fix | Delete
* @param String $stage the execution stage, can be 'begin', 'success', 'error', etc.
[206] Fix | Delete
* @param array|WP_Error|IXR_Error $parameters (optional) extra parameters to be passed to the tracked action.
[207] Fix | Delete
* @param WP_User $user (optional) the acting user.
[208] Fix | Delete
*/
[209] Fix | Delete
public function jetpack_xmlrpc_server_event( $action, $stage, $parameters = array(), $user = null ) {
[210] Fix | Delete
[211] Fix | Delete
if ( is_wp_error( $parameters ) ) {
[212] Fix | Delete
$parameters = array(
[213] Fix | Delete
'error_code' => $parameters->get_error_code(),
[214] Fix | Delete
'error_message' => $parameters->get_error_message(),
[215] Fix | Delete
);
[216] Fix | Delete
} elseif ( is_a( $parameters, IXR_Error::class ) ) {
[217] Fix | Delete
$parameters = array(
[218] Fix | Delete
'error_code' => $parameters->code,
[219] Fix | Delete
'error_message' => $parameters->message,
[220] Fix | Delete
);
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
$this->tracking->record_user_event( 'jpc_' . $action . '_' . $stage, $parameters, $user );
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
/**
[227] Fix | Delete
* Track that the site is incorrectly double-encoding redirects from http to https.
[228] Fix | Delete
*
[229] Fix | Delete
* @access public
[230] Fix | Delete
*/
[231] Fix | Delete
public function jetpack_verify_api_authorization_request_error_double_encode() {
[232] Fix | Delete
$this->tracking->record_user_event( 'error_double_encode' );
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function