Best place to load wp_ajax_the_ajax_hook action in plugin

I don’t know if it is the ‘best’ place, but get_header is early enough to still enqueue scripts: function at_set_header () { global $post, $has_the shortcode; if ( is_object( $post ) && has_shortcode( $post->post_content, ‘shortcode_name’) ) { $has_the_shortcode = true; wp_enqueue_script( ‘my-ajax-handle’, FAU_PLUGIN_URL . ‘js/ajax.js’, array( ‘jquery’ ) ); wp_localize_script( ‘my-ajax-handle’, ‘the_ajax_script’, array( ‘ajaxurl’ => … Read more

Setting value of session with Ajax not working

For me, Session with ajax working with the following code snippet add_action(‘init’, ‘start_session’, 1); function start_session(){ if(!session_id()) { session_start(); } } // form submition add_action( ‘wp_ajax_nopriv_form_response’, ‘form_response’ ); add_action( ‘wp_ajax_form_response’, ‘form_response’ ); function form_response() { $_SESSION[‘value’] = $_POST[‘formFiled’]; } //Session value if(isset($_SESSION[‘value’] )) { echo $_SESSION[‘value’]; }