Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/sal
File: class.json-api-token.php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
/**
[1] Fix | Delete
* SAL_Token class
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[7] Fix | Delete
exit( 0 );
[8] Fix | Delete
}
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Base class for Jetpack_Site, so that we have a real class instead of just passing around an array.
[12] Fix | Delete
*/
[13] Fix | Delete
class SAL_Token {
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* The Jetpack blog ID for the site.
[17] Fix | Delete
*
[18] Fix | Delete
* @var int
[19] Fix | Delete
*/
[20] Fix | Delete
public $blog_id;
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* The Jetpack user's user ID.
[24] Fix | Delete
*
[25] Fix | Delete
* @var int
[26] Fix | Delete
*/
[27] Fix | Delete
public $user_id;
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* The scope for the token, for example global or auth.
[31] Fix | Delete
*
[32] Fix | Delete
* @var string
[33] Fix | Delete
*/
[34] Fix | Delete
public $scope;
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* The Client ID (or WordPress.com Blog ID of this site.
[38] Fix | Delete
*
[39] Fix | Delete
* @var int
[40] Fix | Delete
*/
[41] Fix | Delete
public $client_id;
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* The user ID on the local site.
[45] Fix | Delete
*
[46] Fix | Delete
* @var int
[47] Fix | Delete
*/
[48] Fix | Delete
public $external_user_id;
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Used for tokens created by Oauth clients.
[52] Fix | Delete
*
[53] Fix | Delete
* @var string
[54] Fix | Delete
*/
[55] Fix | Delete
public $external_user_code;
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* The type of authorization based on where the Jetpack connection is made - eg 'calypso', 'jetpack', 'client'.
[59] Fix | Delete
*
[60] Fix | Delete
* @var string
[61] Fix | Delete
*/
[62] Fix | Delete
public $auth_type;
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Contructs the SAL_Token instance.
[66] Fix | Delete
*
[67] Fix | Delete
* @param int $blog_id The Jetpack blog ID for the site.
[68] Fix | Delete
* @param int $user_id The Jetpack user's user ID.
[69] Fix | Delete
* @param string $scope The scope for the token, for example global or auth.
[70] Fix | Delete
* @param int $client_id The Client ID (or WordPress.com Blog ID of this site.
[71] Fix | Delete
* @param int $external_user_id The user ID on the local site.
[72] Fix | Delete
* @param string $external_user_code Used for tokens created by Oauth clients.
[73] Fix | Delete
* @param string $auth_type The type of authorization based on where the Jetpack connection is made (eg. calypso).
[74] Fix | Delete
*/
[75] Fix | Delete
public function __construct( $blog_id, $user_id, $scope, $client_id, $external_user_id, $external_user_code, $auth_type ) {
[76] Fix | Delete
$this->blog_id = $blog_id; // if blog_id is set and scope is not global, limit to that blog.
[77] Fix | Delete
$this->user_id = $user_id;
[78] Fix | Delete
$this->client_id = $client_id;
[79] Fix | Delete
$this->scope = $scope;
[80] Fix | Delete
$this->external_user_id = $external_user_id;
[81] Fix | Delete
$this->external_user_code = $external_user_code;
[82] Fix | Delete
$this->auth_type = $auth_type;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Checks if the scope is 'global'.
[87] Fix | Delete
*
[88] Fix | Delete
* @return bool
[89] Fix | Delete
*/
[90] Fix | Delete
public function is_global() {
[91] Fix | Delete
return $this->scope === 'global';
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* This function is used to create a SAL_Token instance with only a user id, if a token doesn't already exist.
[96] Fix | Delete
*
[97] Fix | Delete
* @return SAL_Token
[98] Fix | Delete
*/
[99] Fix | Delete
public static function for_anonymous_user() {
[100] Fix | Delete
return new SAL_Token(
[101] Fix | Delete
null,
[102] Fix | Delete
get_current_user_id(),
[103] Fix | Delete
null, // there's only ever one scope in our current API implementation, auth or global.
[104] Fix | Delete
null,
[105] Fix | Delete
null,
[106] Fix | Delete
null,
[107] Fix | Delete
null
[108] Fix | Delete
);
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* If a user token exists, the information is used to construct a SAL_Token with the correct parameters.
[113] Fix | Delete
*
[114] Fix | Delete
* @param array $token An array of details relevant to the connected user (may be empty).
[115] Fix | Delete
*
[116] Fix | Delete
* @return SAL_Token
[117] Fix | Delete
*/
[118] Fix | Delete
public static function from_rest_token( $token ) {
[119] Fix | Delete
$user_id = isset( $token['user_id'] ) ? $token['user_id'] : get_current_user_id();
[120] Fix | Delete
$scope = isset( $token['scope'][0] ) ? $token['scope'][0] : null;
[121] Fix | Delete
$client_id = isset( $token['client_id'] ) ? $token['client_id'] : null;
[122] Fix | Delete
$external_user_id = isset( $token['external_user_id'] ) ? $token['external_user_id'] : null;
[123] Fix | Delete
$external_user_code = isset( $token['external_user_code'] ) ? $token['external_user_code'] : null;
[124] Fix | Delete
$auth = isset( $token['auth'] ) ? $token['auth'] : null;
[125] Fix | Delete
$blog_id = isset( $token['blog_id'] ) ? $token['blog_id'] : null;
[126] Fix | Delete
[127] Fix | Delete
return new SAL_Token(
[128] Fix | Delete
$blog_id,
[129] Fix | Delete
$user_id,
[130] Fix | Delete
$scope, // there's only ever one scope in our current API implementation, auth or global.
[131] Fix | Delete
$client_id,
[132] Fix | Delete
$external_user_id,
[133] Fix | Delete
$external_user_code,
[134] Fix | Delete
$auth
[135] Fix | Delete
);
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function