support overriding/customising password reset page title via `action`:
- get_endpoint_title now takes an extra `action` param - this also is passed to the relevant hook (as an additional arg) - woocommerce_endpoint_{$endpoint}_title - for `lost-password?action=rp`, use `Set password` - pass action query param through when using get_endpoint_title
This commit is contained in:
parent
3bb94bc23f
commit
1eb02845aa
|
@ -349,8 +349,9 @@ class WC_Breadcrumb {
|
||||||
* Endpoints.
|
* Endpoints.
|
||||||
*/
|
*/
|
||||||
protected function endpoint_trail() {
|
protected function endpoint_trail() {
|
||||||
|
$action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
|
||||||
$endpoint = is_wc_endpoint_url() ? WC()->query->get_current_endpoint() : '';
|
$endpoint = is_wc_endpoint_url() ? WC()->query->get_current_endpoint() : '';
|
||||||
$endpoint_title = $endpoint ? WC()->query->get_endpoint_title( $endpoint ) : '';
|
$endpoint_title = $endpoint ? WC()->query->get_endpoint_title( $endpoint, $action ) : '';
|
||||||
|
|
||||||
if ( $endpoint_title ) {
|
if ( $endpoint_title ) {
|
||||||
$this->add_crumb( $endpoint_title );
|
$this->add_crumb( $endpoint_title );
|
||||||
|
|
|
@ -49,9 +49,18 @@ class WC_Form_Handler {
|
||||||
$user_id = absint( $_GET['id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
$user_id = absint( $_GET['id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
|
||||||
$value = sprintf( '%d:%s', $user_id, wp_unslash( $_GET['key'] ) ); // phpcs:ignore
|
$value = sprintf( '%d:%s', $user_id, wp_unslash( $_GET['key'] ) ); // phpcs:ignore
|
||||||
WC_Shortcode_My_Account::set_reset_password_cookie( $value );
|
WC_Shortcode_My_Account::set_reset_password_cookie( $value );
|
||||||
wp_safe_redirect( add_query_arg( 'show-reset-form', 'true', wc_lostpassword_url() ) );
|
wp_safe_redirect(
|
||||||
|
add_query_arg(
|
||||||
|
array(
|
||||||
|
'show-reset-form' => 'true',
|
||||||
|
'action' => $action,
|
||||||
|
),
|
||||||
|
wc_lostpassword_url()
|
||||||
|
)
|
||||||
|
);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,9 +89,10 @@ class WC_Query {
|
||||||
* Get page title for an endpoint.
|
* Get page title for an endpoint.
|
||||||
*
|
*
|
||||||
* @param string $endpoint Endpoint key.
|
* @param string $endpoint Endpoint key.
|
||||||
|
* @param string $action Action or variation within the endpoint @since 4.6.0.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_endpoint_title( $endpoint ) {
|
public function get_endpoint_title( $endpoint, $action = '' ) {
|
||||||
global $wp;
|
global $wp;
|
||||||
|
|
||||||
switch ( $endpoint ) {
|
switch ( $endpoint ) {
|
||||||
|
@ -130,14 +131,19 @@ class WC_Query {
|
||||||
$title = __( 'Add payment method', 'woocommerce' );
|
$title = __( 'Add payment method', 'woocommerce' );
|
||||||
break;
|
break;
|
||||||
case 'lost-password':
|
case 'lost-password':
|
||||||
|
if ( 'rp' === $action ) {
|
||||||
|
$title = __( 'Set password', 'woocommerce' );
|
||||||
|
} else {
|
||||||
$title = __( 'Lost password', 'woocommerce' );
|
$title = __( 'Lost password', 'woocommerce' );
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$title = '';
|
$title = '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_endpoint_' . $endpoint . '_title', $title, $endpoint );
|
// TBD - docs for filter.
|
||||||
|
return apply_filters( 'woocommerce_endpoint_' . $endpoint . '_title', $title, $endpoint, $action );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,7 +21,8 @@ function wc_page_endpoint_title( $title ) {
|
||||||
|
|
||||||
if ( ! is_null( $wp_query ) && ! is_admin() && is_main_query() && in_the_loop() && is_page() && is_wc_endpoint_url() ) {
|
if ( ! is_null( $wp_query ) && ! is_admin() && is_main_query() && in_the_loop() && is_page() && is_wc_endpoint_url() ) {
|
||||||
$endpoint = WC()->query->get_current_endpoint();
|
$endpoint = WC()->query->get_current_endpoint();
|
||||||
$endpoint_title = WC()->query->get_endpoint_title( $endpoint );
|
$action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
|
||||||
|
$endpoint_title = WC()->query->get_endpoint_title( $endpoint, $action );
|
||||||
$title = $endpoint_title ? $endpoint_title : $title;
|
$title = $endpoint_title ? $endpoint_title : $title;
|
||||||
|
|
||||||
remove_filter( 'the_title', 'wc_page_endpoint_title' );
|
remove_filter( 'the_title', 'wc_page_endpoint_title' );
|
||||||
|
|
Loading…
Reference in New Issue