WP REST API Post Status Using JavaScript

I am getting my hands dirty in WP REST API. I have gone through a couple of tutorials and have a question using JavaScript to create a new post.

In this tutorial, the post var status = ‘draft’; (see code). So I am just worried that won’t anyone able to hack that status?

jQuery( document ).ready( function ( $ ) {
$( ‘#post-submission-form’ ).on( ‘submit’, function(e) {
e.preventDefault();
var title = $( ‘#post-submission-title’ ).val();
var excerpt = $( ‘#post-submission-excerpt’ ).val();
var content = $( ‘#post-submission-content’ ).val();
var status = ‘draft’; // this code

var data = {
title: title,
excerpt: excerpt,
content: content
};

$.ajax({
method: “POST”,
url: POST_SUBMITTER.root + ‘wp/v2/posts’,
data: data,
beforeSend: function ( xhr ) {
xhr.setRequestHeader( ‘X-WP-Nonce’, POST_SUBMITTER.nonce );
},
success : function( response ) {
console.log( response );
alert( POST_SUBMITTER.success );
},
fail : function( response ) {
console.log( response );
alert( POST_SUBMITTER.failure );
}

});

});

} );

Read more here:: WP REST API Post Status Using JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *