Posted on Leave a comment

Do not use wp-load

When doing ajax calls within your custom plugins to custom server files, and in need of using WordPress functions, one might be attempted to call wp-load on the system. This is really bad practice as it loads the whole framework again.

Try this

add_action('wp_print_scripts','myscript');
function myscript() {
 
}
wp_enqueue_script('myscript','...myscript.js',...);

The bold parts need to matchup

add_action( ‘wp_ajax_myaf‘, ‘myaf‘ );

and is the function name

this is used when a user is not logged in

add_action( ‘wp_ajax_nopriv_myaf‘, ‘myaf‘ );

Leave a Reply

Your email address will not be published.

5 + one =