Adds Ajax in WordPress with a few lines of code. Adding Ajax is now simple…
Developers can now add Ajax by passing three parameters (name of action, PHP callback, and javascript path) to the toria_add_ajax() function using the Tori Ajax plugin.
Documentation
Please check out the Tori Ajax plugin Documentation
About
This is an easy-to-use dev tool for adding Ajax in word press.
Screenshots
Sample theme functions PHP code
Sample Javascript code
Sample theme functions PHP code for authenticated and non-authenticated Ajax actions.
Sample theme functions PHP code for authenticated Ajax actions.
Sample theme functions PHP code for non-authenticated Ajax actions.
FAQ
How to solve toria_add_ajax() is undefined?
- By ensuring the Tori Ajax plugin is installed.
- Use the if statement to check if the toria_add_ajax() exists first before using it. For example:
~~~~
if ( function_exists( ‘toria_add_ajax’ ) ) {
toria_add_ajax(
‘simple’,
‘my_simple_ajax’,
get_stylesheet_directory_uri() . ‘/inc/my_custom_ajax/toria_ajax.js’
);
}
~~~~
How to register action for both logged in and non logged in users?
You can use the fourth parameter to set the mode to ‘both’.
By default, the mode is set to ‘private’ for authenticated Ajax actions for logged-in users.
You can also use ‘public’ to expose the Ajax action to non-authenticated Ajax actions for logged-out users
Summary
both – For exposing the Ajax action to authenticated Ajax actions for logged-in users and non-authenticated Ajax actions for logged-out users.
Example
if ( function_exists( 'toria_add_ajax' ) ) {
toria_add_ajax(
'simple',
'my_simple_ajax',
get_stylesheet_directory_uri() . '/inc/my_custom_ajax/toria_ajax.js',
'both'
);
}
private – For exposing the Ajax action to authenticated Ajax actions for logged-in users.
Example
if ( function_exists( 'toria_add_ajax' ) ) {
toria_add_ajax(
'simple',
'my_simple_ajax',
get_stylesheet_directory_uri() . '/inc/my_custom_ajax/toria_ajax.js',
'private'
);
}
Or
if ( function_exists( 'toria_add_ajax' ) ) {
toria_add_ajax(
'simple',
'my_simple_ajax',
get_stylesheet_directory_uri() . '/inc/my_custom_ajax/toria_ajax.js'
);
}
public – For exposing the Ajax action to non-authenticated Ajax actions for logged-out users.
Example
if ( function_exists( 'toria_add_ajax' ) ) {
toria_add_ajax(
'simple',
'my_simple_ajax',
get_stylesheet_directory_uri() . '/inc/my_custom_ajax/toria_ajax.js',
'public'
);
}
ChangeLog
1.0.0
- The beginning of the Tori Ajax plugin.
1.0.1
- Fixed: Uncaught ArgumentCountError during the nonce check.
- Added JSON output for nonce messages.
1.0.2
1.0.3
- Fixed: PHP Notice undefined variable: allowed_html
1.1.0
- Compatible with WordPress 6.0.
- Added filters:
apply_filters( ‘toria/ajax/action’, $action );
apply_filters( ‘toria/ajax/php_callback’, $php_callback, $action );
apply_filters( ‘toria/ajax/script_path’, $script_path, $action, $php_callback );
apply_filters( ‘toria/ajax/mode’, $mode, $action, $php_callback, $script_path );
apply_filters( ‘toria/ajax/nonce’, $nonce, $action, $php_callback, $script_path, $mode );
apply_filters( ‘toria/ajax/ajax_object’, $ajax_object, $action, $php_callback, $script_path, $mode );
apply_filters( ‘toria/ajax/ajax_handle’, $ajax_handle, $action, $php_callback, $script_path, $mode );
apply_filters( ‘toria/ajax/script_depends’, $script_depends, $action, $php_callback, $script_path, $mode );
apply_filters( ‘toria/ajax/script_version’, $script_version, $action, $php_callback, $script_path, $mode );
apply_filters( ‘toria/ajax/script_in_footer’, $script_in_footer, $action, $php_callback, $script_path, $mode );
apply_filters( ‘toria/ajax/ajax_variables’, $ajax_variables, $action, $php_callback, $script_path, $mode );
1.2.0
*Added more parameters to some filters.
*The affected filters are:
apply_filters( ‘toria/ajax/ajax_object’, $ajax_object, $action, $php_callback, $script_path, $mode, $nonce );
apply_filters( ‘toria/ajax/ajax_handle’, $ajax_handle, $action, $php_callback, $script_path, $mode, $nonce, $ajax_object );
apply_filters( ‘toria/ajax/script_depends’, $script_depends, $action, $php_callback, $script_path, $mode, $nonce, $ajax_object, $ajax_handle );
apply_filters( ‘toria/ajax/script_version’, $script_version, $action, $php_callback, $script_path, $mode, $nonce, $ajax_object, $ajax_handle, $script_depends );
apply_filters( ‘toria/ajax/script_in_footer’, $script_in_footer, $action, $php_callback, $script_path, $mode, $nonce, $ajax_object, $ajax_handle, $script_depends, $script_version );
apply_filters( ‘toria/ajax/ajax_variables’, $ajax_variables, $action, $php_callback, $script_path, $mode, $nonce, $ajax_object, $ajax_handle, $script_depends, $script_version, $script_in_footer );
2.0.0
- Compatible with WordPress 6.1.1.
- Fix: Ajax in private mode is only accessible by signed-in users and those in public are only accessible by signed-out users.
- Pro version available.
2.0.1
- Fixed a PHP Deprecated notice.
2.0.2
- Added plugin meta links in wp-admin/plugins.php