| @@ -44,9 +44,9 @@ | ||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | // Problem: REST_REQUEST constant is false during Store API requests, so we check the rest_route parameter instead. |
| 47 | 47 | $request_uri = defender_get_data_from_request( 'REQUEST_URI', 's' ); |
| 48 | - if ( '' !== $request_uri && strpos( $request_uri, 'rest_route=/wc/store/v1/checkout' ) !== false ) { | |
| 48 | + if ( '' !== $request_uri && str_contains( $request_uri, 'rest_route=/wc/store/v1/checkout' ) ) { | |
| 49 | 49 | return true; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $post_data = defender_get_data_from_request( null, 'p' ); |
| @@ -71,9 +71,9 @@ | ||
| 71 | 71 | $my_account_page_id = wc_get_page_id( 'myaccount' ); |
| 72 | 72 | if ( $my_account_page_id > 0 ) { |
| 73 | 73 | $my_account_url = get_permalink( $my_account_page_id ); |
| 74 | 74 | |
| 75 | - return strpos( $referer, $my_account_url ) === 0; | |
| 75 | + return str_starts_with( $referer, $my_account_url ); | |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | return false; |
| @@ -87,10 +87,30 @@ | ||
| 87 | 87 | */ |
| 88 | 88 | public static function get_forms(): array { |
| 89 | 89 | return array( |
| 90 | 90 | self::WOO_LOGIN_FORM => esc_html__( 'Login', 'defender-security' ), |
| 91 | + self::WOO_LOST_PASSWORD_FORM => esc_html__( 'Lost Password', 'defender-security' ), | |
| 91 | 92 | self::WOO_REGISTER_FORM => esc_html__( 'Registration', 'defender-security' ), |
| 92 | - self::WOO_LOST_PASSWORD_FORM => esc_html__( 'Lost Password', 'defender-security' ), | |
| 93 | 93 | self::WOO_CHECKOUT_FORM => esc_html__( 'Checkout', 'defender-security' ), |
| 94 | 94 | ); |
| 95 | + } | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * Detects if current request originates from WooCommerce code path. | |
| 99 | + * | |
| 100 | + * @return bool | |
| 101 | + */ | |
| 102 | + public function is_woocommerce_page(): bool { | |
| 103 | + if ( ! $this->is_activated() ) { | |
| 104 | + return false; | |
| 105 | + } | |
| 106 | + | |
| 107 | + $traces = debug_backtrace(); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace | |
| 108 | + foreach ( $traces as $trace ) { | |
| 109 | + if ( isset( $trace['file'] ) && str_contains( $trace['file'], 'woocommerce' ) ) { | |
| 110 | + return true; | |
| 111 | + } | |
| 112 | + } | |
| 113 | + | |
| 114 | + return false; | |
| 95 | 115 | } |
| 96 | 116 | } |