If you need a processing endpoint with access to the WordPress API, use the admin_post_
action and eliminate the need to manually include wp-config.php
or any other WordPress files.
// add for logged-in visitors
add_action( 'admin_post_your_action', 'prefix_your_action_function' );
// for non logged-in visitors
add_action( 'admin_post_nopriv_your_action', 'prefix_your_action_function' );
function prefix_your_action_function() {
global $wpdb;
// your processing code here
}
Use admin_url
to target the file in WordPress context, like:
echo admin_url( 'admin-post.php?action=your_action' );
You can GET
or POST
whatever additional data you need to pass.
Related Posts:
- Problem migrating to localhost
- Can’t Install WordPress (local) Failed to open file wp-includes/wp-db.php
- How to use remote db tables in current config? [duplicate]
- Using wpdb to connect to a separate database
- WPDB Insert or if exists Update
- get_results using wpdb
- $wpdb won’t insert NULL into table column
- Please explain how WordPress works with MySQL character set and collation at a low level
- Get error messages when $wpdb->insert() returns false?
- Detecting errors generated by $wpdb->get_results()
- Does dbDelta delete columns as well?
- wpdb update add current timestamp not working
- How to fetch Data in WordPress using MySQLi or $wpdb
- Connect to database using wordpress wp-config file
- wpdb->insert multiple record at once
- WordPress Unit Testing – Cannot Create Tables
- How to define composite keys with dbDelta()
- Does wpdb add considerable overhead on queries with large result sets?
- Why does $wpdb return strings for mysql integer values?
- $wpdb->prepare() warning in WordPress 3.5
- Inserting data into custom tables
- Hook into $wpdb
- Display data from a non wordpress database on a page template
- How does $wpdb handle COUNT(*)
- How might I retrieve a featured post image from an external WP site and display it as a link back?
- WordPress database error: [Query was empty] [closed]
- Export wordpress table to excel
- How to close wpdb connection? [duplicate]
- Inserting Post Meta From SQL
- Why does dbDelta() not catch MysqlErrors?
- Accessing two databases
- Connecting to external oracle database
- Can’t save ajax value to database
- Custom DB_COLLATE (collation) value not working on fresh install?
- What causes the “max_user_connections” warning on WordPress frontend?
- $wpdb variable throw this error Call to a member function get_results() on a non-object in
- Updating all rows of table with $wpdb
- Safe way to find last inserted id in a table?
- How to execute mulitple statement SQL queries using $wpdb->query?
- Is $wpdb->prepare escaping to much? How to use it properly?
- Database slowdown after update to 3.4.1
- When and why should I use $wpdb different return types?
- How wordpress accesses its own database
- Remove database entries where post_date > expiration date
- Error connecting to DB in /wp-includes/wp-db.php on line 1538 [closed]
- Why can’t I swap a DB in a WP install? [closed]
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- Get data from database using $WPDB
- How to use a different database to list and manage comments in the backend
- Getting all the users who have author privilege
- Multiple postmeta with same name for one post in wp_postmeta table
- WP Database Table to CSV file
- Can I have multiple database users within WordPress?
- Cannot update custom database table row
- wpdb_prepare with multiple or condition
- Show last modified date of database
- $wpdb->insert is not working
- Error establishing a database connection on Installation
- Extracting the post_id via the wp_insert_post action (external db query)
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- Moving WP from local server to live, error establishing a db connection
- In what part of the WordPress core does the users table and usermeta table get joined?
- Modify Database in Multi-Site wp_usermeta table
- Multiple wp_options tables to share content across installs
- Advanced SELECT query with condtional statements
- $wpdb doesn’t like to store arrays
- Select two sums with single get_var statement
- Connect to a remote database for wordpress in my own hosting server
- WordPress choose wrong database
- Redirecting to old domain after migration website
- Switching Databases in LocalHost
- Create table from array with prepare
- Update from 4.5 to 4.6 failing
- Localhost to Staging to Development Dynamic WP-CONFIG
- Does WordPress $wpdb functions wait when table is locked?
- How to share plugin created database tables between two WordPress sites
- How Can I Put Meta_Compare in the Database-Query?
- WordPress running SQL query to update database from form
- $wpdb->insert Giving duplicates
- I’m not able to get access to $wpdb [duplicate]
- WPDB SQL query with prepare() returning variable, not db value
- $wpdb error (Call to a member function insert() on a non-object)
- Have working sql query… trying to adjust it to use $wpdb
- Is it important to have integers inserted using %d rather than %s?
- Problem in using wpdb
- $wpdb->query can’t insert data
- Custom WordPress Table wpdb
- How to fetch records from database WordPress
- Best practice to limit results in get_row()?
- Best practice to import user base (subscribers) from one website to another?
- AJAX wp-mysql running too slow
- CreateOrUpdate in WordPress
- Clear Terms from Taxonomy for Specific Post IDs?
- Is my way to change WordPress server is correct?
- Trouble running $wpdb->query() with last_insert_id
- How to get a list of WordPress default database tables?
- Connecting to a different database
- Using $wpdb | checking entered email against existing emails in db
- how to encyrpt DB_PASSWORD in wp-config
- Query Column of Specific ID from Database Table