Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds way to redirect user for connect flow #15124

Merged
merged 5 commits into from
Mar 27, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@ private function __construct() {

add_action( 'jetpack_event_log', array( 'Jetpack', 'log' ), 10, 2 );

add_filter( 'login_url', array( $this, 'login_url' ), 10, 2 );
add_action( 'login_init', array( $this, 'login_init' ) );

add_filter( 'determine_current_user', array( $this, 'wp_rest_authenticate' ) );
add_filter( 'rest_authentication_errors', array( $this, 'wp_rest_authentication_errors' ) );

Expand Down Expand Up @@ -4019,6 +4022,45 @@ function plugin_action_links( $actions ) {
return array_merge( $jetpack_home, $actions );
}

/**
* Filters the login URL to include the registration flow in case the user isn't logged in.
*
* @param string $login_url The wp-login URL.
* @param string $redirect URL to redirect users after logging in.
* @since Jetpack 8.4
* @return string
*/
public function login_url( $login_url, $redirect ) {
parse_str( wp_parse_url( $redirect, PHP_URL_QUERY ), $redirect_parts );
if ( ! empty( $redirect_parts['connect_login_redirect'] ) ) {
ChaosExAnima marked this conversation as resolved.
Show resolved Hide resolved
$login_url = add_query_arg( 'connect_login_redirect', 'true', $login_url );
}
return $login_url;
}

/**
* Redirects non-authenticated users to authenticate with Calypso if redirect flag is set.
*
* @since Jetpack 8.4
*/
public function login_init() {
// phpcs:ignore WordPress.Security.NonceVerification
if ( ! empty( $_GET['connect_login_redirect'] ) ) {
add_filter( 'allowed_redirect_hosts', array( &$this, 'allow_wpcom_environments' ) );
ChaosExAnima marked this conversation as resolved.
Show resolved Hide resolved
wp_safe_redirect(
add_query_arg(
array(
'forceInstall' => 1,
'url' => rawurlencode( get_site_url() ),
),
// @todo provide way to go to specific calypso env.
'https://wordpress.com/jetpack/connect'
ChaosExAnima marked this conversation as resolved.
Show resolved Hide resolved
)
);
exit;
}
}

/*
* Registration flow:
* 1 - ::admin_page_load() action=register
Expand Down