From ee6f69a14edcc541d49f2b33919820612be53360 Mon Sep 17 00:00:00 2001 From: Chi-Hsuan Huang Date: Wed, 22 May 2024 19:15:37 +0800 Subject: [PATCH] Wrap private link exclusion logic in `woocommerce_private_link` option check (#47690) --- .../update-private-link-exclusion-logic | 4 ++++ .../ComingSoon/ComingSoonRequestHandler.php | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 plugins/woocommerce/changelog/update-private-link-exclusion-logic diff --git a/plugins/woocommerce/changelog/update-private-link-exclusion-logic b/plugins/woocommerce/changelog/update-private-link-exclusion-logic new file mode 100644 index 00000000000..1b5d8c628e2 --- /dev/null +++ b/plugins/woocommerce/changelog/update-private-link-exclusion-logic @@ -0,0 +1,4 @@ +Significance: patch +Type: update + +Wrap LYS private link exclusion logic in an overall check diff --git a/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php b/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php index 57bb801cb1b..a2c494fc899 100644 --- a/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php +++ b/plugins/woocommerce/src/Internal/ComingSoon/ComingSoonRequestHandler.php @@ -102,14 +102,17 @@ class ComingSoonRequestHandler { return false; } - // 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 false; - } - if ( isset( $_COOKIE['woo-share'] ) && get_option( 'woocommerce_share_key' ) === $_COOKIE['woo-share'] ) { - return false; + // Check if the private link option is enabled. + if ( get_option( 'woocommerce_private_link' ) === 'yes' ) { + // 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 false; + } + if ( isset( $_COOKIE['woo-share'] ) && get_option( 'woocommerce_share_key' ) === $_COOKIE['woo-share'] ) { + return false; + } } return true; }