[wp-trac] [WordPress Trac] #55129: WP REST API - Updating "status" field on a "post" from "future" to "publish" does not work

WordPress Trac noreply at wordpress.org
Wed Feb 9 23:11:26 UTC 2022

#55129: WP REST API - Updating "status" field on a "post" from "future" to
"publish" does not work
 Reporter:  mcmwebsol     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  REST API      |     Version:  5.9
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:

Comment (by mcmwebsol):

 Replying to [comment:1 rafiahmedd]:
 > I just check the issue and I can see it's working perfectly fine with
 > {{{
 > Content-Type: multipart/form-data
 > }}}
 I tried it now with Content-Type: multipart/form-data using the below PHP
 code (sensitive information scrubbed) and it still does not update the
 status to "publish"

 $siteURL = 'https://subdomain.wpengine.com';
 $url = $siteURL.'/wp-json/wp/v2/posts/3302';
 $data = array(
   'status'  => 'publish'
 $username = 'user';
 $password = 'pass'
 posty($url, $data, $username, $password);

 function posty($url, $data, $username, $password) {

     $ch = curl_init($url);

     $headers = [
         'Cache-Control: no-cache',
         'Content-Type: multipart/form-data',
         'Accept: application/json'

     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_USERPWD, "$username:$password" );
     curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header
 info from response
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data
 instead of TRUE(1)
     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // use HTTP
 POST to send form data
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // for now..
     curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
     $resp = curl_exec($ch); //execute post and get results

     print " resp=$resp// ";

     $jsonResponse = json_decode($resp, TRUE);

     $newID = FALSE;

     if ( isset($jsonResponse['id']) ) {
       $newID = $jsonResponse['id'];
     else {
       echo '<div class="mcm-errors">An error occurred.  Error Code:
             ' Error Message: '.htmlentities($jsonResponse['message']).'

     return $newID;


Ticket URL: <https://core.trac.wordpress.org/ticket/55129#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list