is_admin() and DOING_AJAX in WordPress Plugins
-
Im developing a WordPress-plugin, where the main file of the plugins includes a PHP-file depending on (supposed to at least) if you are back-end or front-end.
As the is_admin() returns true on AJAX requests, I have used the DOING_AJAX constant to check whetever AJAX is done or not:
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) { require_once('admin/functions_admin.php'); } else { require_once('public/functions_public.php'); }The correct file is loaded in wp-admin. The correct file is loaded front-end. Ajax-requests works front-end – but not back end. The “if” is not executed when doing Ajax back-end with this code.
When adding the following “else if” code it works back-end, but then not frond-end of course:
else if ( is_admin() ) { require_once('admin/functions_admin.php'); }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘is_admin() and DOING_AJAX in WordPress Plugins’ is closed to new replies.