Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. $post_data = array(
  2. 'post_title' => '',
  3. 'post_type' => 'post',
  4. 'post_content' => '',
  5. 'post_status' => 'draft',
  6. 'post_author' => 1
  7. );
  8.  
  9. $post_id = wp_insert_post( $post_data );
  10.  
  11. add_filter('pre_post_title', 'wpse28021_mask_empty');
  12. add_filter('pre_post_content', 'wpse28021_mask_empty');
  13. function wpse28021_mask_empty($value)
  14. {
  15. if ( empty($value) ) {
  16. return ' ';
  17. }
  18. return $value;
  19. }
  20.  
  21. add_filter('wp_insert_post_data', 'wpse28021_unmask_empty');
  22. function wpse28021_unmask_empty($data)
  23. {
  24. if ( ' ' == $data['post_title'] ) {
  25. $data['post_title'] = '';
  26. }
  27. if ( ' ' == $data['post_content'] ) {
  28. $data['post_content'] = '';
  29. }
  30. return $data;
  31. }
  32.  
  33. add_filter( 'wp_insert_post_empty_content', '__return_false' );
  34.  
  35. $post = wp_insert_post( $post_args );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement