Skip to content

Commit 8cca74c

Browse files
committed
Move app shell setup logic into separate method
1 parent 6c23a17 commit 8cca74c

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

includes/class-amp-theme-support.php

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ public static function get_theme_support_args() {
238238
* @since 0.7
239239
*/
240240
public static function finish_init() {
241-
$requested_app_shell_component = self::get_requested_app_shell_component();
241+
self::init_app_shell();
242+
242243
if ( ! is_amp_endpoint() ) {
243244

244245
// Redirect to AMP-less variable if AMP is not available for this URL and yet the query var is present.
@@ -247,27 +248,9 @@ public static function finish_init() {
247248
}
248249

249250
amp_add_frontend_actions();
250-
if ( 'outer' === $requested_app_shell_component ) {
251-
wp_enqueue_script( 'amp-shadow' );
252-
// @todo Enqueue script which hooks uses AMP Shadow API (assets/js/amp-app-shell.js).
253-
// @todo Prevent showing admin bar?
254-
} elseif ( 'inner' === $requested_app_shell_component ) {
255-
wp_die(
256-
esc_html__( 'Inner app shell can only be requested of the AMP version (thus requires paired mode).', 'amp' ),
257-
esc_html__( 'AMP Inner App Shell Problem', 'amp' ),
258-
array( 'response' => 400 )
259-
);
260-
}
261251
return;
262252
}
263253

264-
if ( 'outer' === $requested_app_shell_component ) {
265-
wp_die(
266-
esc_html__( 'Outer app shell can only be requested of the non-AMP version (thus requires paired mode).', 'amp' ),
267-
esc_html__( 'AMP Outer App Shell Problem', 'amp' ),
268-
array( 'response' => 400 )
269-
);
270-
}
271254
self::ensure_proper_amp_location();
272255

273256
$theme_support = self::get_theme_support_args();
@@ -288,6 +271,51 @@ public static function finish_init() {
288271
}
289272
}
290273

274+
/**
275+
* Init app shell.
276+
*
277+
* @since 1.1
278+
*/
279+
public static function init_app_shell() {
280+
$theme_support = self::get_theme_support_args();
281+
if ( ! isset( $theme_support['app_shell'] ) ) {
282+
return;
283+
}
284+
285+
$requested_app_shell_component = self::get_requested_app_shell_component();
286+
287+
if ( ! is_amp_endpoint() ) {
288+
289+
if ( 'outer' === $requested_app_shell_component ) {
290+
wp_enqueue_script( 'amp-shadow' );
291+
// @todo Enqueue script which hooks uses AMP Shadow API (assets/js/amp-app-shell.js).
292+
// @todo Prevent showing admin bar?
293+
// @todo For non-outer
294+
} elseif ( 'inner' === $requested_app_shell_component ) {
295+
wp_die(
296+
esc_html__( 'Inner app shell can only be requested of the AMP version (thus requires paired mode).', 'amp' ),
297+
esc_html__( 'AMP Inner App Shell Problem', 'amp' ),
298+
array( 'response' => 400 )
299+
);
300+
}
301+
302+
// @todo Is this right? It should really be enqueued regardless. It's not about whether the current template has AMP available, but _other_ URLs.
303+
$template_availability = self::get_template_availability();
304+
if ( ! empty( $template_availability['supported'] ) ) {
305+
wp_enqueue_script( 'amp-shadow' );
306+
// @todo Enqueue other required scripts.
307+
}
308+
} else {
309+
if ( 'outer' === $requested_app_shell_component ) {
310+
wp_die(
311+
esc_html__( 'Outer app shell can only be requested of the non-AMP version (thus requires paired mode).', 'amp' ),
312+
esc_html__( 'AMP Outer App Shell Problem', 'amp' ),
313+
array( 'response' => 400 )
314+
);
315+
}
316+
}
317+
}
318+
291319
/**
292320
* Ensure that the current AMP location is correct.
293321
*

0 commit comments

Comments
 (0)