When using Ajax API, and you want to make the ajax callback available for non-logged users, you need to add 2 actions, "wp_ajax_{$action}"
and "wp_ajax_nopriv_{$action}"
.
Using only the first action, the callback will be called only for logged users, using only the second it will be called only for non-logged visitors.
Try this:
function check_username() {
$uname = filter_input( INPUT_POST, 'user', FILTER_SANITIZE_STRING );
wp_send_json( array(
'user_exists' => get_user_by( 'login', $uname ) ? 'true' : 'false'
) );
}
add_action('wp_ajax_check_username', 'check_username');
add_action('wp_ajax_nopriv_check_username', 'check_username');
Related Posts:
- Can i check if user is doing any ajax request?
- How to add default images into theme customizer image control?
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Validate a users email address when using gmail to register
- Click loads template via ajax
- How to speed up admin-ajax.php in wordpress
- get post based on category chosen in drop down – The ajax method
- How to store data from multiple forms using ajax and php
- PHP 8, AJAX mail form to function.php doesn’t work
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- Why ajax doesn’t work on certain wordpress hooks?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- dynamic dependent select dropdown
- how to make custom ajax handler?
- How to disable controls in theme customizer?
- is_user_logged_in() not working in AJAX validation call
- Using data sent via AJAX in multiple functions on a WP plugin
- Function won’t run onclick using Ajax
- Simple AJAX notification when the new post is added to the database
- Why i can’t get custom fields value or post ID via Ajax?
- Post not populating for custom post type based on category selection
- How to get post category list as select in front-end?
- Is there a hack for using is_page() within the function.php file?
- Execute Jquery when a specific page in my plugin is loading
- AJAX function not working [closed]
- Disclaimer that will show every refresh of the page
- Database entry removed on browser refresh, Ajax PHP jQuery
- Store ajax data in PHP variable
- Multiple AJAX handler functions conflict in functions.php
- Ajax filter with loadmore button
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- register_block_type is not working properly
- get_the_author_meta( ‘ID’ ) just return 1
- Update $wpdb query with AJAX
- Can an AJAX callback function access a PHP variable which was defined during initial page load?
- WordPress Ajax filter: Create two loops for different output styles?
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Offset with ajax load more posts duplicates
- ajaxurl usage for a custom function
- How to call a function from functions.php with ajax?
- Custom Post type Ajax search results
- Find the method which AJAX GET calls
- AJAX Returning Way Too Many Posts
- wordpress ajax return 0
- wp_delete_comment is doing nothing
- Modify category archive page loop on functions.php
- Registration form not registering First and Last name
- Modify php code to pass a page id as a parameter in order to create a breadcrumb
- ajax form function error
- AJAX: WordPress filters inside $html do not work as intended
- Adding “Remember Me” in custom login
- Retrieve POST data from AJAX call
- How to check if new posts have been published since page load?
- Change the footer text on the login page
- Rewriting search and pagination base
- Copyright info change in Theme Child PHP
- Update WordPress Custom Field with AJAX on cached page
- Create an array from an array
- Using wp_get_image_editor in a standalone script
- Can I change a variable in a content part while calling it?
- PHP Deprecated: WP_RSSjb has a deprecated constructor
- Returning a value from a PHP page
- Shortcode return function with link href inside PHP
- Set WordPress Default Template
- Can’t get page content in WordPress
- Why is $_REQUEST an empty array in admin-ajax.php?
- How to insert a single row to WP database table?
- Get date numerical and separate?
- How to check if a meta value has already been assigned to any user?
- How to call plugin function per site in a multisite?
- Pagination broken on is_front_page()
- Missing a text-domain esc_attr_e
- Extract and display user infromation on an automatically created page
- Programmatically revert to backup .htaccess a possibility?
- WordPress Conditional / Multiple Taxonomy Query
- Execute PHP code only with specific user role
- WordPress User Meta value variable into Google Gauge Chart
- PHP function for horizontal Woocommerce thumbnails and badges
- How to call my PHP function with AJAX ? wp_query
- Embed video from streamtape using direct link
- Is there a PHP function that will return the block ID generated by WordPress?
- Creating a Function and Call It
- WooCommerce display price before add to cart [closed]
- Show sidebar only to author of post
- how to add custom select field to wordpress edit page
- WordPress ajax filter returning all posts when it should be filtering by category
- Theme editing “post thumbnail” help
- Prepared DB Query from _POST array
- How to Request a User to Register on Landing at a Site, Then Automatically Delete the Users Password on Logout?
- Custom HTML form using PHP – help with ajax/username validation
- Matching multi user
- Where can I find the declaration of `$_wp_theme_features`?
- redirect 301 with special character like WIX site “#!”
- auto metakey value on post tile
- How I can add div to menu?
- How to print redirected query string variables to the page?
- Admin-area broken through weird issues
- Check if values exists DB
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- How to modify this function to exclude also the post belonging to a specific category?