Create Page
function wpcreatepage(){
$title = $_REQUEST['title'];
$content = $_REQUEST['content'];
$userid = $_REQUEST['userid'];
$my_post = array(
'post_title' => wp_strip_all_tags($title ),
'post_content' => $content,
'post_status' => 'publish',
'post_author' => $userid,
'post_type' => 'page',
);
$pid = wp_insert_post( $my_post );
echo $pid;
die();
}
Retrieve Page
function wpeditpage(){
$pageid = $_REQUEST['pageid'];
$post = get_post( $pageid, ARRAY_A);
echo json_encode($post);
die();
}
Update Page
function wpupdatepage(){
$title = $_REQUEST['title'];
$content = $_REQUEST['content'];
$pageid = $_REQUEST['pageid'];
$my_post = array();
$my_post['ID'] = $pageid;
$my_post['post_title'] = wp_strip_all_tags($title);
$my_post['post_content'] = $content;
// Update the post into the database
wp_update_post( $my_post );
die();
}
Delete Page
function wpdeletepage(){
$pageids = rawurldecode($_REQUEST['pageids']);
$pageid = rawurldecode($_REQUEST['pageid']);
if(!empty($pageid)){
echo wp_delete_post($pageid);
}else if(!empty($pageids)){
$pageids = explode(",",$pageids);
foreach($pageids as $id){
echo wp_delete_post($id);
}
}
die();
}
No comments:
Post a Comment