0
Ich entwickle ein WordPress-Plugin. Ich würde gerne eine Variable in Aktion Hook Function Callback übergeben. Mein Code ist wie folgt.Passvariable in Aktionshaken
class myplugin {
function __construct() {
add_action('wp_loaded', array($this, 'init'));
}
public function init() {
add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));
//what I want is to pass the argument $mode in admin_scripts method to load only certain script according to the argument passed to method
//add_action('admin_enqueue_scripts', array($this, 'admin_scripts('caledar')')); ==> which will only load calendar script
}
public function admin_scripts($mode) {
switch($mode){
case 'calendar':
wp_enqueue_script('calendar-script', PLUGIN_URL . '/js/calendar.js', array('jquery'), '1.0.0');
break;
case 'alert':
wp_enqueue_script('alert-script', PLUGIN_URL . '/js/alert.js', array('jquery'), '1.0.0');
break;
}
}
}
new myplugin();
Ich bin mir nicht sicher, aber ich denke, Sie müssen eine globale var deklarieren, die alle Daten behandelt, die Sie in Hooks übergeben möchten ... – LoicTheAztec