# Block Publishing Posts That Contain Placeholder Text

> Refuses to publish content that still contains placeholder words such as "Lorem ipsum", "TODO", "TK" or "[insert", so unfinished drafts never go live by accident.

- Type: PHP
- Runs: Run everywhere
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: editorial, publishing, quality
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/content-block-placeholder-text/

## Code

```php
// Phrases that mean a post is not finished.
$wpide_placeholder_phrases = array( 'lorem ipsum', 'todo', 'tk tk', '[insert', 'xxx', 'placeholder' );

$wpide_find_placeholder = function ( $text ) use ( $wpide_placeholder_phrases ) {
    $text = wp_strip_all_tags( (string) $text );
    foreach ( $wpide_placeholder_phrases as $phrase ) {
        if ( preg_match( '/(^|\W)' . preg_quote( $phrase, '/' ) . '($|\W)/i', $text ) ) {
            return $phrase;
        }
    }
    return '';
};

add_filter( 'rest_pre_insert_post', function ( $prepared, $request ) use ( $wpide_find_placeholder ) {
    $status = $request->get_param( 'status' ) ? $request->get_param( 'status' ) : get_post_status( (int) ( $prepared->ID ?? 0 ) );
    if ( ! in_array( $status, array( 'publish', 'future' ), true ) ) {
        return $prepared;
    }

    $content = $prepared->post_content ?? get_post_field( 'post_content', (int) ( $prepared->ID ?? 0 ), 'raw' );
    $found   = $wpide_find_placeholder( ( $prepared->post_title ?? '' ) . ' ' . $content );

    return $found
        ? new WP_Error( 'wpide_placeholder_text', sprintf( 'This post still contains placeholder text ("%s"). Replace it before publishing.', $found ), array( 'status' => 400 ) )
        : $prepared;
}, 10, 2 );

add_filter( 'wp_insert_post_data', function ( $data ) use ( $wpide_find_placeholder ) {
    if ( wp_is_serving_rest_request() || ! in_array( $data['post_status'], array( 'publish', 'future' ), true ) || ! in_array( $data['post_type'], array( 'post', 'page' ), true ) ) {
        return $data;
    }
    if ( $wpide_find_placeholder( wp_unslash( $data['post_title'] . ' ' . $data['post_content'] ) ) ) {
        $data['post_status'] = 'draft';
    }
    return $data;
} );
```

## Notes

Add or remove phrases in $wpide_placeholder_phrases; matching ignores letter case.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Block Publishing Posts That Contain Placeholder Text" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
