public
Last active

Revisions generator

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
<?php
// How many revisions should be created?
$num_of_revisions = 40;
 
// Demo content
$content = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
 
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.";
 
// Create a post
$post = array(
'post_content' => $content,
'post_title' => sprintf( '%d Revisions: %d', $num_of_revisions, time() )
);
$pid = wp_insert_post( $post );
 
// Create revisions
for( $i = 0; $i <= $num_of_revisions - 2; $i++ ) {
$post = get_post( $pid );
$old_content = $post->post_content;
 
$old_content = str_split( $old_content, rand( 1, ceil( mb_strlen( $old_content ) / 2 ) ) );
 
$new_content = $old_content[ 0 ] . "\n\n" . $content . "\n\n" . $old_content[ 1 ];
 
$args = array(
'ID' => $pid,
'post_content' => $new_content
);
wp_update_post( $args );
 
// We need to slow down it a bit
sleep( 1 );
};
 
echo 'Done - ' . time();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.