Prevent empty posts from publish.
-
Hello,
I have a semi-automated blog witch uses RSS feeds to publish some posts.
My problem is that when I am authorizing automatic publish I am getting many empty posts published.
I do not know if the issue is coming from the RSS feed itself or from one of the other plugins I am using in my blog.
I tried three PHP codes in order to prevent posts with empty content or empty title, my objective is to save those posts as drafts.
function _myplugin_save_post_check($post_id) { if ( $parent_id = wp_is_post_revision( $post_id ) ) $post_id = $parent_id; $custom_feilds = get_post_meta( $post_id, 'whatever', true ); if ( empty( $custom_feilds ) ) { remove_action( 'save_post', '_myplugin_save_post_check' ); wp_update_post( array( 'ID' => $post_id, 'post_status' => 'draft' ) ); add_action( 'save_post', '_myplugin_save_post_check' ); } } add_action( 'save_post', '_myplugin_save_post_check' );
add_filter( 'wp_insert_post_data' , 'filter_post_data' , '99', 2 ); function filter_post_data( $data , $postarr ) { if( empty($data['post_title']) ) { $data['post_status'] = 'draft'; } return $data; }
function minWord($content) { global $post; $content = $post->post_content; if (str_word_count($content) < 100 ) //set this to the minimum number of words wp_die( __('Error: your post is below the minimum word count. It needs to be longer than 100 words.') ); } add_action('publish_post', 'minWord');
Apparently, the filter for the title is working but the two filters for the content are absolutely not working.
I am using Woody ad snippets to add the PHP codes because I am not familiar with PHP.
I think that the problem is that the posts are maybe modified by another plugin and are saved empty because there is no reason for having this issue after adding the PHP codes.
Do you have any idea or suggestion about this problem?
Thank you in advance.
- The topic ‘Prevent empty posts from publish.’ is closed to new replies.