I created my own javascript file and now I want to integrate into my module. I'm trying to do as told in this site https://developer.wordpress.org/reference/functions/wp_enqueue_script/ But it does not work, I don't understand why
P.S: I am in the main file of my module (exampe.php)
class exemple
{
public function __construct()
{
register_activation_hook(__FILE__, array('exemple_bd', 'install'));
register_uninstall_hook(__FILE__, array('exemple_bd', 'uninstall'));
include_once plugin_dir_path( __FILE__ ).'settings.php';
new Settings();
add_action('admin_menu', array($this, 'add_admin_menu'));
add_action('admin_init', array($this, 'load_JS'));
}
public function add_admin_menu()
{
add_menu_page('monTitre', 'Monplugin', 'manage_options','xxx', array($this, 'menu_html'),'dashicons-email');
add_submenu_page('xxx', 'NouveauTitre', 'NouveauTitre', 'manage_options', 'xxx', array($this, 'menu_html'));
}
public function load_JS()
{
wp_register_script('myfunction',plugins_url( '/js/function.js', __FILE__ ));
wp_enqueue_script('myfunction');
}