There is no functions in wordpress to handle transactions but you can easily use the $wpdb object to make a simple query to achieve this. The following function will start a transaction and then insert a new user into the database and finally rollback the current transaction. In order to make the transaction permanent you would instead use $wpdb->query('COMMIT');
function test_transaction() {
global $wpdb;
// begin transaction
$wpdb->query('START TRANSACTION');
$user = array(
'user_pass' => 'sample_password',
'user_login' => 'sample_login',
'user_email' => '[email protected]',
'first_name' => 'sample_firstname',
'last_name' => 'sample_lastname',
);
$user_id = wp_insert_user($user);
// roll back everything - e.g remove the new user record from the database
$wpdb->query('ROLLBACK');
};
Related Posts:
- How to get the list of WooCommerce product image of a certain category from database?
- How to make WordPress plugin check for database changes and then do something?
- How to Join two tables from separate databases within WordPress
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- register_activation_hook isn’t adding table to DB
- What SQL / WordPress queries would need a nonce?
- Importing Geo data into wordpress database
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- $wpdb->insert() does not Insert record in a table
- Use $wpdb or other PHP script method to find/replace in WP database
- How can I add a new row in a separate database when someone registers via WordPress?
- Pull MySQL data from multiple tables and merge into 1 PHP array
- Use variable in SQL statement
- mySQL queries are executed twice on wordpress website
- making php value numeric
- Database SQL query error
- How to run complex query using PHP
- Inserting other fields to existing registration form in a WordPress theme
- SQL Query Search page
- can’t delete a row from post_meta table
- Conditional statement within WP SQL query
- Deprecated: mysql_connect()
- PDO with INSERT INTO through prepared statements
- Creating a search form in PHP to search a database?
- Commands out of sync; you can’t run this command now
- Fatal error: Call to a member function query() on null
- Query both first_name and last_name from wp_usermeta at the same time
- Alter query on edit.php
- How to add query vars with paginated URLs?
- WordPress will not operate correctly
- simple wordpress ajax plugin not working when not logged in
- Install will not load: PHP does not have MYSQL installed
- Insert post without actions/hooks
- Import 10,000 Users into WordPress WITH a specific ID for each user
- if statement on database query
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Unusable menus and “Illegal widget setting ID: nav_menu_item[]” error
- How to get the post_id from postmeta
- Sortable admin column for one meta key with three possible meta values
- WordPress Ajax Custom Query – High CPU LOAD
- AJAX in WordPress, sending coords data to MySQL and show after into map
- Styling images coming from another blog
- How to generate page content from database the right way?
- Query String being Removed Creating a Pagination Issue within a Custom Plugin
- Ajax $wpdb not returning table data
- Converting MYSQL to WordPress $WPDB
- Custom Plugin For Converting CSV To MySQL
- phpMyAdmin displays error when importing database
- Preferred Method of debugging a wordpress SQL calls?
- Checking for new message using AJAX and PHP. Server overload?
- How to check if a meta value has already been assigned to any user?
- wp query foreach deleting record returning only first or last item
- inserting a post from an extern php file but post content doesn’t show on wp site
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- $wpdb->wp_users returning empty value for
- Using custom tables for old posts
- Help with a $wpdb MySQL Query
- How i can obtain all the post meta for a specific post as an array?
- Multiple meta_key in one global $wpdb;
- WordPress member notification
- Moving wordpress site from localhost to live server using GoDaddy cPanel
- How does WP work in conjunction with a web server?
- Location of core code for database connection and get_header
- Creating Database Table vs. Adding MetaData to Post & User
- WordPress and MySQL: trying to print data using PHP from user_meta custom field data
- Most commented posts by time period (last 12h, last 24h and etc)
- Hide posts if user is added to it WP_query
- How to unserialize data from MySQL
- PHP -> SQL Query with Summing
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- Known Issues in WordPress When Upgrading PHP to ver 7
- Get the id of the row from database on click of a button [closed]
- WPDB secure custom form
- Remove password protection from all posts
- SQL error with custom query
- Modify WooCommerce used to get all orders in dashboard
- WordPress SQL Prepare
- Run a sql (update) after 12 hours after the user login. Woocommerce users
- How to get database connection details without longing to cpanel in WordPress?
- Weird fonts showing which are coming from database
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- WordPress Bad Request Error 400
- I am facing this error Your PHP installation appears to be missing the MySQL extension which is required by WordPress
- What is the correct way to search 3 custom fields only in WordPress?
- cant insert data in a custom table in phpmyadmin
- How to import woocommerce custom fields data into another site?
- Collect all events in one year
- autocomplete in wordpress using ajax with json-data
- New database entry to trigger runing PHP/SQL query through link with token, without logging into the website
- Query doesn’t display text data with apostrophes
- I want show only data for today
- Getting error in sql query
- user update profile for custom code
- How to export database correctly for local to online
- How to pass username into form that sends data to database
- Your PHP installation appears to be missing the MySQL … After deleting and restarting from cpanel
- How to sort search result by post_title, then by post_content
- what to do after instlling cyberpanel on VPS
- Can’t insert into a database wordpress
- Updates applied to staging WordPress site affecting production even with different databases