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 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3.0.1 6.1.0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7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / ComingSoon / ComingSoonRequestHandler.php
woocommerce / src / Internal / ComingSoon Last commit date
ComingSoonAdminBarBadge.php 1 month ago ComingSoonCacheInvalidator.php 1 year ago ComingSoonHelper.php 1 year ago ComingSoonRequestHandler.php 2 weeks ago
ComingSoonRequestHandler.php
300 lines
1 <?php
2 namespace Automattic\WooCommerce\Internal\ComingSoon;
3
4 use Automattic\WooCommerce\Blocks\BlockTemplatesController;
5 use Automattic\WooCommerce\Blocks\BlockTemplatesRegistry;
6 use Automattic\WooCommerce\Blocks\Package as BlocksPackage;
7 use Automattic\Jetpack\Constants;
8
9 /**
10 * Handles the template_include hook to determine whether the current page needs
11 * to be replaced with a coming soon screen.
12 */
13 class ComingSoonRequestHandler {
14
15 /**
16 * Coming soon helper.
17 *
18 * @var ComingSoonHelper
19 */
20 private $coming_soon_helper = null;
21
22 /**
23 * Whether the coming soon screen should be shown. Cache the result to avoid multiple calls to the helper.
24 *
25 * @var bool
26 */
27 private static $show_coming_soon = false;
28
29 /**
30 * Sets up the hook.
31 *
32 * @internal
33 *
34 * @param ComingSoonHelper $coming_soon_helper Dependency.
35 */
36 final public function init( ComingSoonHelper $coming_soon_helper ) {
37 $this->coming_soon_helper = $coming_soon_helper;
38 // Hook into plugins_loaded to ensure features are initialized to determine coming soon status.
39 add_action(
40 'plugins_loaded',
41 function () {
42 // Skip if the site is live.
43 if ( $this->coming_soon_helper->is_site_live() ) {
44 return;
45 }
46
47 add_filter( 'template_include', array( $this, 'handle_template_include' ) );
48 add_filter( 'wp_theme_json_data_theme', array( $this, 'experimental_filter_theme_json_theme' ) );
49 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
50 add_action( 'after_setup_theme', array( $this, 'possibly_init_block_templates' ), 999 );
51 }
52 );
53 }
54
55 /**
56 * Initializes block templates so we can show coming soon page in non-FSE themes.
57 */
58 public function possibly_init_block_templates() {
59 // No need to initialize block templates since we've already initialized them in the Block Bootstrap.
60 if ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) {
61 return;
62 }
63
64 $container = BlocksPackage::container();
65 $container->get( BlockTemplatesRegistry::class )->init();
66 $container->get( BlockTemplatesController::class )->init();
67 }
68
69 /**
70 * Replaces the page template with a 'coming soon' when the site is in coming soon mode.
71 *
72 * @internal
73 *
74 * @param string $template The path to the previously determined template.
75 * @return string The path to the 'coming soon' template or any empty string to prevent further template loading in FSE themes.
76 */
77 public function handle_template_include( $template ) {
78 if ( ! $this->should_show_coming_soon() ) {
79 return $template;
80 }
81
82 // A coming soon page needs to be displayed. Set a short cache duration to prevents ddos attacks.
83 header( 'Cache-Control: max-age=60' );
84
85 $is_fse_theme = wp_is_block_theme();
86 $is_store_coming_soon = $this->coming_soon_helper->is_store_coming_soon();
87 add_theme_support( 'block-templates' );
88
89 $coming_soon_template = get_query_template( 'coming-soon' );
90
91 if ( ! $is_fse_theme && $is_store_coming_soon ) {
92 get_header();
93 }
94
95 add_action(
96 'wp_head',
97 function () {
98 echo "<meta name='woo-coming-soon-page' content='yes'>";
99 }
100 );
101
102 if ( ! empty( $coming_soon_template ) && file_exists( $coming_soon_template ) ) {
103 if ( ! $is_fse_theme && $is_store_coming_soon && function_exists( 'get_the_block_template_html' ) ) {
104 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
105 echo get_the_block_template_html();
106 } else {
107 include $coming_soon_template;
108 }
109 }
110
111 if ( ! $is_fse_theme && $is_store_coming_soon ) {
112 get_footer();
113 }
114
115 if ( $is_fse_theme ) {
116 // Since we've already rendered a template, return empty string to ensure no other template is rendered.
117 return '';
118 } else {
119 // In non-FSE themes, other templates will still be rendered.
120 // We need to exit to prevent further processing.
121 exit();
122 }
123 }
124
125 /**
126 * Determines whether the coming soon screen should be shown.
127 *
128 * @return bool
129 */
130 private function should_show_coming_soon() {
131 // Early exit if already determined that the coming soon screen should be shown.
132 if ( self::$show_coming_soon ) {
133 return true;
134 }
135
136 // Early exit if the user is logged in as administrator / shop manager.
137 if ( current_user_can( 'manage_woocommerce' ) ) {
138 return false;
139 }
140
141 // Do not show coming soon on 404 pages when applied to store pages only.
142 if ( $this->coming_soon_helper->is_store_coming_soon() && is_404() ) {
143 return false;
144 }
145
146 // Early exit if the current page doesn't need a coming soon screen.
147 if ( ! $this->coming_soon_helper->is_current_page_coming_soon() ) {
148 return false;
149 }
150
151 /**
152 * Check if there is an exclusion.
153 *
154 * @since 9.1.0
155 *
156 * @param bool $is_excluded If the request should be excluded from Coming soon mode. Defaults to false.
157 */
158 if ( apply_filters( 'woocommerce_coming_soon_exclude', false ) ) {
159 return false;
160 }
161
162 // Check if the private link option is enabled.
163 if ( get_option( 'woocommerce_private_link' ) === 'yes' ) {
164 // Exclude users with a private link.
165 if ( isset( $_GET['woo-share'] ) && get_option( 'woocommerce_share_key' ) === $_GET['woo-share'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
166 // Persist the share link with a cookie for 90 days.
167 setcookie( 'woo-share', sanitize_text_field( wp_unslash( $_GET['woo-share'] ) ), time() + 60 * 60 * 24 * 90, '/' ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
168 return false;
169 }
170 if ( isset( $_COOKIE['woo-share'] ) && get_option( 'woocommerce_share_key' ) === $_COOKIE['woo-share'] ) {
171 return false;
172 }
173 }
174
175 self::$show_coming_soon = true;
176 return true;
177 }
178
179 /**
180 * Filters the theme.json data to add Coming Soon fonts.
181 * This runs after child theme merging to ensure parent theme fonts are included.
182 *
183 * @param WP_Theme_JSON_Data $theme_json The theme json data object.
184 * @return WP_Theme_JSON_Data The filtered theme json data.
185 */
186 public function experimental_filter_theme_json_theme( $theme_json ) {
187 $theme_data = $theme_json->get_data();
188 $font_data = $theme_data['settings']['typography']['fontFamilies']['theme'] ?? array();
189
190 // Check if the current theme is a child theme. And if so, merge the parent theme fonts with the existing fonts.
191 if ( wp_get_theme()->parent() ) {
192 $parent_theme = wp_get_theme()->parent();
193 $parent_theme_json_file = $parent_theme->get_file_path( 'theme.json' );
194
195 if ( is_readable( $parent_theme_json_file ) ) {
196 $parent_theme_json_data = json_decode( file_get_contents( $parent_theme_json_file ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
197
198 if ( isset( $parent_theme_json_data['settings']['typography']['fontFamilies'] ) ) {
199 $parent_fonts = $parent_theme_json_data['settings']['typography']['fontFamilies'];
200
201 // Merge parent theme fonts with existing fonts.
202 foreach ( $parent_fonts as $parent_font ) {
203 $found = false;
204 foreach ( $font_data as $existing_font ) {
205 if ( isset( $parent_font['name'] ) && isset( $existing_font['name'] ) &&
206 $parent_font['name'] === $existing_font['name'] ) {
207 $found = true;
208 break;
209 }
210 }
211
212 if ( ! $found ) {
213 $font_data[] = $parent_font;
214 }
215 }
216 }
217 }
218 }
219
220 $fonts_to_add = array(
221 array(
222 'fontFamily' => '"Inter", sans-serif',
223 'name' => 'Inter',
224 'slug' => 'inter',
225 'fontFace' => array(
226 array(
227 'fontFamily' => 'Inter',
228 'fontStretch' => 'normal',
229 'fontStyle' => 'normal',
230 'fontWeight' => '300 900',
231 'src' => array( WC()->plugin_url() . '/assets/fonts/Inter-VariableFont_slnt,wght.woff2' ),
232 ),
233 ),
234 ),
235 array(
236 'fontFamily' => 'Cardo',
237 'name' => 'Cardo',
238 'slug' => 'cardo',
239 'fontFace' => array(
240 array(
241 'fontFamily' => 'Cardo',
242 'fontStyle' => 'normal',
243 'fontWeight' => '400',
244 'src' => array( WC()->plugin_url() . '/assets/fonts/cardo_normal_400.woff2' ),
245 ),
246 ),
247 ),
248 );
249
250 // Add WooCommerce fonts if they don't already exist.
251 foreach ( $fonts_to_add as $font_to_add ) {
252 $found = false;
253 foreach ( $font_data as $font ) {
254 if ( isset( $font['name'] ) && $font['name'] === $font_to_add['name'] ) {
255 $found = true;
256 break;
257 }
258 }
259
260 if ( ! $found ) {
261 $font_data[] = $font_to_add;
262 }
263 }
264
265 $new_data = array(
266 'version' => 1,
267 'settings' => array(
268 'typography' => array(
269 'fontFamilies' => array(
270 'theme' => $font_data,
271 ),
272 ),
273 ),
274 );
275 $theme_json->update_with( $new_data );
276 return $theme_json;
277 }
278
279 /**
280 * Enqueues the coming soon banner styles.
281 */
282 public function enqueue_styles() {
283 // Early exit if the user is not logged in as administrator / shop manager.
284 if ( ! current_user_can( 'manage_woocommerce' ) ) {
285 return;
286 }
287
288 if ( $this->coming_soon_helper->is_site_live() ) {
289 return;
290 }
291
292 wp_enqueue_style(
293 'woocommerce-coming-soon',
294 WC()->plugin_url() . '/assets/css/coming-soon' . ( is_rtl() ? '-rtl' : '' ) . '.css',
295 array(),
296 Constants::get_constant( 'WC_VERSION' )
297 );
298 }
299 }
300