You could use anonymous functions in PHP 5.3+ to do this.
<?php
function addThemeJS($enqueueThemeJS, $handle, $src, $deps, $ver, $in_footer)
{
add_action('wp_enqueue_scripts', function() use ($handle, $src, $deps, $ver, $in_footer) {
wp_enqueue_script($handle, $src, $deps, $ver, $in_footer);
});
}
If you’re using this a personal project where you know the server has 5.3+ you would be okay if a bit weird. If it’s something you want to release in the WP.org repo, you probably want to find another way.
You might be better of creating some sort of wrapper object and using this.
<?php
// add the action
WPSE74479_Enqueue::init();
// register scripts...
WPSE74479_Enqueue::register('modernizr', THEME_JS_DIR . "/plugins/modernizr.custom.js", array(), false, false);
class WPSE74479_Enqueue
{
private static $ins = null;
private $scripts = array();
public static function instance()
{
is_null(self::$ins) && self::$ins = new self;
return self::$ins;
}
public static function init()
{
add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue'));
}
public static function register($hndl, $src, $deps=array(), $ver=null, $footer=false)
{
self::instance()->scripts[$hndl] = array(
'src' => $src,
'deps' => $deps,
'ver' => $ver,
'footer' => $footer,
);
}
public function enqueue()
{
foreach($this->scripts as $hdnl => $script)
{
wp_enqueue_script(
$hndl,
$script['src'],
$script['deps'],
$script['ver'],
$script['footer']
);
}
}
}