Skip to content

Instantly share code, notes, and snippets.

@anthonybudd
Last active February 27, 2017 18:23
Show Gist options
  • Save anthonybudd/32c488e9244ea91960503ad9e4f89610 to your computer and use it in GitHub Desktop.
Save anthonybudd/32c488e9244ea91960503ad9e4f89610 to your computer and use it in GitHub Desktop.
<?php
Class CreatePost extends WP_AJAX
{
protected $action = 'create_post';
protected function run(){
if($this->isLoggedIn()){
$post = [
'post_status' => 'publish'
];
if( $this->requestType(['POST', 'put']) ){
$post['post_content'] = 'This request was either POST or PUT';
}else if( $this->requestType('get') ){
$post['post_content'] = 'This request was GET';
}
$post['post_title'] = sprintf('This post was created by %s', $this->user->data->user_nicename);
wp_insert_post($post);
$this->JSONResponse($post);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment