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:
Rua Haszard 2020-10-07 16:50:54 +13:00
parent 3bb94bc23f
commit 1eb02845aa
4 changed files with 24 additions and 7 deletions

View File

@ -349,8 +349,9 @@ class WC_Breadcrumb {
* Endpoints.
*/
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_title = $endpoint ? WC()->query->get_endpoint_title( $endpoint ) : '';
$endpoint_title = $endpoint ? WC()->query->get_endpoint_title( $endpoint, $action ) : '';
if ( $endpoint_title ) {
$this->add_crumb( $endpoint_title );

View File

@ -49,9 +49,18 @@ class WC_Form_Handler {
$user_id = absint( $_GET['id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
$value = sprintf( '%d:%s', $user_id, wp_unslash( $_GET['key'] ) ); // phpcs:ignore
$action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
$value = sprintf( '%d:%s', $user_id, wp_unslash( $_GET['key'] ) ); // phpcs:ignore
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;
}
}

View File

@ -89,9 +89,10 @@ class WC_Query {
* Get page title for an endpoint.
*
* @param string $endpoint Endpoint key.
* @param string $action Action or variation within the endpoint @since 4.6.0.
* @return string
*/
public function get_endpoint_title( $endpoint ) {
public function get_endpoint_title( $endpoint, $action = '' ) {
global $wp;
switch ( $endpoint ) {
@ -130,14 +131,19 @@ class WC_Query {
$title = __( 'Add payment method', 'woocommerce' );
break;
case 'lost-password':
$title = __( 'Lost password', 'woocommerce' );
if ( 'rp' === $action ) {
$title = __( 'Set password', 'woocommerce' );
} else {
$title = __( 'Lost password', 'woocommerce' );
}
break;
default:
$title = '';
break;
}
return apply_filters( 'woocommerce_endpoint_' . $endpoint . '_title', $title, $endpoint );
// TBD - docs for filter.
return apply_filters( 'woocommerce_endpoint_' . $endpoint . '_title', $title, $endpoint, $action );
}
/**

View File

@ -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() ) {
$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;
remove_filter( 'the_title', 'wc_page_endpoint_title' );