forked from nuriodaci/Blogger-To-Wordpress-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert.php
43 lines (31 loc) · 1.01 KB
/
insert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
require( '../wp-load.php');
require( '../wp-admin/includes/file.php');
require( '../wp-admin/includes/media.php');
require( '../wp-admin/includes/image.php');
if (isset($_POST)) {
$name=$_POST['name'];
$content=$_POST['content'];
$tag=$_POST['tag'];
$img=$_POST['img'];
$tags=explode(",",$tag);
$user_id = get_current_user_id();
// Create post object
$my_post = array();
$my_post['post_title'] = $name;
$my_post['post_content'] = $content;
$my_post['post_status'] = 'publish';
$my_post['post_author'] = $user_id;
$my_post['post_category'] = array(0);
$my_post['tags_input']=$tags;
// Insert the post into the database
$postid=wp_insert_post( $my_post );
$image = media_sideload_image($img, $postid, $name);
$attachments = get_posts(array('numberposts' => '1', 'post_parent' => $postid, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC'));
if(sizeof($attachments) > 0){
// set image as the post thumbnail
set_post_thumbnail($postid, $attachments[0]->ID);
}
}
echo $name;
?>