Ecommerce Shopify WordPress Discussion

How to create WordPress application password without loading wordpress core files?

I am using Laravel 10 to build a CMS manager to remotely manage multiple CMS at single panel. One of the CMS available is WordPress. Most API functions works well such as publishing posts, creating tags, etc. All I need to do is to create an application password manually and paste to my Laravel CMS manager. As I can also access the mysql of the WordPress sites, I would like to create the application password programmatically via Laravel instead of manually at WordPress dashboard. My thought is first create a hashed password and save directly to database wp_usermeta table. However, the programmatically generated password seems not correct. WordPress return 401. The following is how I generate the application password. As WordPress uses WP_Application_Passwords::create_new_application_password() to generate the password which the hashing of $new_password is done by wp_hash_password($new_password), so I load PasswordHash in my Laravel CMS manager. function wp_hash_password($password) { $wp_hasher = new \PasswordHash( 8, TRUE ); $hashed_password = $wp_hasher->HashPassword(trim($password)); return $hashed_password; } Then I prepare the format for wp_usermeta. $api_password = 'kNRC ERNk ZJJ4 nrL2 EgKI HctJ'; //also tried without space $this->wp_hash_password($api_password) $api_password_data_array[] = [ 'uuid' => str()->uuid()->toString(), //6890ea8f-e7c9-4ab0-b51a-c2a3d724eecc 'app_id' => '', "name" => "ai2", "password" => $hashed_password, //$P$Bl7AWybOsI3/JJIHpvv/rf1JrwZeeK0 "created" => time(), 'last_used' => null, 'last_ip' => null, ]; //Connect remote wordpress database. DB::connection($connection_name) ->table('wp_usermeta') ->updateOrInsert( [ 'meta_key' => '_application_passwords' ], [ 'user_id' => 1, 'meta_value' => serialize($api_password_data_array) ] ); The programmatically generated data structure created is exactly the same as when I manually create application password via wordpress dashboard. a:1:{i:0;a:7:{s:4:"uuid";s:36:"6890ea8f-e7c9-4ab0-b51a-c2a3d724eecc";s:6:"app_id";s:0:"";s:4:"name";s:3:"ai2";s:8:"password";s:34:"$P$Bl7AWybOsI3/JJIHpvv/rf1JrwZeeK0";s:7:"created";i:1708716939;s:9:"last_used";N;s:7:"last_ip";N;}} However, It's just not working. WordPress always return 401. Therefore, my question is: How to create WordPress application password and directly save to database without requiring the wordpress files?
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.