This commit is contained in:
Mike Jolley 2021-02-15 16:46:02 +00:00 committed by GitHub
parent edf79c699a
commit 51789e2105
2 changed files with 29 additions and 11 deletions

View File

@ -84,6 +84,7 @@ const defaultPage = {
permalink: '', permalink: '',
}; };
const storePages = getSetting( 'storePages', { const storePages = getSetting( 'storePages', {
myaccount: defaultPage,
shop: defaultPage, shop: defaultPage,
cart: defaultPage, cart: defaultPage,
checkout: defaultPage, checkout: defaultPage,
@ -109,4 +110,7 @@ export const CHECKOUT_ALLOWS_SIGNUP = getSetting(
'checkoutAllowsSignup', 'checkoutAllowsSignup',
false false
); );
export const LOGIN_URL = getSetting( 'loginUrl', '/wp-login.php' );
export const LOGIN_URL = storePages.myaccount.permalink
? storePages.myaccount.permalink
: getSetting( 'loginUrl', '/wp-login.php' );

View File

@ -24,6 +24,7 @@ class Assets {
add_action( 'body_class', array( __CLASS__, 'add_theme_body_class' ), 1 ); add_action( 'body_class', array( __CLASS__, 'add_theme_body_class' ), 1 );
add_action( 'admin_body_class', array( __CLASS__, 'add_theme_admin_body_class' ), 1 ); add_action( 'admin_body_class', array( __CLASS__, 'add_theme_admin_body_class' ), 1 );
add_filter( 'woocommerce_shared_settings', array( __CLASS__, 'get_wc_block_data' ) ); add_filter( 'woocommerce_shared_settings', array( __CLASS__, 'get_wc_block_data' ) );
add_action( 'woocommerce_login_form_end', array( __CLASS__, 'redirect_to_field' ) );
} }
/** /**
@ -141,6 +142,7 @@ class Assets {
$tag_count = wp_count_terms( 'product_tag' ); $tag_count = wp_count_terms( 'product_tag' );
$product_counts = wp_count_posts( 'product' ); $product_counts = wp_count_posts( 'product' );
$page_ids = [ $page_ids = [
'myaccount' => wc_get_page_id( 'myaccount' ),
'shop' => wc_get_page_id( 'shop' ), 'shop' => wc_get_page_id( 'shop' ),
'cart' => wc_get_page_id( 'cart' ), 'cart' => wc_get_page_id( 'cart' ),
'checkout' => wc_get_page_id( 'checkout' ), 'checkout' => wc_get_page_id( 'checkout' ),
@ -186,6 +188,7 @@ class Assets {
], ],
'homeUrl' => esc_url( home_url( '/' ) ), 'homeUrl' => esc_url( home_url( '/' ) ),
'storePages' => [ 'storePages' => [
'myaccount' => self::format_page_resource( $page_ids['myaccount'] ),
'shop' => self::format_page_resource( $page_ids['shop'] ), 'shop' => self::format_page_resource( $page_ids['shop'] ),
'cart' => self::format_page_resource( $page_ids['cart'] ), 'cart' => self::format_page_resource( $page_ids['cart'] ),
'checkout' => self::format_page_resource( $page_ids['checkout'] ), 'checkout' => self::format_page_resource( $page_ids['checkout'] ),
@ -215,6 +218,17 @@ class Assets {
); );
} }
/**
* Adds a redirect field to the login form so blocks can redirect users after login.
*/
public static function redirect_to_field() {
// phpcs:ignore WordPress.Security.NonceVerification
if ( empty( $_GET['redirect_to'] ) ) {
return;
}
echo '<input type="hidden" name="redirect" value="' . esc_attr( esc_url_raw( wp_unslash( $_GET['redirect_to'] ) ) ) . '" />'; // phpcs:ignore WordPress.Security.NonceVerification
}
/** /**
* Format a page object into a standard array of data. * Format a page object into a standard array of data.
* *