Update wprest.php

This commit is contained in:
Namhyeon Go 2018-12-30 15:08:20 +09:00 committed by GitHub
parent 2508024ec4
commit 7803edba07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -173,23 +173,40 @@ if(!function_exists("authenticate_wp")) {
} }
if(!function_exists("write_wp_post")) { if(!function_exists("write_wp_post")) {
function write_wp_post($wp_server_url, $access_token, $title, $content, $author=1, $status="publish") { function write_wp_post($wp_server_url, $access_token, $data=array()) {
$response = get_web_page(get_web_build_qs($wp_server_url, array( $default_data = array(
"title" => "Untitled",
"content" => "insert your content",
"author" => 2,
"status" => "publish",
"categories" => ""
);
foreach($data as $k=>$v) {
$default_data[$k] = $v;
}
$response = get_web_json(get_web_build_qs($wp_server_url, array(
"rest_route" => "/wp/v2/posts" "rest_route" => "/wp/v2/posts"
)), "jsondata", array( )), "jsondata", array(
"headers" => array( "headers" => array(
"Content-Type" => "application/x-www-form-urlencoded", "Content-Type" => "application/x-www-form-urlencoded",
"Authorization" => "Bearer " . $access_token "Authorization" => "Bearer " . $access_token
), ),
"data" => array( "data" => $default_data
"title" => $title,
"content" => $content,
"author" => $author,
"status" => $status
)
) )
); );
return $response; return $response;
} }
} }
if(!function_exists("get_wp_categories")) {
function get_wp_categories($wp_server_url, $access_token) {
$response = get_web_json(get_web_build_qs($wp_server_url, array(
"rest_route" => "/wp/v2/categories"
)), "get");
return $response;
}
}