Last active
February 27, 2017 18:23
-
-
Save anthonybudd/32c488e9244ea91960503ad9e4f89610 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
<?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