Created
January 18, 2016 18:54
-
-
Save jdcauley/10044f193937ef6aa0fb 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
function call_routes() { | |
add_action( 'rest_api_init', function () { | |
register_rest_route( 'census/v1', '/test/', array( | |
'methods' => 'GET', | |
'callback' => array($this, 'test_action') | |
) ); | |
register_rest_route( 'census/v1', '/submit', | |
array( | |
'methods' => 'POST', | |
'callback' => array($this, 'submit') | |
) | |
); | |
} ); | |
} | |
function submit( WP_REST_Request $request ) { | |
$params= $request->get_params(); | |
$params['content_type'] = $_SERVER["CONTENT_TYPE"]; | |
$params['success'] = true; | |
$new_post = array( | |
'post_content' => 'no content yet',// The full text of the post. | |
'post_title' => 'Jordan Cauley', // The title of your post. | |
'post_status' => 'publish', | |
'post_type' => 'binary_census_subs' // Default 'post'. | |
); | |
$data = wp_insert_post( $new_post, $wp_error ); | |
$params['post'] = $data; | |
return $params; | |
} | |
function test_action(WP_REST_Request $request) { | |
return array('thing' => 'response'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment