Failed Conditions
Pull Request — develop (#34)
by
unknown
03:44
created

src/Services/Assets.php (2 issues)

1
<?php
2
/**
3
 * Assets.
4
 *
5
 * @link https://github.com/htmlburger/wpemerge-theme-core/blob/master/src/Assets/Assets.php
6
 * @package WPSteak
7
 */
8
9
declare(strict_types=1);
10
11
namespace WPSteak\Services;
12
13
/**
14
 * Assets trait.
15
 *
16
 * @codeCoverageIgnore
17
 */
18
trait Assets {
19
	/**
20
	 * Generate a version for a given file.
21
	 *
22
	 * @param  string $file_path The file path.
23
	 * @return integer|boolean
24
	 */
25
	protected function generate_file_version( $file_path ) {
26
		$version = false;
27
28
		if ( $file_path && file_exists( $file_path ) ) {
29
			$version = filemtime( $file_path );
30
		}
31
32
		return $version;
33
	}
34
35
	/**
36
	 * Enqueue a style, dynamically generating a version for it.
37
	 *
38
	 * @param  string   $handle The handle for enqueue.
39
	 * @param  string   $src The file src.
40
	 * @param  string   $file The file path.
41
	 * @param  string[] $dependencies Dependencies for this file.
42
	 * @param  string   $media The media.
43
	 * @return void
44
	 */
45
	public function enqueue_style( $handle, $src, $file = '', $dependencies = [], $media = 'all' ) {
0 ignored issues
show
Short array syntax is not allowed
Loading history...
46
		wp_enqueue_style( $handle, $src, $dependencies, $this->generate_file_version( $file ), $media );
47
	}
48
49
	/**
50
	 * Enqueue a script, dynamically generating a version for it.
51
	 *
52
	 * @param  string   $handle The handle for enqueue.
53
	 * @param  string   $src The file src.
54
	 * @param  string   $file The file path.
55
	 * @param  string[] $dependencies Dependencies for this file.
56
	 * @param  boolean  $in_footer The media.
57
	 * @return void
58
	 */
59
	public function enqueue_script( $handle, $src, $file = '', $dependencies = [], $in_footer = false ) {
0 ignored issues
show
Short array syntax is not allowed
Loading history...
60
		wp_enqueue_script( $handle, $src, $dependencies, $this->generate_file_version( $file ), $in_footer );
61
	}
62
}
63