48.1 F
Los Angeles
Monday, January 30, 2023

Apple March 8, 2022 Event

Apple announced several products during their March 8, 2022, event. Studio Display Mac Studio iPad air iPhone SE iPhone 13 and 13 Pro color addition Some of the products will...

Eastman files motion for exculpatory information and continuance

In response to the January 6 Select Committee Brief to Eastman Privilege Assertions, Eastman has filed a new motion with the court. A request for the court to require...

February 2022 Employment Report

U.S. Bureau of Labor Statistics reported today that total nonfarm payroll employment rose by 678,000. The unemployment rate edged down to 3.8 percent The employment number exceeded forecasts The...

The current state of inserting user information into a WordPress database

Writing PHP code is not easy for me. Easy ideas can be frustrating to complete. For example, inserting a new user into WordPress should be as simple as using the function wp_insert_user. An array is built and the information is inserted into the WordPress database. Only if it was that easy.

The XenWord plugin requires the ID of the user to match the XenForo member user_id. This means part of the array inserted into the WordPress database must be the ID. The WordPress developer site states the integer ID may be included in the array but the example provided on the page returns the newly created user_id. Most important, the page states, “If there is no ID, a new user will be created. If you pass an ID , the user with that ID will be updated.”

Since no user with that ID exists and the ID must be passed in the array, then wp_insert_user isn’t the best choice for adding the user information. Instead, an array is created and this information is added to the database by an insert command.

Once the information is added to the database then the role for the new user is added with the function set_role. Any meta information is added using the update_user_meta.

[pastacode lang=”php” path_id=”91c07754df8fe2580abb84586ce1b93a” file=”” highlight=”” lines=”” provider=”gist”/]

This is the only way I’ve found that works. Please let me know if you discover a better way to insert a new user into the database while passing the ID parameter.

Related Stories