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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 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 year ago ComingSoonCacheInvalidator.php 1 year ago ComingSoonHelper.php 1 year ago ComingSoonRequestHandler.php 9 months ago
ComingSoonRequestHandler.php
315 lines
1 <?php
2 namespace Automattic\WooCommerce\Internal\ComingSoon;
3
4 use Automattic\WooCommerce\Admin\Features\Features;
5 use Automattic\WooCommerce\Blocks\BlockTemplatesController;
6 use Automattic\WooCommerce\Blocks\BlockTemplatesRegistry;
7 use Automattic\WooCommerce\Blocks\Package as BlocksPackage;
8 use Automattic\Jetpack\Constants;
9
10 /**
11 * Handles the template_include hook to determine whether the current page needs
12 * to be replaced with a coming soon screen.
13 */
14 class ComingSoonRequestHandler {
15
16 /**
17 * Coming soon helper.
18 *
19 * @var ComingSoonHelper
20 */
21 private $coming_soon_helper = null;
22
23 /**
24 * Whether the coming soon screen should be shown. Cache the result to avoid multiple calls to the helper.
25 *
26 * @var bool
27 */
28 private static $show_coming_soon = false;
29
30 /**
31 * Sets up the hook.
32 *
33 * @internal
34 *
35 * @param ComingSoonHelper $coming_soon_helper Dependency.
36 */
37 final public function init( ComingSoonHelper $coming_soon_helper ) {
38 $this->coming_soon_helper = $coming_soon_helper;
39 // Hook into plugins_loaded to ensure features are initialized to determine coming soon status.
40 add_action(
41 'plugins_loaded',
42 function () {
43 // Skip if the site is live.
44 if ( $this->coming_soon_helper->is_site_live() ) {
45 return;
46 }
47
48 add_filter( 'template_include', array( $this, 'handle_template_include' ) );
49 add_filter( 'wp_theme_json_data_theme', array( $this, 'experimental_filter_theme_json_theme' ) );
50 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
51 add_action( 'after_setup_theme', array( $this, 'possibly_init_block_templates' ), 999 );
52 }
53 );
54 }
55
56 /**
57 * Initializes block templates so we can show coming soon page in non-FSE themes.
58 */
59 public function possibly_init_block_templates() {
60 // No need to initialize block templates since we've already initialized them in the Block Bootstrap.
61 if ( wp_is_block_theme() || current_theme_supports( 'block-template-parts' ) ) {
62 return;
63 }
64
65 $container = BlocksPackage::container();
66 $container->get( BlockTemplatesRegistry::class )->init();
67 $container->get( BlockTemplatesController::class )->init();
68 }
69
70 /**
71 * Replaces the page template with a 'coming soon' when the site is in coming soon mode.
72 *
73 * @internal
74 *
75 * @param string $template The path to the previously determined template.
76 * @return string The path to the 'coming soon' template or any empty string to prevent further template loading in FSE themes.
77 */
78 public function handle_template_include( $template ) {
79 if ( ! $this->should_show_coming_soon() ) {
80 return $template;
81 }
82
83 // A coming soon page needs to be displayed. Set a short cache duration to prevents ddos attacks.
84 header( 'Cache-Control: max-age=60' );
85
86 $is_fse_theme = wp_is_block_theme();
87 $is_store_coming_soon = $this->coming_soon_helper->is_store_coming_soon();
88 add_theme_support( 'block-templates' );
89
90 $coming_soon_template = get_query_template( 'coming-soon' );
91
92 if ( ! $is_fse_theme && $is_store_coming_soon ) {
93 get_header();
94 }
95
96 add_action(
97 'wp_head',
98 function () {
99 echo "<meta name='woo-coming-soon-page' content='yes'>";
100 }
101 );
102
103 if ( ! empty( $coming_soon_template ) && file_exists( $coming_soon_template ) ) {
104 if ( ! $is_fse_theme && $is_store_coming_soon && function_exists( 'get_the_block_template_html' ) ) {
105 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
106 echo get_the_block_template_html();
107 } else {
108 include $coming_soon_template;
109 }
110 }
111
112 if ( ! $is_fse_theme && $is_store_coming_soon ) {
113 get_footer();
114 }
115
116 if ( $is_fse_theme ) {
117 // Since we've already rendered a template, return empty string to ensure no other template is rendered.
118 return '';
119 } else {
120 // In non-FSE themes, other templates will still be rendered.
121 // We need to exit to prevent further processing.
122 exit();
123 }
124 }
125
126 /**
127 * Determines whether the coming soon screen should be shown.
128 *
129 * @return bool
130 */
131 private function should_show_coming_soon() {
132 // Early exit if already determined that the coming soon screen should be shown.
133 if ( self::$show_coming_soon ) {
134 return true;
135 }
136
137 // Early exit if LYS feature is disabled.
138 if ( ! Features::is_enabled( 'launch-your-store' ) ) {
139 return false;
140 }
141
142 // Early exit if the user is logged in as administrator / shop manager.
143 if ( current_user_can( 'manage_woocommerce' ) ) {
144 return false;
145 }
146
147 // Do not show coming soon on 404 pages when applied to store pages only.
148 if ( $this->coming_soon_helper->is_store_coming_soon() && is_404() ) {
149 return false;
150 }
151
152 // Early exit if the current page doesn't need a coming soon screen.
153 if ( ! $this->coming_soon_helper->is_current_page_coming_soon() ) {
154 return false;
155 }
156
157 /**
158 * Check if there is an exclusion.
159 *
160 * @since 9.1.0
161 *
162 * @param bool $is_excluded If the request should be excluded from Coming soon mode. Defaults to false.
163 */
164 if ( apply_filters( 'woocommerce_coming_soon_exclude', false ) ) {
165 return false;
166 }
167
168 // Check if the private link option is enabled.
169 if ( get_option( 'woocommerce_private_link' ) === 'yes' ) {
170 // Exclude users with a private link.
171 if ( isset( $_GET['woo-share'] ) && get_option( 'woocommerce_share_key' ) === $_GET['woo-share'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
172 // Persist the share link with a cookie for 90 days.
173 setcookie( 'woo-share', sanitize_text_field( wp_unslash( $_GET['woo-share'] ) ), time() + 60 * 60 * 24 * 90, '/' ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
174 return false;
175 }
176 if ( isset( $_COOKIE['woo-share'] ) && get_option( 'woocommerce_share_key' ) === $_COOKIE['woo-share'] ) {
177 return false;
178 }
179 }
180
181 self::$show_coming_soon = true;
182 return true;
183 }
184
185 /**
186 * Filters the theme.json data to add Coming Soon fonts.
187 * This runs after child theme merging to ensure parent theme fonts are included.
188 *
189 * @param WP_Theme_JSON_Data $theme_json The theme json data object.
190 * @return WP_Theme_JSON_Data The filtered theme json data.
191 */
192 public function experimental_filter_theme_json_theme( $theme_json ) {
193 if ( ! Features::is_enabled( 'launch-your-store' ) ) {
194 return $theme_json;
195 }
196
197 $theme_data = $theme_json->get_data();
198 $font_data = $theme_data['settings']['typography']['fontFamilies']['theme'] ?? array();
199
200 // Check if the current theme is a child theme. And if so, merge the parent theme fonts with the existing fonts.
201 if ( wp_get_theme()->parent() ) {
202 $parent_theme = wp_get_theme()->parent();
203 $parent_theme_json_file = $parent_theme->get_file_path( 'theme.json' );
204
205 if ( is_readable( $parent_theme_json_file ) ) {
206 $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
207
208 if ( isset( $parent_theme_json_data['settings']['typography']['fontFamilies'] ) ) {
209 $parent_fonts = $parent_theme_json_data['settings']['typography']['fontFamilies'];
210
211 // Merge parent theme fonts with existing fonts.
212 foreach ( $parent_fonts as $parent_font ) {
213 $found = false;
214 foreach ( $font_data as $existing_font ) {
215 if ( isset( $parent_font['name'] ) && isset( $existing_font['name'] ) &&
216 $parent_font['name'] === $existing_font['name'] ) {
217 $found = true;
218 break;
219 }
220 }
221
222 if ( ! $found ) {
223 $font_data[] = $parent_font;
224 }
225 }
226 }
227 }
228 }
229
230 $fonts_to_add = array(
231 array(
232 'fontFamily' => '"Inter", sans-serif',
233 'name' => 'Inter',
234 'slug' => 'inter',
235 'fontFace' => array(
236 array(
237 'fontFamily' => 'Inter',
238 'fontStretch' => 'normal',
239 'fontStyle' => 'normal',
240 'fontWeight' => '300 900',
241 'src' => array( WC()->plugin_url() . '/assets/fonts/Inter-VariableFont_slnt,wght.woff2' ),
242 ),
243 ),
244 ),
245 array(
246 'fontFamily' => 'Cardo',
247 'name' => 'Cardo',
248 'slug' => 'cardo',
249 'fontFace' => array(
250 array(
251 'fontFamily' => 'Cardo',
252 'fontStyle' => 'normal',
253 'fontWeight' => '400',
254 'src' => array( WC()->plugin_url() . '/assets/fonts/cardo_normal_400.woff2' ),
255 ),
256 ),
257 ),
258 );
259
260 // Add WooCommerce fonts if they don't already exist.
261 foreach ( $fonts_to_add as $font_to_add ) {
262 $found = false;
263 foreach ( $font_data as $font ) {
264 if ( isset( $font['name'] ) && $font['name'] === $font_to_add['name'] ) {
265 $found = true;
266 break;
267 }
268 }
269
270 if ( ! $found ) {
271 $font_data[] = $font_to_add;
272 }
273 }
274
275 $new_data = array(
276 'version' => 1,
277 'settings' => array(
278 'typography' => array(
279 'fontFamilies' => array(
280 'theme' => $font_data,
281 ),
282 ),
283 ),
284 );
285 $theme_json->update_with( $new_data );
286 return $theme_json;
287 }
288
289 /**
290 * Enqueues the coming soon banner styles.
291 */
292 public function enqueue_styles() {
293 // Early exit if the user is not logged in as administrator / shop manager.
294 if ( ! current_user_can( 'manage_woocommerce' ) ) {
295 return;
296 }
297
298 // Early exit if LYS feature is disabled.
299 if ( ! Features::is_enabled( 'launch-your-store' ) ) {
300 return;
301 }
302
303 if ( $this->coming_soon_helper->is_site_live() ) {
304 return;
305 }
306
307 wp_enqueue_style(
308 'woocommerce-coming-soon',
309 WC()->plugin_url() . '/assets/css/coming-soon' . ( is_rtl() ? '-rtl' : '' ) . '.css',
310 array(),
311 Constants::get_constant( 'WC_VERSION' )
312 );
313 }
314 }
315