Completed
Push — add/pwa ( 4f210b...3e657d )
by
unknown
07:35
created

Jetpack_Perf_Optimize_Assets::script_has_deps()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 6
Ratio 54.55 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 6
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Optimizes page assets for unreliable networks and fast rendering, particularly with empty caches
5
 * - inline scripts and styles
6
 * - async external JS
7
 * - remove references to external fonts
8
 * - move CSS links below scripts in head (scripts after CSS blocks render until script finishes downloading)
9
 */
10
11
class Jetpack_Perf_Optimize_Assets {
12
	private static $__instance = null;
13
	private $remove_remote_fonts = false;
14
	private $inline_scripts_and_styles = false;
15
	private $async_scripts = false;
16
	private $defer_scripts = false;
17
	const INLINE_ASSET_MAX_SIZE_BYTES = 10 * 1024; // 10kb
18
	const INLINE_CSS_URL_MAX_SIZE_BYTES = 5 * 1024; // 5kb
19
20
	/**
21
	 * Singleton implementation
22
	 *
23
	 * @return object
24
	 */
25
	public static function instance() {
26
		if ( ! is_a( self::$__instance, 'Jetpack_Perf_Optimize_Assets' ) ) {
27
			self::$__instance = new Jetpack_Perf_Optimize_Assets();
28
		}
29
30
		return self::$__instance;
31
	}
32
33
	public function disable_for_request() {
34
		$this->remove_remote_fonts = false;
35
		$this->inline_scripts_and_styles = false;
36
		$this->async_scripts = false;
37
		$this->defer_scripts = false;
38
	}
39
40
	/**
41
	 * TODO: detect if this is worth doing for wp-admin?
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
42
	 */
43
44
	/**
45
	 * Registers actions
46
	 */
47
	private function __construct() {
48
		$this->is_first_load             = ! isset( $_COOKIE['jetpack_perf_loaded'] );
0 ignored issues
show
Bug introduced by
The property is_first_load does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
49
		$this->remove_remote_fonts       = get_option( 'perf_remove_remote_fonts', true );
50
		$this->inline_always             = get_option( 'perf_inline_on_every_request', false );
0 ignored issues
show
Bug introduced by
The property inline_always does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
		$this->inline_scripts_and_styles = get_option( 'perf_inline_scripts_and_styles', true ) && ( $this->is_first_load || $this->inline_always );
52
		$this->async_scripts             = get_option( 'perf_async_scripts', true );
53
		$this->defer_scripts             = get_option( 'perf_defer_scripts', true );
54
		$this->move_scripts_to_footer    = false;//true;
0 ignored issues
show
Bug introduced by
The property move_scripts_to_footer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
55
		$this->move_scripts_above_css_in_header = true;
0 ignored issues
show
Bug introduced by
The property move_scripts_above_css_in_header does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
56
		$this->remove_core_emojis        = true;
0 ignored issues
show
Bug introduced by
The property remove_core_emojis does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
57
		$this->prevent_jetpack_implode_css = true;
0 ignored issues
show
Bug introduced by
The property prevent_jetpack_implode_css does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
58
59
		if ( $this->remove_remote_fonts ) {
60
			add_filter( 'jetpack_perf_remove_script', array( $this, 'remove_external_font_scripts' ), 10, 3 );
61
			add_filter( 'jetpack_perf_remove_style', array( $this, 'remove_external_font_styles' ), 10, 3 );
62
		}
63
64
//		if ( $this->move_scripts_to_footer ) {
65
			add_filter( 'jetpack_perf_script_group', array( $this, 'set_script_groups' ), 10, 2 );
66
//		}
67
		
68
		add_action( 'wp_enqueue_scripts', array( $this, 'relocate_assets' ), PHP_INT_MAX );
69
70
		// relocate assets
71
		add_filter( 'jetpack_perf_style_group', array( $this, 'set_style_groups' ), 10, 2 );
72
73
		if ( $this->move_scripts_above_css_in_header ) {
74
			add_action( 'init', array( $this, 'move_styles_to_bottom_of_header' ), PHP_INT_MAX );
75
		}
76
77
		if ( $this->prevent_jetpack_implode_css ) {
78
			add_filter( 'jetpack_implode_frontend_css', '__return_false' );
79
		}
80
81
		add_filter( 'script_loader_src', array( $this, 'filter_inline_scripts' ), -100, 2 );
82
		add_filter( 'script_loader_tag', array( $this, 'print_inline_scripts' ), -100, 3 );
83
		add_filter( 'style_loader_src', array( $this, 'filter_inline_styles' ), -100, 2 );
84
		add_filter( 'style_loader_tag', array( $this, 'print_inline_styles' ), -100, 4 );
85
86
		add_action( 'init', array( $this, 'set_first_load_cookie' ) );
87
88
		/**
89
		 * Feature, theme and plugin-specific hacks
90
		 */
91
92
		// remove emoji detection - TODO a setting for this
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
93
		if ( $this->remove_core_emojis ) {
94
			add_action( 'init', array( $this, 'disable_emojis' ) );
95
		}
96
97
		// inline/defer/async stuff for Jetpack
98
		add_action( 'init', array( $this, 'optimize_jetpack' ) );
99
	}
100
101
	/** Disabling Emojis **/
102
	// improves page load performance
103
104
	function disable_emojis() {
105
		remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
106
		remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
107
		remove_action( 'embed_head', 'print_emoji_detection_script', 7 );
108
109
		remove_action( 'wp_print_styles', 'print_emoji_styles' );
110
		remove_action( 'admin_print_styles', 'print_emoji_styles' );
111
112
		remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
113
		remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
114
		remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
115
116
		add_filter( 'tiny_mce_plugins', array( $this, 'disable_emojis_tinymce' ) );
117
		add_filter( 'wp_resource_hints', array( $this, 'disable_emojis_remove_dns_prefetch' ), 10, 2 );
118
	}
119
120
	function optimize_jetpack() {
121
122
	}
123
124
	/**
125
	 * Filter function used to remove the tinymce emoji plugin.
126
	 *
127
	 * @param array $plugins
128
	 * @return array Difference betwen the two arrays
129
	 */
130
	function disable_emojis_tinymce( $plugins ) {
131
		if ( is_array( $plugins ) ) {
132
			return array_diff( $plugins, array( 'wpemoji' ) );
133
		} else {
134
			return array();
135
		}
136
	}
137
138
	/**
139
	 * Remove emoji CDN hostname from DNS prefetching hints.
140
	 *
141
	 * @param array $urls URLs to print for resource hints.
142
	 * @param string $relation_type The relation type the URLs are printed for.
143
	 * @return array Difference betwen the two arrays.
144
	 */
145
	function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
146
		if ( 'dns-prefetch' == $relation_type ) {
147
			/** This filter is documented in wp-includes/formatting.php */
148
			$emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
149
150
			$urls = array_diff( $urls, array( $emoji_svg_url ) );
151
		}
152
153
		return $urls;
154
	}
155
156
	// by default we only inline scripts+styles on first page load for a given user
157
	function set_first_load_cookie() {
158 View Code Duplication
		if ( ! isset( $_COOKIE['jetpack_perf_loaded'] ) ) {
159
			setcookie( 'jetpack_perf_loaded', '1', time() + YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
160
		}
161
	}
162
163
	// this code essentially sets the default asset location to the footer rather than the head
164
	function relocate_assets() {
165
		global $wp_scripts;
166
167
		// fetch all deps for head
168
		$wp_scripts->all_deps( $wp_scripts->queue, true, 1 );
169 View Code Duplication
		foreach( $wp_scripts->to_do as $handle ) {
170
			$registration = $wp_scripts->registered[$handle];
171
			$asset_group = apply_filters( 'jetpack_perf_script_group', $registration->args, $handle );
172
173
			if ( $asset_group !== NULL ) {
174
				$registration->args = $asset_group;
175
				$wp_scripts->groups[$handle] = $asset_group;
176
			} 
177
		}
178
179
180
		global $wp_styles;
181
182
                // fetch all deps for head
183
                $wp_styles->all_deps( $wp_styles->queue, true );
184 View Code Duplication
                foreach( $wp_styles->to_do as $handle ) {
185
                        $registration = $wp_styles->registered[$handle];
186
                        $asset_group = apply_filters( 'jetpack_perf_style_group', $registration->args, $handle );
187
188
                        if ( $asset_group !== NULL ) {
189
                                $registration->args = $asset_group;
190
                                $wp_styles->groups[$handle] = $asset_group;
191
                        }
192
                }
193
194
	}
195
196
	// scripts that run after CSS <link>s in the header block waiting for the CSS to load
197
	// so we move styles as late as possible in the wp_head action to maximise the chance
198
	// of non-blocking rendering
199
	function move_styles_to_bottom_of_header() {
200
		remove_action( 'wp_head', 'wp_print_styles', 8 );
201
		add_action( 'wp_head', 'wp_print_styles', 999 );
202
	}
203
204
	function set_script_groups( $group, $handle ) {
205
		// force jquery into header, everything else can go in footer unless filtered elsewhere
206
		if ( in_array( $handle, array( 'jquery-core', 'jquery-migrate', 'jquery' ) ) ) {
207
			return 0;
208
		}
209
210
		// force scripts with deps into header
211
		if ( $this->script_has_deps( $handle ) ) {
212
			return 0;
213
		}
214
215
		if ( $group === NULL ) {
216
			// set default location to footer
217
			return 1;
218
		}
219
220
		return $group;
221
	}
222
223
	function set_style_groups( $group, $handle ) {
224
		if ( in_array( $handle, array( 'genericons' ) ) ) {
225
			return 0;
226
		}
227
228
		return $group;
229
	}
230
231
	
232
233
	/** FILTERS **/
234
	public function remove_external_font_scripts( $should_remove, $handle, $asset_url ) {
235
		$font_script_url = 'http://use.typekit.com/';
236
		return strncmp( $asset_url, $font_script_url, strlen( $font_script_url ) ) === 0;
237
	}
238
239
	public function remove_external_font_styles( $should_remove, $handle, $asset_url ) {
240
		$font_url = 'https://fonts.googleapis.com';
241
		return strncmp( $asset_url, $font_url, strlen( $font_url ) ) === 0;
242
	}
243
244
	/** SCRIPTS **/
245 View Code Duplication
	public function filter_inline_scripts( $src, $handle ) {
246
		global $wp_scripts;
247
248
		if ( is_admin() || ! isset( $wp_scripts->registered[$handle] ) ) {
249
			return $src;
250
		}
251
252
		$script = $wp_scripts->registered[$handle];
253
254
		// reset src to empty - can't return empty string though because then it skips rendering the tag
255
		if ( $this->should_inline_script( $script ) ) {
256
			return '#';
257
		}
258
259
		return $src;
260
	}
261
262
	public function print_inline_scripts( $tag, $handle, $src ) {
263
		global $wp_scripts;
264
265
		if ( is_admin() || ! isset( $wp_scripts->registered[$handle] ) ) {
266
			return $tag;
267
		}
268
269
		$script = $wp_scripts->registered[$handle];
270
271
		if ( $this->should_remove_script( $script ) ) {
272
			return '';
273
		}
274
275
		if ( $this->should_inline_script( $script ) ) {
276
			$label = '<!-- ' . $script->src . ' -->';
277
			// base64-encoding a script into the src URL only makes sense if we intend to async or defer it
278
			if ( $this->should_defer_script( $script ) ) {
279
				$tag = $label . '<script defer type="text/javascript" src="data:text/javascript;base64,' . base64_encode( file_get_contents( $script->extra['jetpack-inline-file'] ) ) . '"></script>';
280
			} elseif ( $this->should_async_script( $script ) ) {
281
				$tag = $label . '<script async type="text/javascript" src="data:text/javascript;base64,' . base64_encode( file_get_contents( $script->extra['jetpack-inline-file'] ) ) . '"></script>';
282
			} else {
283
				$tag = $label . '<script type="text/javascript">' . file_get_contents( $script->extra['jetpack-inline-file'] ) . '</script>';
284
			}
285
		} else {
286
			if ( $this->should_defer_script( $script ) ) {
287
				$tag = preg_replace( '/<script /', '<script defer ', $tag );
288
			} elseif ( $this->should_async_script( $script ) ) {
289
				$tag = preg_replace( '/<script /', '<script async ', $tag );
290
			}
291
		}
292
293
		return $tag;
294
	}
295
296
	private function should_async_script( $script ) {
297
		// this could be dangerous if scripts have undeclared dependencies
298
		// only make scripts async if nothing depends on them
299
		$should_async_script = ! $this->script_has_deps( $script->handle );
300
301
		// you can override this logic by setting jetpack-async
302
		$should_async_script = $should_async_script || ( isset( $script->extra['jetpack-async'] ) && $script->extra['jetpack-async'] );
303
		return $this->async_scripts && apply_filters( 'jetpack_perf_async_script', $should_async_script, $script->handle, $script->src );
304
	}
305
306
	private function script_has_deps( $handle ) {
307
		global $wp_scripts;
308 View Code Duplication
                foreach ( $wp_scripts->to_do as $other_script_handle ) {
309
                        $other_script = $wp_scripts->registered[ $other_script_handle ];
310
                        if ( in_array( $handle, $other_script->deps ) ) {
311
				return true;
312
                        }
313
                }
314
315
		return false;
316
	}
317
318
	private function should_defer_script( $script ) {
319
		global $wp_scripts;
320
321
		// if it's explicitly not in the footer, or we have Jetpack Defer set, and has no dependencies
322
		$should_defer_script = $script->args === 0;
323
324
		// only make scripts deferred if nothing depends on them
325 View Code Duplication
		foreach ( $wp_scripts->to_do as $other_script_handle ) {
326
			$other_script = $wp_scripts->registered[ $other_script_handle ];
327
			if ( in_array( $script->handle, $other_script->deps ) ) {
328
				$should_defer_script = false;
329
				break;
330
			}
331
		}
332
333
		$should_defer_script = $should_defer_script || ( isset( $script->extra['jetpack-defer'] ) && $script->extra['jetpack-defer'] );
334
		return $this->defer_scripts && apply_filters( 'jetpack_perf_defer_script', $should_defer_script, $script->handle, $script->src );
335
	}
336
337
	private function should_remove_script( $script ) {
338
		return $this->should_remove_asset( 'jetpack_perf_remove_script', $script );
339
	}
340
341
	private function should_inline_script( $script ) {
342
		return ( $this->inline_scripts_and_styles || $this->inline_always ) && $this->should_inline_asset( 'jetpack_perf_inline_script', $script );
343
	}
344
345
	/** STYLES **/
346 View Code Duplication
	public function filter_inline_styles( $src, $handle ) {
347
		global $wp_scripts;
348
349
		if ( is_admin() || ! isset( $wp_scripts->registered[$handle] ) ) {
350
			return $src;
351
		}
352
353
		$style = $wp_scripts->registered[$handle];
354
355
		if ( $this->should_inline_style( $style ) ) {
356
			return '#';
357
		}
358
359
		return $src;
360
	}
361
362
	public function print_inline_styles( $tag, $handle, $href, $media ) {
363
		global $wp_styles;
364
365
		if ( is_admin() || ! isset( $wp_styles->registered[$handle] ) ) {
366
			return $tag;
367
		}
368
369
		$style = $wp_styles->registered[$handle];
370
371
		if ( $this->should_inline_style( $style ) ) {
372
			$label = '<!-- ' . $style->src . ' -->';
373
			$css = $this->fix_css_urls( file_get_contents( $style->extra['jetpack-inline-file'] ), $style->src );
374
			return "$label<style type='text/css' media='$media'>$css</style>";
375
		}
376
377
		if ( $this->should_remove_style( $style ) ) {
378
			return '';
379
		}
380
381
		return $tag;
382
	}
383
384
	public function fix_css_urls( $css, $css_url ) {
385
		$base = trailingslashit( dirname( $css_url ) );
386
		$base = str_replace( site_url(), '', $base );
387
388
		// reject absolute site_url
389
		if ( 'http' === substr( $base, 0, 4 ) ) {
390
			return $css;
391
		}
392
393
		return preg_replace_callback( '/url[\s]*\([\s]*["\']?[\s]*(?!https?:\/\/)(?!data:)(?!#)([^\)"\']*)["\']?\)/i', function( $matches ) use ( $base ) {
394
			// TODO: embed data-encoded file, for files smaller than certain size?
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
395
			$url = $this->rel2abspath( $matches[1], $base );
396
397
			// sneaky - see if it's small enough that it should be encoded and placed inline
398
			$local_path = $this->local_url_to_file_path( $url );
399
			if ( file_exists( $local_path ) && filesize( $local_path ) < self::INLINE_CSS_URL_MAX_SIZE_BYTES && ( $mime_type = wp_check_filetype( $url )['type'] ) ) {
400
				$url = 'data:' . $mime_type . ';base64,' . base64_encode( file_get_contents( $local_path ) );
401
			} 
402
403
			return 'url('.$url.')';
404
		}, $css );
405
	}
406
407
	// see: http://stackoverflow.com/questions/4444475/transfrom-relative-path-into-absolute-url-using-php
408
	private function rel2abspath( $rel, $path) {
409
		/* remove non-directory element from path */
410
		$path = preg_replace( '#/[^/]*$#', '', $path );
411
412
		/* destroy path if relative url points to root */
413
		if( $rel[0] == '/' )
414
			$path = '';
415
416
		/* dirty absolute URL */
417
		$abs = '';
418
419
		$abs .= $path . '/' . $rel;
420
421
		/* replace '//' or '/./' or '/foo/../' with '/' */
422
		$re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#');
423
		for( $n=1; $n>0; $abs = preg_replace( $re, '/', $abs, -1, $n ) ) {}
0 ignored issues
show
Unused Code introduced by
This for loop is empty and can be removed.

This check looks for for loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
424
425
		/* absolute path is ready! */
426
		return $abs;
427
	}
428
429
	private function should_inline_style( $style ) {
430
		return ( $this->inline_scripts_and_styles || $this->inline_always ) && $this->should_inline_asset( 'jetpack_perf_inline_style', $style );
431
	}
432
433
	private function should_remove_style( $style ) {
434
		return $this->should_remove_asset( 'jetpack_perf_remove_style', $style );
435
	}
436
437
	/** shared code **/
438
439
	private function should_inline_asset( $filter, $dependency ) {
440
		// inline anything local, with a src starting with /, or starting with site_url
441
		$site_url = site_url();
442
443
		$is_local_url = ( strncmp( $dependency->src, '/', 1 ) === 0 && strncmp( $dependency->src, '//', 2 ) !== 0 )
444
			|| strpos( $dependency->src, $site_url ) === 0;
445
446
		if ( $is_local_url && ! isset( $dependency->extra['jetpack-inline'] ) ) {
447
			$dependency->extra['jetpack-inline'] = true;
448
			$dependency->extra['jetpack-inline-file'] = $this->local_url_to_file_path( $dependency->src );
449
		}
450
451
		// early exit if the file doesn't exist or is too large
452
		if ( ! isset( $dependency->extra['jetpack-inline-file'] ) || ! file_exists( $dependency->extra['jetpack-inline-file'] ) ) {
453
			return false;
454
		}
455
456
		// only inline if we don't have a conditional
457
		$should_inline = ! isset( $dependency->extra['conditional'] )
458
			&& isset( $dependency->extra['jetpack-inline'] )
459
			&& $dependency->extra['jetpack-inline']
460
			&& filesize( $dependency->extra['jetpack-inline-file'] ) < self::INLINE_ASSET_MAX_SIZE_BYTES;
461
462
		return apply_filters( $filter, $should_inline, $dependency->handle, $dependency->src );
463
	}
464
465
	private function local_url_to_file_path( $url ) {
466
		$path = untrailingslashit( ABSPATH ) . parse_url( $url )['path'];
467
		if ( '/' !== DIRECTORY_SEPARATOR )
468
	             	$path = str_replace( '/', DIRECTORY_SEPARATOR, $path );
469
		return $path;
470
	}
471
472
	private function should_remove_asset( $filter, $dependency ) {
473
		return apply_filters( $filter, false, $dependency->handle, $dependency->src );
474
	}
475
476
	/**
477
	 * if inline assets are enabled, renders inline
478
	 * TODO: enable this just for certain paths/patterns/filetypes
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
479
	 * This is actually currently unused
480
	 */
481
	 public function register_inline_script( $handle, $file, $plugin_file, $deps = false, $ver = false, $in_footer = false ) {
482
		$registered = wp_register_script( $handle, plugins_url( $file, $plugin_file ), $deps, $ver, $in_footer );
483
484 View Code Duplication
		if ( $registered ) {
485
			$file_full_path = dirname( $plugin_file ) . '/' . $file;
486
			wp_script_add_data( $handle, 'jetpack-inline', true );
487
			wp_script_add_data( $handle, 'jetpack-inline-file', $file_full_path );
488
		}
489
490
		return $registered;
491
	}
492
493
	/**
494
	 * if inline assets are enabled, renders inline
495
	 * TODO: enable this just for certain paths/patterns/filetypes
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
496
	 * This is actually currently unused
497
	 */
498
	public function register_inline_style( $handle, $file, $plugin_file, $deps = array(), $ver = false, $media = 'all' ) {
499
		$registered = wp_register_style( $handle, plugins_url( $file, $plugin_file ), $deps, $ver, $media );
500
501 View Code Duplication
		if ( $registered ) {
502
			$file_full_path = dirname( $plugin_file ) . '/' . $file;
503
			wp_style_add_data( $handle, 'jetpack-inline', true );
504
			wp_style_add_data( $handle, 'jetpack-inline-file', $file_full_path );
505
		}
506
	}
507
}
508