add_inline_script( 'wp-polyfill', wp_get_script_polyfill( $scripts, array( 'window.URL && window.URL.prototype && window.URLSearchParams' => 'wp-polyfill-url', ) ) ); } add_action( 'wp_default_scripts', 'gutenberg_add_url_polyfill', 20 ); /** * Adds a polyfill for DOMRect in environments which do not support it. * * This can be removed when plugin support requires WordPress 5.4.0+. * * The script registration occurs in `gutenberg_register_vendor_scripts`, which * should be removed in coordination with this function. * * @see gutenberg_register_vendor_scripts * @see gutenberg_add_url_polyfill * @see https://core.trac.wordpress.org/ticket/49360 * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect * @see https://developer.wordpress.org/reference/functions/wp_default_packages_vendor/ * * @since 7.5.0 * * @param WP_Scripts $scripts WP_Scripts object. */ function gutenberg_add_dom_rect_polyfill( $scripts ) { did_action( 'init' ) && $scripts->add_inline_script( 'wp-polyfill', wp_get_script_polyfill( $scripts, array( 'window.DOMRect' => 'wp-polyfill-dom-rect', ) ) ); } add_action( 'wp_default_scripts', 'gutenberg_add_dom_rect_polyfill', 20 ); /** * Sets the current post for usage in template blocks. * * @return WP_Post|null The post if any, or null otherwise. */ function gutenberg_get_post_from_context() { // TODO: Without this temporary fix, an infinite loop can occur where // posts with post content blocks render themselves recursively. if ( is_admin() || defined( 'REST_REQUEST' ) ) { return null; } if ( ! in_the_loop() ) { rewind_posts(); the_post(); } return get_post(); }