Skip to content

Commit 4fb4dc8

Browse files
danslebobygfazioli
authored andcommitted
Align View enqueue methods with WordPress wp_enqueue_style/wp_enqueue_script signatures
Fix $ver default from [] to false to match WordPress signatures. Add $media parameter to style methods and $args parameter to script methods to allow full control as with native WordPress enqueue calls.
1 parent a3def9a commit 4fb4dc8

1 file changed

Lines changed: 61 additions & 42 deletions

File tree

src/View/View.php

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -235,69 +235,73 @@ public function withInlineStyle($name, $data): View
235235
/**
236236
* Load a new css resource in admin area.
237237
*
238-
* @param string $name Name of style.
239-
* @param array $deps Optional. Array of slug deps
240-
* @param array $ver Optional. Version.
238+
* @param string $name Name of style.
239+
* @param array $deps Optional. Array of slug deps.
240+
* @param string|false $ver Optional. Version.
241+
* @param string $media Optional. The media for which this stylesheet has been defined. Default 'all'.
241242
*
242243
* @return $this
243244
*/
244-
public function withAdminStyle($name, $deps = [], $ver = []): View
245+
public function withAdminStyle($name, $deps = [], $ver = false, $media = 'all'): View
245246
{
246-
$this->adminStyles[] = [$name, $deps, $ver];
247+
$this->adminStyles[] = [$name, $deps, $ver, $media];
247248

248249
return $this;
249250
}
250251

251252
/**
252253
* Load a new css resource in admin area.
253254
*
254-
* @param string $name Name of style.
255-
* @param array $deps Optional. Array of slug deps
256-
* @param array $ver Optional. Version.
255+
* @param string $name Name of style.
256+
* @param array $deps Optional. Array of slug deps.
257+
* @param string|false $ver Optional. Version.
258+
* @param string $media Optional. The media for which this stylesheet has been defined. Default 'all'.
257259
*
258260
* @deprecated 1.6.0
259261
*
260262
* @return $this
261263
*/
262-
public function withAdminStyles($name, $deps = [], $ver = []): View
264+
public function withAdminStyles($name, $deps = [], $ver = false, $media = 'all'): View
263265
{
264266
_deprecated_function(__METHOD__, '1.6.0', 'withAdminStyle()');
265267

266-
return $this->withAdminStyle($name, $deps, $ver);
268+
return $this->withAdminStyle($name, $deps, $ver, $media);
267269
}
268270

269271
/**
270272
* Load a new Javascript resource in admin area.
271273
*
272-
* @param string $name Name of script.
273-
* @param array $deps Optional. Array of slug deps
274-
* @param array $ver Optional. Version.
274+
* @param string $name Name of script.
275+
* @param array $deps Optional. Array of slug deps.
276+
* @param string|false $ver Optional. Version.
277+
* @param bool|array $args Optional. Whether to enqueue the script in the footer. Default true.
275278
*
276279
* @return $this
277280
*/
278-
public function withAdminScript($name, $deps = [], $ver = []): View
281+
public function withAdminScript($name, $deps = [], $ver = false, $args = true): View
279282
{
280-
$this->adminScripts[] = [$name, $deps, $ver];
283+
$this->adminScripts[] = [$name, $deps, $ver, $args];
281284

282285
return $this;
283286
}
284287

285288
/**
286289
* Load a new Javascript resource in admin area.
287290
*
288-
* @param string $name Name of script.
289-
* @param array $deps Optional. Array of slug deps
290-
* @param array $ver Optional. Version.
291+
* @param string $name Name of script.
292+
* @param array $deps Optional. Array of slug deps.
293+
* @param string|false $ver Optional. Version.
294+
* @param bool|array $args Optional. Whether to enqueue the script in the footer. Default true.
291295
*
292296
* @deprecated 1.6.0
293297
*
294298
* @return $this
295299
*/
296-
public function withAdminScripts($name, $deps = [], $ver = []): View
300+
public function withAdminScripts($name, $deps = [], $ver = false, $args = true): View
297301
{
298302
_deprecated_function(__METHOD__, '1.6.0', 'withAdminScript()');
299303

300-
return $this->withAdminScript($name, $deps, $ver);
304+
return $this->withAdminScript($name, $deps, $ver, $args);
301305
}
302306

303307
/**
@@ -352,58 +356,73 @@ public function withAdminAppsScripts($name, $deps = [], $ver = []): View
352356
/**
353357
* Load a new css resource in theme.
354358
*
355-
* @param string $name Name of style.
356-
* @param array $deps Optional. Array of slug deps
357-
* @param array $ver Optional. Version.
359+
* @param string $name Name of style.
360+
* @param array $deps Optional. Array of slug deps.
361+
* @param string|false $ver Optional. Version.
362+
* @param string $media Optional. The media for which this stylesheet has been defined. Default 'all'.
358363
*
359364
* @return $this
360365
*/
361-
public function withStyle($name, $deps = [], $ver = []): View
366+
public function withStyle($name, $deps = [], $ver = false, $media = 'all'): View
362367
{
363-
$this->styles[] = [$name, $deps, $ver];
368+
$this->styles[] = [$name, $deps, $ver, $media];
364369

365370
return $this;
366371
}
367372

368373
/**
369374
* Load a new css resource in theme.
370375
*
371-
* @param string $name Name of style.
372-
* @param array $deps Optional. Array of slug deps
373-
* @param array $ver Optional. Version.
376+
* @param string $name Name of style.
377+
* @param array $deps Optional. Array of slug deps.
378+
* @param string|false $ver Optional. Version.
379+
* @param string $media Optional. The media for which this stylesheet has been defined. Default 'all'.
374380
*
375381
* @deprecated 1.6.1
376382
*
377383
* @return $this
378384
*/
379-
public function withStyles($name, $deps = [], $ver = []): View
385+
public function withStyles($name, $deps = [], $ver = false, $media = 'all'): View
380386
{
381387
_deprecated_function(__METHOD__, '1.6.1', 'withStyle()');
382388

383-
return $this->withStyle($name, $deps, $ver);
389+
return $this->withStyle($name, $deps, $ver, $media);
384390
}
385391

386392
/**
387-
* Load a new css resource in theme.
393+
* Load a new Javascript resource in theme.
388394
*
389-
* @param string $name Name of script.
390-
* @param array $deps Optional. Array of slug deps
391-
* @param array $ver Optional. Version.
395+
* @param string $name Name of script.
396+
* @param array $deps Optional. Array of slug deps.
397+
* @param string|false $ver Optional. Version.
398+
* @param bool|array $args Optional. Whether to enqueue the script in the footer. Default true.
392399
*
393400
* @return $this
394401
*/
395-
public function withScript($name, $deps = [], $ver = []): View
402+
public function withScript($name, $deps = [], $ver = false, $args = true): View
396403
{
397-
$this->scripts[] = [$name, $deps, $ver];
404+
$this->scripts[] = [$name, $deps, $ver, $args];
398405

399406
return $this;
400407
}
401408

402-
public function withScripts($name, $deps = [], $ver = []): View
409+
/**
410+
* Load a new Javascript resource in theme.
411+
*
412+
* @param string $name Name of script.
413+
* @param array $deps Optional. Array of slug deps.
414+
* @param string|false $ver Optional. Version.
415+
* @param bool|array $args Optional. Whether to enqueue the script in the footer. Default true.
416+
*
417+
* @deprecated 1.6.1
418+
*
419+
* @return $this
420+
*/
421+
public function withScripts($name, $deps = [], $ver = false, $args = true): View
403422
{
404423
_deprecated_function(__METHOD__, '1.6.1', 'withScript()');
405424

406-
return $this->withScript($name, $deps, $ver);
425+
return $this->withScript($name, $deps, $ver, $args);
407426
}
408427

409428
/**
@@ -437,7 +456,7 @@ protected function admin_enqueue_scripts()
437456
if (!empty($this->adminScripts)) {
438457
foreach ($this->adminScripts as $script) {
439458
$src = $this->container->js . '/' . $script[0] . '.js';
440-
wp_enqueue_script($script[0], $src, $script[1], $script[2], true);
459+
wp_enqueue_script($script[0], $src, $script[1], $script[2], $script[3]);
441460
}
442461
}
443462

@@ -476,7 +495,7 @@ protected function admin_print_styles()
476495
if (!empty($this->adminStyles)) {
477496
foreach ($this->adminStyles as $style) {
478497
$src = $this->container->css . '/' . $style[0] . '.css';
479-
wp_enqueue_style($style[0], $src, $style[1], $style[2]);
498+
wp_enqueue_style($style[0], $src, $style[1], $style[2], $style[3]);
480499
}
481500
}
482501

@@ -504,7 +523,7 @@ protected function wp_enqueue_scripts()
504523
if (!empty($this->scripts)) {
505524
foreach ($this->scripts as $script) {
506525
$src = $this->container->js . '/' . $script[0] . '.js';
507-
wp_enqueue_script($script[0], $src, $script[1], $script[2], true);
526+
wp_enqueue_script($script[0], $src, $script[1], $script[2], $script[3]);
508527
}
509528
}
510529

@@ -531,7 +550,7 @@ protected function wp_print_styles()
531550
if (!empty($this->styles)) {
532551
foreach ($this->styles as $style) {
533552
$src = $this->container->css . '/' . $style[0] . '.css';
534-
wp_enqueue_style($style[0], $src, $style[1], $style[2]);
553+
wp_enqueue_style($style[0], $src, $style[1], $style[2], $style[3]);
535554
}
536555
}
537556

0 commit comments

Comments
 (0)