settings.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | if( isset( $_POST['wpcmp_submit_for_create_posts'] ) ){ |
| 4 | |
| 5 | if ( |
| 6 | ! isset( $_POST['wpcmp_nonce'] ) |
| 7 | || ! wp_verify_nonce( $_POST['wpcmp_nonce'], 'wpcmp_create_posts' ) |
| 8 | ) { |
| 9 | |
| 10 | print 'Sorry, your nonce did not verify.'; |
| 11 | exit; |
| 12 | |
| 13 | }else{ |
| 14 | |
| 15 | extract( $_POST ); |
| 16 | |
| 17 | if ( !empty( $wpcmp_posts_titles ) ) { |
| 18 | |
| 19 | $posts_titles = explode( "\n", $wpcmp_posts_titles ); |
| 20 | |
| 21 | $category_id = array(1); |
| 22 | |
| 23 | if ( !empty( $wpcmp_new_post_category ) ) { |
| 24 | |
| 25 | foreach ( $wpcmp_new_post_category as $id ) { |
| 26 | |
| 27 | if ( !in_array( $id, $category_id ) ) { |
| 28 | |
| 29 | $category_id[] = $id; |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | $created_posts = array(); |
| 35 | |
| 36 | foreach ( $posts_titles as $post_title ) { |
| 37 | |
| 38 | $post = array( |
| 39 | 'post_title' => wp_strip_all_tags( $post_title ), |
| 40 | 'post_content' => '', |
| 41 | 'post_type' => $wpcmp_new_post_type, |
| 42 | 'post_status' => $wpcmp_new_post_status, |
| 43 | 'post_author' => $wpcmp_new_post_author, |
| 44 | 'post_category' => $category_id |
| 45 | ); |
| 46 | |
| 47 | // Insert the post into the database |
| 48 | $post_id = wp_insert_post( $post ); |
| 49 | |
| 50 | if( !is_wp_error( $post_id ) ){ |
| 51 | |
| 52 | //the post is valid |
| 53 | $wpcmp_show_message = 'success'; |
| 54 | |
| 55 | $created_posts[] = $post_id; |
| 56 | |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if ( $wpcmp_show_message && $wpcmp_show_message == 'success' ) { |
| 61 | |
| 62 | $wpcmp_message = 'Posts Successfully Created!'; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | ?> |