From 6486c26d76d7a23d0c3176205b7f632d828c7de0 Mon Sep 17 00:00:00 2001 From: Adrian Duffell <9312929+adrianduffell@users.noreply.github.com> Date: Mon, 15 Apr 2024 07:57:02 +0800 Subject: [PATCH] Add exclusion for users with private link (#46465) * Add exclusion for users with private link * Remove unused private function * Fix lint issues * Add changelog * Update sanitization method sanitize_key converts to lowercase * Fix lint issue --- .../changelog/try-LYS-coming-soon-template-only | 4 ++++ .../Internal/ComingSoon/ComingSoonRequestHandler.php | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 plugins/woocommerce/changelog/try-LYS-coming-soon-template-only diff --git a/plugins/woocommerce/changelog/try-LYS-coming-soon-template-only b/plugins/woocommerce/changelog/try-LYS-coming-soon-template-only new file mode 100644 index 00000000000..67b135a9b07 --- /dev/null +++ b/plugins/woocommerce/changelog/try-LYS-coming-soon-template-only @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Add coming soon exclusion for users with a private link. diff --git a/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php b/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php index f27a5b4df6b..d28f295a782 100644 --- a/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php +++ b/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php @@ -54,6 +54,16 @@ class ComingSoonRequestHandler { return $wp; } + // Exclude users with a private link. + if ( isset( $_GET['woo-share'] ) && get_option( 'woocommerce_share_key' ) === $_GET['woo-share'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended + // Persist the share link with a cookie for 90 days. + setcookie( 'woo-share', sanitize_text_field( wp_unslash( $_GET['woo-share'] ) ), time() + 60 * 60 * 24 * 90 ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended + return $wp; + } + if ( isset( $_COOKIE['woo-share'] ) && get_option( 'woocommerce_share_key' ) === $_COOKIE['woo-share'] ) { + return $wp; + } + // A coming soon page needs to be displayed. Don't cache this response. nocache_headers();