Last active
August 31, 2017 12:12
-
-
Save vladfil/e35fb592435a0e4307b22dea22fe7f6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Create post | |
| $('#send-post').click( function() { | |
| var title = $('.add-posts input[name="title"]').val(); | |
| var post = $('.add-posts textarea[name="post"]').val(); | |
| console.log(screenReaderText.nonce); | |
| $.ajax({ | |
| type: 'POST', | |
| url: 'http://wordpress.localhost.dev/wp-json/wp/v2/posts', | |
| beforeSend: function(jqXHR){ | |
| jqXHR.setRequestHeader('X-WP-Nonce', screenReaderText.nonce); | |
| }, | |
| data: { | |
| title: title, | |
| content: post, | |
| status: 'publish' | |
| }, | |
| }); | |
| } ); | |
| // Update post | |
| $('#update-post').click( function() { | |
| var title = $('.update-posts input[name="title"]').val(); | |
| var post = $('.update-posts textarea[name="post"]').val(); | |
| // console.log(screenReaderText.nonce); | |
| var id = $(this).data('id'); | |
| var url = 'http://wordpress.localhost.dev/wp-json/wp/v2/posts/' + id; | |
| $.ajax({ | |
| type: 'POST', | |
| url: url, | |
| beforeSend: function(jqXHR){ | |
| jqXHR.setRequestHeader('X-WP-Nonce', screenReaderText.nonce); | |
| }, | |
| data: { | |
| title: title, | |
| content: post, | |
| status: 'publish' | |
| }, | |
| }); | |
| } ); | |
| // Delete post | |
| $('#delete-post').click( function() { | |
| var id = $(this).data('id'); | |
| var url = 'http://wordpress.localhost.dev/wp-json/wp/v2/posts/' + id; | |
| $.ajax({ | |
| type: 'DELETE', | |
| url: url, | |
| beforeSend: function(jqXHR){ | |
| jqXHR.setRequestHeader('X-WP-Nonce', screenReaderText.nonce); | |
| }, | |
| }); | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment