“…I need them to authenticate the database connection.”
Not exactly sure this is what you want, but in your ajax function you can connect to and use a database if you declare the global variable $wpdb.
Here’s a simple example:
function api_list_devices() {
global $wpdb;
$name = $_POST['name']; // ajax call sends "name"
// try to insert $name into "people" tables "name" column
if($wpdb->insert('people',array(
'name'=>$name
))===FALSE){
echo "Error";
}
else {
echo "Person '".$name. "' has been successfully added;
}
}
Related Posts:
- Adding callback function for wp_ajax_ has no effect
- WP_LOCALIZE_SCRIPT doesn’t work
- Rate limiting ajax requests in WordPress
- In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
- Plugin Form Submission Best Practice
- Best way to abort plugin in case of insufficient PHP version?
- What do you think about custom designed plugin/theme options UIs?
- Where to put third party PHP library?
- Optimize shortcode callbacks
- Nonces can be reused multiple times? Bug / Security issue?
- How-to implement admin Ajax inside an admin WP_List_Table?
- How to integrate a PHP webmail script into the backend of WordPress?
- How to log plugin errors to plugin error_log file
- Using AJAX in FrontEnd with WordPress Plugin Boilerplate (wppb.io)
- Which to use to execute code during the saving of a plugin settings page?
- Custom theme sufficient or custom plugin neccessary for this feature set?
- How to create custom home page via plugin?
- Sessions not creating correctly in custom function
- Featured Image not showing in admin
- Plugin Settings not Saving on Ajax re-ordered table
- Admin-ajax.php appending a status code to ajax response
- Get the password key when using the wp_new_user_notification_email filter
- Ensure function has completed before allowing another Ajax call
- How to deal with equal & similar arguments for a function?
- Fetching the value of forms in WordPress AJAX
- Executing a function upon webhook calling wordpress
- Customizer: widget-synced triggers twice
- Disable The Events Calendar plugin from loading its scripts
- Any problem in using native jquery ajax style instead of using admin-ajax.php?
- WordPress is automatically linking plain text email addresses
- Is Using WordPress Supplied WYSIWYG Advisable?
- Show special field when correct shipping is chosen
- .mo translation strings not loading in PHP scripts that handle AJAX calls
- Maximum lifetime for nonce
- Custom Taxonomy to dropdown box on adminside wordpress
- How to localize admin.php only once
- How to modify the comments to be displayed in a post?
- Create a new post using rest api and save featured image using an external image url
- Incorporate small angular feature in my wordpress site
- wp.template() returns tags in Ajax response
- How to get Metabox custom field to show checked if value is updated using post meta query?
- Fatal error: Uncaught Error: Call to undefined function get_option()
- Use just a shortcode from another page
- template_redirect or admin-ajax.php?
- how to get context information inside my funcion
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- AJAX form post returns 0
- Update Data parameter of a wp_localize_script() call
- Bad Request in AJAX
- ajax recursive calls on wordpress returning answers outsite the function scope
- Ajax submit result opens in admin-ajax.php
- Show message from backend
- Are there any security risks when submitting data-attribute data through AJAX?
- Why in this archive page that call query_posts() function show only the last 10 posts?
- insert query on a custom table using ajax with jQuery plugin Jeditable
- Plugin AJAX Save to Custom Table
- Data not insert and update through ajax and jQuery in admin page?
- WP ajax requests not stacking?
- AJAX button with success callback. (Titan Framework)
- how to save wp_editor html content in options table
- AJAX call returns ‘testtest0’ instead of ‘test’ – why?
- Best practice for plugin: always detect admin-ajax call?
- Why is the form not updating when I select a new sector from the list?
- Plugin Form Submitting to admin-ajax.php instead of admin-post.php
- How to remove/replace current page template?
- How to determine which capability to use?
- Get cat parameter from admin-ajax
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- How to control ajax calls without effecting memory of server?
- Forbidden Error in ajax call with wordpress
- “add to cart” links css class “ajax_add_to_cart” doesn’t show in woocommerce in widget sidebar
- ajax call return 406 not acceptable for non logged users only
- Does $this context change in an AJAX callback?
- WordPress Ajax not returning Response
- Performing ajax request in wordpress
- Inserted data from database does not showing on front-page without referesh page?
- wp_ajax function return the html page
- Using JavaScript in WordPress page to call for server data using AJAX
- How To do Ajax In WordPress Custom Plugin?
- external Integration with wordpress timeout error
- Making adding info to an overlay bio easy for average user?
- Implementing Select2 plugin into WordPress
- WP Ajax on page load not working on bluehost but was working on Godaddy
- Ajax not working to insert, query and result data
- Associating special meaning with user id 0
- Can I access WordPress API’s from within plugin scripts?
- Link to a admin submenu item using a custom link
- Change the search results header from plugin
- Dynamic banner for use on external sites
- Can’t get query string in ajax call
- Ajax url value to pass ‘variable’ to use in query
- An adiitional function fires on my AJAX submit
- Developing Themes on WordPress, Looking for Excellent Tutorials [closed]
- How to Implement SAM Broadcaster with WordPress? [closed]
- Extend WP_List_Table class – Edit wp_usermeta – WPPB.me Boilerplate – Action error
- Trigger a JavaScript function based on the data fetched from Woo commerce hook
- Is there any other ways to replicating changes on live from staging without pushing from git
- Can I log the searches that are returning 404 in the DB?
- Why my admin-ajax url returns 0 even after adding echo and die() at the end of function?
- WordPress plugin boilerplate AJAX functionality