Hello everyone I have this CURL that works if I put the "wp_create_nonce" cookie user manually. And when I execute the php from my browser with the user logged in.
The problem is to get the "wp_create_nonce" of the user from the cookies, is there any way to get it or simulate it?
The problem is when I run the php from the Cron it doesn't take the current session from the CURL to create the wp_create_nonce
Code CURL PHP
//We get wp_create_nonce from the current user logged
//$fb_product_id = 27540 is the ID of the product.
$nemo = wp_create_nonce( 'update-post_'.$fb_product_id);
$nemowoo = wp_create_nonce( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
//Start CURL
$chanelfacebook = curl_init();
curl_setopt($chanelfacebook, CURLOPT_URL, 'https://myserverexample.com/wp-admin/post.php');
curl_setopt($chanelfacebook, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($chanelfacebook, CURLOPT_POST, 1);
curl_setopt($chanelfacebook, CURLOPT_POSTFIELDS, "_wpnonce=".$nemo."&user_ID=1&action=editpost&post_ID=".$fb_product_id."&woocommerce_meta_nonce=".$nemowoo."&_wc_pre_orders_enabled=yes&facebookpreloadedu=yes&save=Actualizar");
curl_setopt($chanelfacebook, CURLOPT_ENCODING, 'gzip, deflate');
$headersfacebook = array();
$headersfacebook[] = 'Authority: miserverexample.com';
$headersfacebook[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9';
$headersfacebook[] = 'Accept-Language: es-419,es;q=0.9,en;q=0.8';
$headersfacebook[] = 'Cache-Control: max-age=0';
$headersfacebook[] = 'Content-Type: application/x-www-form-urlencoded';
$headersfacebook[] = 'Cookie: //cookie deleted for security//';
$headersfacebook[] = 'Origin: https://myserverexample.com';
$headersfacebook[] = 'Referer: https://myserverexample.com/wp-admin/post.php?post='.$fb_product_id.'&action=edit';
$headersfacebook[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36';
curl_setopt($chanelfacebook, CURLOPT_HTTPHEADER, $headersfacebook);
$result = curl_exec($chanelfacebook);
if (curl_errno($chanelfacebook)) { error_log( print_r( "Error de Curl EN STOCK: ".curl_error($chanelfacebook), true ) ); }
curl_close($chanelfacebook);
The problem is creating the wp_create_nonce by doing it manually in the cron from the browser where the user is logged in works.
But if it is done from the cron when there is no user, it does not work.
How to solve it?
I can think of maybe an impersonate user to generate the code "wp_create_nonce"
P.D: 1.- I am doing CURL to the same origin server. 2.- CURL works fine if I run it from the browser where the curl cookie user is logged in.
In short I need to simulate the "wp_create_nonce" by user_id is this possible?
Example:
wp_create_nonce( 'update-post_'.$fb_product_id, $simulateiduser);