“…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
- Objective Best Practices for Plugin Development? [closed]
- ajaxurl not defined on front end
- How do i best handle custom plugin page actions?
- How to create an API for my plugin?
- Is it ever okay to include inline CSS in plugins?
- Plugins in symlinked directories?
- Why does WordPress add 0 (zero) to an Ajax response?
- 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?
- How can I configure Docker for developing and deploying a custom theme?
- What do you think about custom designed plugin/theme options UIs?
- No Error Log File, no debug info
- Where to put third party PHP library?
- Saving data-URI to media library
- Is the new WordPress 3.1 admin bar pluggable and how can I extend it?
- How to use PanelColorSettings in custom Gutenberg block?
- Getting a peer review for my new plugin?
- Optimize shortcode callbacks
- Nonces can be reused multiple times? Bug / Security issue?
- How can I run AJAX on a button click event?
- Check for dependent plugin and if false dont activate plugin
- How-to implement admin Ajax inside an admin WP_List_Table?
- How to integrate a PHP webmail script into the backend of WordPress?
- Using filters and actions for plugin API?
- Is There A Hook To Process The Content Of The Text Widget?
- How to Change the Entire WordPress Admin panel Look and Feel?
- What is nonce and how to use it with Ajax in WordPress? [duplicate]
- How to log plugin errors to plugin error_log file
- Empty POST data on server on AJAX request using Angular $http
- Using AJAX in FrontEnd with WordPress Plugin Boilerplate (wppb.io)
- Which to use to execute code during the saving of a plugin settings page?
- Allowing for multiple template views on the Gallery Settings page when using the Visual Editor
- Build path for a custom portfolio plugin
- Using Primary Color in Plugin Block
- Using AJAX in a plugin to submit form – REALLY confused
- wp_localize_script $handle
- When is it appropriate to put functions on page template vs. functions.php?
- Custom theme sufficient or custom plugin neccessary for this feature set?
- When to check if a function exists
- How to enable users to down-vote in this simple voting counter (that uses the post meta)?
- How to create custom home page via plugin?
- Sessions not creating correctly in custom function
- get all products of one category
- Get returned variable from a function to add_shortcode function
- Featured Image not showing in admin
- Plugin Settings not Saving on Ajax re-ordered table
- How to use wp_set_password in a plugin?
- How to post form in ajax mode and handle it in wordpress
- Using Ajax call in jQuery doesn’t work in widget
- How Can I setup WP CLI on Windows development machine running AMPPS?
- Timeout on Admin-Ajax?
- Admin-ajax.php appending a status code to ajax response
- Nuance in adding CPT and TAX to a submenu
- Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?
- Comment `Reply` link doesn’t work if comments are loaded from ajax
- Delete a specific item menu when I deactivate my plugin
- Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?
- Ajax in WordPress – path issue
- Cannot search post by taxonomy
- WordPress Ajax callback function from plugin – OOP
- Get the password key when using the wp_new_user_notification_email filter
- WP AJAX is not working, always returns 0
- Ensure function has completed before allowing another Ajax call
- Order properties should not be accessed directly
- Frontend Ajax call not working using wp_ajax, wp_enqueue_script and wp_localize_script
- 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
- WordPress not working on localhost
- Adding functions to hooks from within a class
- how to use hook deleted_user into custom function to delete user from custom table
- Disable The Events Calendar plugin from loading its scripts
- Where to store the name of a custom table?
- include wp-blog-header not working on MAMP
- Any problem in using native jquery ajax style instead of using admin-ajax.php?
- Applying OO patterns and principles to plugin development
- WordPress is automatically linking plain text email addresses
- Is Using WordPress Supplied WYSIWYG Advisable?
- ServerSideRender and Media Object: attributes passing image data object to php renderer even though it’s not set
- Slow WP_query due to nested wp_query. Need Suggestions
- Show special field when correct shipping is chosen
- .mo translation strings not loading in PHP scripts that handle AJAX calls
- Is it possible to change a term slug before being saved to the database?
- How can I pass get_the_author_meta(‘user_email’) through the REST API?
- Maximum lifetime for nonce
- Clearing caches on plugin uninstall
- How to use a hook to override an update_post_meta call in a plugin?
- Add code inside specific wordpress standard function
- Custom Taxonomy to dropdown box on adminside wordpress
- Woocommerce checkout update totals with datepicker
- Create a free scripts and styles template within a plugin
- Including the necessary functions for a custom ajax registration form
- How can I rewrite a URL to pass requests to a custom method via AJAX? (I can’t use admin-ajax.php)
- How to localize admin.php only once
- How to modify the comments to be displayed in a post?