| 1 |
<?php |
| 2 |
/** |
| 3 |
* Load global styles assets in the front-end. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* This code lives in script-loader.php |
| 10 |
* where we just load styles using wp_get_global_stylesheet. |
| 11 |
*/ |
| 12 |
if ( ! function_exists( 'wp_get_global_styles' ) ) { |
| 13 |
/** |
| 14 |
* Fetches the preferences for each origin (core, theme, user) |
| 15 |
* and enqueues the resulting stylesheet. |
| 16 |
*/ |
| 17 |
function gutenberg_enqueue_global_styles_assets() { |
| 18 |
$stylesheet = wp_get_global_stylesheet(); |
| 19 |
if ( empty( $stylesheet ) ) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
if ( isset( wp_styles()->registered['global-styles'] ) ) { |
| 24 |
// We're in WordPress 5.8, so we overwrite the existing. |
| 25 |
wp_styles()->registered['global-styles']->extra['after'][0] = $stylesheet; |
| 26 |
} else { |
| 27 |
// WordPress 5.7 or lower. |
| 28 |
wp_register_style( 'global-styles', false, array(), true, true ); |
| 29 |
wp_add_inline_style( 'global-styles', $stylesheet ); |
| 30 |
wp_enqueue_style( 'global-styles' ); |
| 31 |
} |
| 32 |
} |
| 33 |
add_action( 'wp_enqueue_scripts', 'gutenberg_enqueue_global_styles_assets' ); |
| 34 |
} |
| 35 |
|