@@ -238,7 +238,8 @@ public static function get_theme_support_args() {
238
238
* @since 0.7
239
239
*/
240
240
public static function finish_init () {
241
- $ requested_app_shell_component = self ::get_requested_app_shell_component ();
241
+ self ::init_app_shell ();
242
+
242
243
if ( ! is_amp_endpoint () ) {
243
244
244
245
// 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() {
247
248
}
248
249
249
250
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
- }
261
251
return ;
262
252
}
263
253
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
- }
271
254
self ::ensure_proper_amp_location ();
272
255
273
256
$ theme_support = self ::get_theme_support_args ();
@@ -288,6 +271,51 @@ public static function finish_init() {
288
271
}
289
272
}
290
273
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
+
291
319
/**
292
320
* Ensure that the current AMP location is correct.
293
321
*
0 commit comments