1 | <?php |
---|
2 | /** |
---|
3 | * Plugin Name: Slow Post Embeds |
---|
4 | * Description: This tests an (uncommon) scenario where a post embed iframe finishes loading before the host page is able to load wp-embed.js and fire the DOMContentLoaded event. In this scenario (filed as <a href="https://core.trac.wordpress.org/ticket/44306">#44306</a>), the embed will fail to get the height set since the host page missed the height message from the post embed window. |
---|
5 | * Author: Weston Ruter |
---|
6 | */ |
---|
7 | |
---|
8 | namespace Slow_Post_Embeds; |
---|
9 | |
---|
10 | const QUERY_VAR = 'slow_redirect_url'; |
---|
11 | |
---|
12 | add_filter( |
---|
13 | 'script_loader_src', |
---|
14 | static function ( $url, $handle ) { |
---|
15 | if ( 'wp-embed' === $handle ) { |
---|
16 | $url = add_query_arg( |
---|
17 | [ |
---|
18 | QUERY_VAR => rawurlencode( $url ), |
---|
19 | 'cache_bust' => wp_rand(), |
---|
20 | ], |
---|
21 | home_url( '/' ) |
---|
22 | ); |
---|
23 | } |
---|
24 | return $url; |
---|
25 | }, |
---|
26 | 10, |
---|
27 | 2 |
---|
28 | ); |
---|
29 | |
---|
30 | add_action( |
---|
31 | 'template_redirect', |
---|
32 | static function () { |
---|
33 | if ( ! isset( $_GET[ QUERY_VAR ] ) ) { |
---|
34 | return; |
---|
35 | } |
---|
36 | |
---|
37 | $url = wp_validate_redirect( wp_unslash( $_GET[ QUERY_VAR ] ) ); |
---|
38 | if ( ! $url ) { |
---|
39 | return; |
---|
40 | } |
---|
41 | |
---|
42 | sleep( 3 ); |
---|
43 | wp_redirect( $url, 302 ); |
---|
44 | exit; |
---|
45 | } |
---|
46 | ); |
---|