26 const JQUERY =
'jquery';
28 protected $scripts = array();
37 public function __construct()
53 public function hasScripts( $handle, $comp =
'&' )
57 if ( isset( $wp_scripts->registered ) && !empty( $handle ) ) {
60 if ( is_string( $handle ) ) {
61 $handles = explode(
',', $handle );
63 elseif ( is_array( $handle ) ) {
71 if (
'&' == $comp ||
'AND' == strtoupper( $comp ) ) {
72 foreach ( $handles as $handle ) {
73 if ( !isset( $wp_scripts->registered[$handle] ) ) {
81 if (
'|' == $comp ||
'OR' == strtoupper( $comp ) ) {
82 foreach ( $handles as $handle ) {
83 if ( isset( $wp_scripts->registered[$handle] ) ) {
143 public function registerScripts( $scripts, $path =
'', $deps = array(), $version =
false, $in_footer =
true )
145 if ( !empty( $scripts ) && is_array( $scripts ) ) {
146 foreach ( $scripts as $filename => $info ) {
149 if ( is_array( $info ) ) {
151 $_path = isset( $info[
'path'] ) ? $info[
'path'] : $path;
152 $_deps = isset( $info[
'deps'] ) ? $info[
'deps'] : $deps;
155 if ( is_string( $_deps ) ) {
156 $_deps = explode(
',', $_deps );
159 $_version = isset( $info[
'version'] ) ? $info[
'version'] : $version;
160 $_in_footer = isset( $info[
'footer'] ) ? $info[
'footer'] : $in_footer;
161 $src = sprintf(
'%s%s', trailingslashit( $_path ), $filename );
163 elseif ( is_string( $info ) ) {
169 if ( is_string( $_deps ) ) {
170 $_deps = explode(
',', $_deps );
173 $_version = $version;
174 $_in_footer = $in_footer;
175 $src = sprintf(
'%s%s', trailingslashit( $_path ), $info );
183 if ( !empty( $handle ) && !empty( $src ) ) {
184 wp_register_script( $handle, $src, $_deps, $_version, $_in_footer );
205 public static function enqueue_script_pages( $pages, $handle, $src =
false, $deps = array(), $ver =
false,
208 if ( empty( $pages ) ) {
211 if ( is_string( $pages ) ) {
212 $pages = array( $pages );
216 $handles = (array)$handle;
217 foreach ( $pages as $slug ) {
218 if ( is_page( $slug ) ) {
219 foreach ( $handles as $handle ) {
220 wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
241 public static function enqueue_style_pages( $pages, $handle, $src =
false, $deps = array(), $ver =
false )
243 if ( empty( $pages ) ) {
246 if ( is_string( $pages ) ) {
247 $pages = array( $pages );
251 $handles = (array)$handle;
252 foreach ( $pages as $slug ) {
253 if ( is_page( $slug ) ) {
254 foreach ( $handles as $handle ) {
255 wp_enqueue_style( $handle, $src, $deps, $ver );
279 public static function enqueue_script_page_templates( $page_templates, $handle, $src =
false, $deps = array(),
280 $ver =
false, $in_footer =
false )
282 if ( empty( $page_templates ) ) {
285 if ( is_string( $page_templates ) ) {
286 $page_templates = array( $page_templates );
290 $handles = (array)$handle;
291 foreach ( $page_templates as $slug ) {
292 if ( is_page_template( $slug ) ) {
293 foreach ( $handles as $handle ) {
294 wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
315 public static function enqueue_style_page_templates( $page_templates, $handle, $src =
false, $deps = array(), $ver =
false )
317 if ( empty( $page_templates ) ) {
320 if ( is_string( $page_templates ) ) {
321 $page_templates = array( $page_templates );
325 $handles = (array)$handle;
326 foreach ( $page_templates as $slug ) {
327 if ( is_page_template( $slug ) ) {
328 foreach ( $handles as $handle ) {
329 wp_enqueue_style( $handle, $src, $deps, $ver );