diff --git a/src/Integration/JetpackWPCOM.php b/src/Integration/JetpackWPCOM.php index e112d82233..b2a7677201 100644 --- a/src/Integration/JetpackWPCOM.php +++ b/src/Integration/JetpackWPCOM.php @@ -20,6 +20,10 @@ * Initializes the Jetpack function required to connect the WPCOM App. * This class can be deleted when the jetpack-connection package includes these functions. * + * The majority of these class methods have been copied from the Jetpack class. + * + * @see https://github.com/Automattic/jetpack/blob/trunk/projects/plugins/jetpack/class.jetpack.php + * * @package Automattic\WooCommerce\GoogleListingsAndAds\Integration */ class JetpackWPCOM implements Service, Registerable, Conditional { @@ -64,6 +68,8 @@ public static function is_needed(): bool { /** * Handles the login action for Authorizing the JSON API + * + * @see https://github.com/Automattic/jetpack/blob/6066d7181f78bdec7c355d8b2152733f4691e8a9/projects/plugins/jetpack/class.jetpack.php#L5301 */ public function login_form_json_api_authorization() { $this->verify_json_api_authorization_request(); @@ -78,12 +84,8 @@ public function login_form_json_api_authorization() { * * @param string $user_login Unused. * @param WP_User $user User logged in. - */ - /** - * If someone logs in to approve API access, store the Access Code in usermeta. * - * @param string $user_login Unused. - * @param WP_User $user User logged in. + * @see https://github.com/Automattic/jetpack/blob/6066d7181f78bdec7c355d8b2152733f4691e8a9/projects/plugins/jetpack/class.jetpack.php#L5349 */ public function store_json_api_authorization_token( $user_login, $user ) { add_filter( 'login_redirect', [ $this, 'add_token_to_login_redirect_json_api_authorization' ], 10, 3 ); @@ -94,6 +96,8 @@ public function store_json_api_authorization_token( $user_login, $user ) { /** * Make sure the POSTed request is handled by the same action. + * + * @see https://github.com/Automattic/jetpack/blob/6066d7181f78bdec7c355d8b2152733f4691e8a9/projects/plugins/jetpack/class.jetpack.php#L5336 */ public function preserve_action_in_login_form_for_json_api_authorization() { $http_host = isset( $_SERVER['HTTP_HOST'] ) ? wp_unslash( $_SERVER['HTTP_HOST'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- escaped with esc_url below. @@ -108,6 +112,8 @@ public function preserve_action_in_login_form_for_json_api_authorization() { * @param string $url Redirect URL. * @param string $path Path. * @param string $scheme URL Scheme. + * + * @see https://github.com/Automattic/jetpack/blob/trunk/projects/plugins/jetpack/class.jetpack.php#L5318 */ public function post_login_form_to_signed_url( $url, $path, $scheme ) { if ( 'wp-login.php' !== $path || ( 'login_post' !== $scheme && 'login' !== $scheme ) ) { @@ -132,6 +138,8 @@ public function post_login_form_to_signed_url( $url, $path, $scheme ) { * @param WP_User $user WP_User for the redirect. * * @return string + * + * @see https://github.com/Automattic/jetpack/blob/6066d7181f78bdec7c355d8b2152733f4691e8a9/projects/plugins/jetpack/class.jetpack.php#L5401 */ public function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { return add_query_arg( @@ -148,10 +156,11 @@ public function add_token_to_login_redirect_json_api_authorization( $redirect_to /** * Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access. - * * To be used with a filter of allowed domains for a redirect. * * @param array $domains Allowed WP.com Environments. + * + * @see https://github.com/Automattic/jetpack/blob/6066d7181f78bdec7c355d8b2152733f4691e8a9/projects/plugins/jetpack/class.jetpack.php#L5363 */ public function allow_wpcom_public_api_domain( $domains ) { $domains[] = 'public-api.wordpress.com'; @@ -164,6 +173,8 @@ public function allow_wpcom_public_api_domain( $domains ) { * @param string $redirect_url Redirect URL. * * @return bool If redirect has been encoded. + * + * @see https://github.com/Automattic/jetpack/blob/6066d7181f78bdec7c355d8b2152733f4691e8a9/projects/plugins/jetpack/class.jetpack.php#L5375 */ public static function is_redirect_encoded( $redirect_url ) { return preg_match( '/https?%3A%2F%2F/i', $redirect_url ) > 0; @@ -173,6 +184,8 @@ public static function is_redirect_encoded( $redirect_url ) { * HTML for the JSON API authorization notice. * * @return string + * + * @see https://github.com/Automattic/jetpack/blob/6066d7181f78bdec7c355d8b2152733f4691e8a9/projects/plugins/jetpack/class.jetpack.php#L5603 */ public function login_message_json_api_authorization() { return '