The tricky part is that is_admin()
doesn’t mean "is the user an admin"—it means "is the current page an admin page (like wp-admin)?" So even if you're logged in as an admin, if you're on the front end of the site, is_admin()
will still return false.
That’s why your add_action('wp_ajax_mvp_reel_get_comments', ...)
wasn’t running—because the code was skipping it when not on an admin page, which is exactly where your AJAX call happens.
Best move: always register both wp_ajax_
and wp_ajax_nopriv_
outside any is_admin()
check. If you only want the actual function to run for certain users, do that inside the function using something like current_user_can()
.
That way, your AJAX hook is always ready when needed, but access is still secure and controlled.