Fact-Check Reminder When Editing Old Posts
Shows a notice in the block editor when someone opens a post published more than two years ago, reminding them to check facts, links and screenshots while they are there.
Opens WPIDE on
Code
// Age in years that triggers the reminder.
$wpide_old_post_years = 2;
add_action( 'enqueue_block_editor_assets', function () use ( $wpide_old_post_years ) {
$post = get_post();
if ( ! $post || 'publish' !== $post->post_status || get_post_time( 'U', true, $post ) > strtotime( "-{$wpide_old_post_years} years" ) ) {
return;
}
$message = sprintf( 'This post was published %s ago. Please check that facts, prices, links and screenshots are still correct.', human_time_diff( get_post_time( 'U', true, $post ) ) );
wp_add_inline_script(
'wp-notices',
sprintf( 'wp.domReady(function(){wp.data.dispatch("core/notices").createWarningNotice(%s,{id:"wpide-old-post",isDismissible:true});});', wp_json_encode( $message ) ),
'after'
);
wp_enqueue_script( 'wp-notices' );
wp_enqueue_script( 'wp-dom-ready' );
} );
Notes
Change $wpide_old_post_years; the notice can be dismissed for the session.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.