I’m still not clear on this solution. The link seems to suggest moving the enqueue out of admin_head filter, but I’m fairly new to Vite, so could someone provide more details? As with the original question, I’m trying to get Ajax working on the front end of my WP site.
My actual php function called by this jquery function is in ajax.php (which is loaded through functions.php), which also includes:
<?php
namespace App;
class Ajax {
public function __construct() {
add_action('wp_ajax_event_month', [$this, 'event_month']);
add_action('wp_ajax_nopriv_event_month', [$this, 'event_month']);
}
public function event_month() {
wp_send_json_success('Month test');
}
Before Vite, I would use the bundle (as described in the initial question). But the following does not work (this is in add_action(‘wp_enqueue_scripts’ …):
When I run it, I get frontend_ajax_object is not defined. I could pull the AJAX code into a separate js file, enqueue and localize it separately, but it seems to me there should be a way to incorporate the “wp_localize_script” using the Sage infrastructure