admin管理员组

文章数量:1290926

I'm using IFTTT to post images from a subreddit to my WordPress site, and then WordPress shares those images with their post titles on multiple social sites.

The problem is, IFTTT publishes blank posts on WordPress sometimes. They only have a title but no images. Now the plugin I use for sharing the posts published by IFTTT can't recognize empty posts, and it shares only their title on other social media sites since there is no image.

So my only solution is to auto delete empty WordPress posts. Is there any script or plugin to do it?

Please let me know. Thanks

I'm using IFTTT to post images from a subreddit to my WordPress site, and then WordPress shares those images with their post titles on multiple social sites.

The problem is, IFTTT publishes blank posts on WordPress sometimes. They only have a title but no images. Now the plugin I use for sharing the posts published by IFTTT can't recognize empty posts, and it shares only their title on other social media sites since there is no image.

So my only solution is to auto delete empty WordPress posts. Is there any script or plugin to do it?

Please let me know. Thanks

Share Improve this question asked Jun 10, 2021 at 10:02 heyitsriteshheyitsritesh 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You want to write a wp_insert_post_empty_content filter.

WordPress will already try and reject empty posts:

$maybe_empty = 'attachment' !== $post_type
    && ! $post_content && ! $post_title && ! $post_excerpt
    && post_type_supports( $post_type, 'editor' )
    && post_type_supports( $post_type, 'title' )
    && post_type_supports( $post_type, 'excerpt' );

but I guess that logic isn't catching your posts here. So you'll need to work out what your empty posts look like specifically and catch them too:

function wpse390344_empty_posts_filter( $empty, $postarr ) {
    if ( ! $empty ) {
        // TODO: look at $postarr - see wp_insert_post() documentation for format
        //       and decide if this is an empty post you want to reject.
        //       If it is, return true.
    }

    return $empty;
}
add_filter( 'wp_insert_post_empty_content', 'wpse390344_empty_posts_filter', 10, 2 );

本文标签: pluginsAuto delete empty posts