| @@ -8,66 +8,70 @@ | ||
| 8 | 8 | * |
| 9 | 9 | * @package gutenberg |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -/** | |
| 13 | - * Registers a style according to `wp_register_style`. Honors this request by | |
| 14 | - * deregistering any style by the same handler before registration. | |
| 15 | - * | |
| 16 | - * @param WP_Styles $styles WP_Styles instance. | |
| 17 | - * @param string $handle Name of the stylesheet. Should be unique. | |
| 18 | - * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. | |
| 19 | - * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array. | |
| 20 | - * @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL | |
| 21 | - * as a query string for cache busting purposes. If version is set to false, a version | |
| 22 | - * number is automatically added equal to current installed WordPress version. | |
| 23 | - * If set to null, no version is added. | |
| 24 | - * @param string $media Optional. The media for which this stylesheet has been defined. | |
| 25 | - * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like | |
| 26 | - * '(orientation: portrait)' and '(max-width: 640px)'. | |
| 27 | - */ | |
| 28 | -function gutenberg_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { | |
| 29 | - $style = $styles->query( $handle, 'registered' ); | |
| 30 | - if ( $style ) { | |
| 31 | - $styles->remove( $handle ); | |
| 12 | +if ( ! function_exists( 'gutenberg_override_style' ) ) { | |
| 13 | + /** | |
| 14 | + * Registers a style according to `wp_register_style`. Honors this request by | |
| 15 | + * deregistering any style by the same handler before registration. | |
| 16 | + * | |
| 17 | + * @param WP_Styles $styles WP_Styles instance. | |
| 18 | + * @param string $handle Name of the stylesheet. Should be unique. | |
| 19 | + * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. | |
| 20 | + * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array. | |
| 21 | + * @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL | |
| 22 | + * as a query string for cache busting purposes. If version is set to false, a version | |
| 23 | + * number is automatically added equal to current installed WordPress version. | |
| 24 | + * If set to null, no version is added. | |
| 25 | + * @param string $media Optional. The media for which this stylesheet has been defined. | |
| 26 | + * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like | |
| 27 | + * '(orientation: portrait)' and '(max-width: 640px)'. | |
| 28 | + */ | |
| 29 | + function gutenberg_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { | |
| 30 | + $style = $styles->query( $handle, 'registered' ); | |
| 31 | + if ( $style ) { | |
| 32 | + $styles->remove( $handle ); | |
| 33 | + } | |
| 34 | + $styles->add( $handle, $src, $deps, $ver, $media ); | |
| 32 | 35 | } |
| 33 | - $styles->add( $handle, $src, $deps, $ver, $media ); | |
| 34 | 36 | } |
| 35 | 37 | |
| 36 | -/** | |
| 37 | - * Register all package styles (simple cases only). | |
| 38 | - * Complex cases should be manually registered in lib/client-assets.php. | |
| 39 | - * | |
| 40 | - * @param WP_Styles $styles WP_Styles instance. | |
| 41 | - */ | |
| 42 | -function gutenberg_register_package_styles( $styles ) { | |
| 43 | - // Load build constants | |
| 44 | - $build_constants = require __DIR__ . '/constants.php'; | |
| 45 | - $default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time(); | |
| 46 | - $suffix = SCRIPT_DEBUG ? '' : '.min'; | |
| 38 | +if ( ! function_exists( 'gutenberg_register_package_styles' ) ) { | |
| 39 | + /** | |
| 40 | + * Register all package styles (simple cases only). | |
| 41 | + * Complex cases should be manually registered in lib/client-assets.php. | |
| 42 | + * | |
| 43 | + * @param WP_Styles $styles WP_Styles instance. | |
| 44 | + */ | |
| 45 | + function gutenberg_register_package_styles( $styles ) { | |
| 46 | + // Load build constants | |
| 47 | + $build_constants = require __DIR__ . '/constants.php'; | |
| 48 | + $default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time(); | |
| 49 | + $suffix = SCRIPT_DEBUG ? '' : '.min'; | |
| 47 | 50 | |
| 48 | - $styles_dir = __DIR__ . '/styles'; | |
| 49 | - $styles_file = $styles_dir . '/registry.php'; | |
| 51 | + $styles_dir = __DIR__ . '/styles'; | |
| 52 | + $styles_file = $styles_dir . '/registry.php'; | |
| 50 | 53 | |
| 51 | - if ( ! file_exists( $styles_file ) ) { | |
| 52 | - return; | |
| 53 | - } | |
| 54 | + if ( ! file_exists( $styles_file ) ) { | |
| 55 | + return; | |
| 56 | + } | |
| 54 | 57 | |
| 55 | - $styles_data = require $styles_file; | |
| 56 | - $plugin_dir = dirname( __FILE__ ); | |
| 58 | + $styles_data = require $styles_file; | |
| 59 | + $plugin_dir = dirname( __FILE__ ); | |
| 57 | 60 | |
| 58 | - foreach ( $styles_data as $style_data ) { | |
| 59 | - gutenberg_override_style( | |
| 60 | - $styles, | |
| 61 | - $style_data['handle'], | |
| 62 | - $build_constants['build_url'] . 'styles/' . $style_data['path'] . $suffix . '.css', | |
| 63 | - $style_data['dependencies'], | |
| 64 | - $default_version | |
| 65 | - ); | |
| 61 | + foreach ( $styles_data as $style_data ) { | |
| 62 | + gutenberg_override_style( | |
| 63 | + $styles, | |
| 64 | + $style_data['handle'], | |
| 65 | + $build_constants['build_url'] . 'styles/' . $style_data['path'] . $suffix . '.css', | |
| 66 | + $style_data['dependencies'], | |
| 67 | + $default_version | |
| 68 | + ); | |
| 66 | 69 | |
| 67 | - // Enable RTL support (WordPress automatically loads -rtl.css variant) | |
| 68 | - $styles->add_data( $style_data['handle'], 'rtl', 'replace' ); | |
| 69 | - $styles->add_data( $style_data['handle'], 'suffix', $suffix ); | |
| 70 | + // Enable RTL support (WordPress automatically loads -rtl.css variant) | |
| 71 | + $styles->add_data( $style_data['handle'], 'rtl', 'replace' ); | |
| 72 | + $styles->add_data( $style_data['handle'], 'suffix', $suffix ); | |
| 73 | + } | |
| 70 | 74 | } |
| 75 | + | |
| 76 | + add_action( 'wp_default_styles', 'gutenberg_register_package_styles' ); | |
| 71 | 77 | } |
| 72 | - | |
| 73 | -add_action( 'wp_default_styles', 'gutenberg_register_package_styles' ); | |