-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.php
More file actions
117 lines (97 loc) · 2.16 KB
/
Copy pathscript.php
File metadata and controls
117 lines (97 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
class Prompt_Script {
/** @var string */
protected $handle;
/** @var string */
protected $path;
/** @var string */
protected $url;
/** @var array */
protected $dependencies;
/** @var string */
protected $version;
/** @var boolean */
protected $in_footer;
/**
* @param array $properties {
* Script properties
* @type string $handle Unique script identifier
* @type string $path Path to script from plugin root
* @type array $dependencies Optional dependencies
* @type string $version Defaults to plugin version
* @type boolean $in_footer Defaults to true
* }
*/
public function __construct( $properties ) {
$defaults = array(
'dependencies' => array(),
'version' => Prompt_Core::version(),
'in_footer' => true,
);
$properties = wp_parse_args( $properties, $defaults );
foreach ( $properties as $name => $value ) {
$this->{$name} = $value;
}
$suffix = '.min';
if ( defined( 'WP_SCRIPT_DEBUG' ) and WP_SCRIPT_DEBUG )
$suffix = '';
if ( !file_exists( Prompt_Core::$dir_path . '/version' ) )
$suffix = '';
if ( $suffix )
$this->path = preg_replace( '/(\.[^\.]*$)/', $suffix . '\1', $this->path );
$this->url = path_join( Prompt_Core::$url_path, $this->path );
}
/**
* @return array
*/
public function get_dependencies() {
return $this->dependencies;
}
/**
* @return string
*/
public function get_handle() {
return $this->handle;
}
/**
* @return boolean
*/
public function get_in_footer() {
return $this->in_footer;
}
/**
* @return string
*/
public function get_path() {
return $this->path;
}
/**
* @return string
*/
public function get_url() {
return $this->url;
}
/**
* @return string
*/
public function get_version() {
return $this->version;
}
public function register() {
wp_register_script(
$this->handle,
$this->url,
$this->dependencies,
$this->version,
$this->in_footer
);
}
public function enqueue() {
$this->register();
wp_enqueue_script( $this->handle );
}
public function localize( $object_name, $data ) {
$this->register();
wp_localize_script( $this->handle, $object_name, $data );
}
}