get( $handle ) ) { return $tag; } // Bail when not dealing with JS assets. if ( 'js' !== $asset->type ) { return $tag; } // Only localize on JS and if we have data. if ( empty( $asset->localize ) ) { return $tag; } global $wp_scripts; // Makes sure we have an Array of Localize data. if ( is_object( $asset->localize ) ) { $localization = [ $asset->localize ]; } else { $localization = (array) $asset->localize; } /** * Check to ensure we haven't already localized it before. * * @since 4.5.8 */ foreach ( $localization as $localize ) { if ( in_array( $localize->name, $this->localized ) ) { continue; } // If we have a Callable as the Localize data we execute it. if ( is_callable( $localize->data ) ) { $localize->data = call_user_func( $localize->data, $asset ); } wp_localize_script( $asset->slug, $localize->name, $localize->data ); $this->localized[] = $localize->name; } // Fetch the HTML for all the localized data. ob_start(); $wp_scripts->print_extra_script( $asset->slug, true ); $localization_html = ob_get_clean(); // After printing it remove data;| $wp_scripts->add_data( $asset->slug, 'data', '' ); return $localization_html . $tag; } /** * Filters the Script tags to attach Async and/or Defer based on the rules we set in our Asset class. * * @since 4.13.0 * * @param string $tag Tag we are filtering. * @param string $handle Which is the ID/Handle of the tag we are about to print. * * @return string Script tag with the defer and/or async attached. */ public function filter_tag_async_defer( $tag, $handle ) { // Only filter for own own filters. if ( ! $asset = $this->get( $handle ) ) { return $tag; } // Bail when not dealing with JS assets. if ( 'js' !== $asset->type ) { return $tag; } // When async and defer are false we bail with the tag. if ( ! $asset->defer && ! $asset->async ) { return $tag; } $tag_has_async = false !== strpos( $tag, ' async ' ); $tag_has_defer = false !== strpos( $tag, ' defer ' ); $replacement = '