Skip to content

Instantly share code, notes, and snippets.

@norcross
Created December 18, 2012 23:33

Revisions

  1. norcross revised this gist Dec 19, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions cron-delete-revisions.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    // add filter to allow for new weekly schedule
    add_filter( 'cron_schedules', 'rkv_weekly_cron' );

  2. norcross revised this gist Dec 19, 2012. 1 changed file with 41 additions and 42 deletions.
    83 changes: 41 additions & 42 deletions cron-delete-revisions.php
    Original file line number Diff line number Diff line change
    @@ -1,42 +1,41 @@
    // add filter to allow for new weekly schedule
    add_filter( 'cron_schedules', 'rkv_weekly_cron' );

    function rkv_weekly_cron( $schedules ) {
    // Adds once weekly to the existing schedules.
    $schedules['weekly'] = array(
    'interval' => 604800,
    'display' => __( 'Once Weekly' )
    );
    return $schedules;
    }

    add_action('rkv_revision_cron', 'rkv_revision_delete');

    // set cron schedule
    function rkv_revision_schedule() {
    if ( !wp_next_scheduled( 'rkv_revision_cron' ) ) {
    wp_schedule_event( time(), 'weekly', 'rkv_revision_cron');
    }
    }
    add_action('wp', 'rkv_revision_schedule');

    // run deletion on revisions
    function rkv_revision_delete() {

    // query revisions and get array of IDs
    $args = array(
    'fields' => 'ids',
    'post_type' => 'revision',
    'numberposts' => -1
    );


    $revisions = get_posts($args);

    // loop through and delete each
    foreach ($revisions as $revision):

    wp_delete_post( $revision );

    endforeach;
    }
    // add filter to allow for new weekly schedule
    add_filter( 'cron_schedules', 'rkv_weekly_cron' );

    function rkv_weekly_cron( $schedules ) {
    // Adds once weekly to the existing schedules.
    $schedules['weekly'] = array(
    'interval' => 604800,
    'display' => __( 'Once Weekly' )
    );
    return $schedules;
    }

    add_action('rkv_revision_cron', 'rkv_revision_delete');

    // set cron schedule
    function rkv_revision_schedule() {
    if ( !wp_next_scheduled( 'rkv_revision_cron' ) ) {
    wp_schedule_event( time(), 'weekly', 'rkv_revision_cron');
    }
    }
    add_action('wp', 'rkv_revision_schedule');

    // run deletion on revisions
    function rkv_revision_delete() {

    // query revisions and get array of IDs
    $args = array(
    'fields' => 'ids',
    'post_type' => 'revision',
    'numberposts' => -1
    );

    $revisions = get_posts($args);

    // loop through and delete each
    foreach ($revisions as $revision):

    wp_delete_post( $revision );

    endforeach;
    }
  3. norcross revised this gist Dec 19, 2012. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion cron-delete-revisions.php
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,21 @@
    // add filter to allow for new weekly schedule
    add_filter( 'cron_schedules', 'rkv_weekly_cron' );

    function rkv_weekly_cron( $schedules ) {
    // Adds once weekly to the existing schedules.
    $schedules['weekly'] = array(
    'interval' => 604800,
    'display' => __( 'Once Weekly' )
    );
    return $schedules;
    }

    add_action('rkv_revision_cron', 'rkv_revision_delete');

    // set cron schedule
    function rkv_revision_schedule() {
    if ( !wp_next_scheduled( 'rkv_revision_cron' ) ) {
    wp_schedule_event( time(), 'daily', 'rkv_revision_cron');
    wp_schedule_event( time(), 'weekly', 'rkv_revision_cron');
    }
    }
    add_action('wp', 'rkv_revision_schedule');
    @@ -18,6 +30,7 @@ function rkv_revision_delete() {
    'numberposts' => -1
    );


    $revisions = get_posts($args);

    // loop through and delete each
  4. norcross created this gist Dec 18, 2012.
    29 changes: 29 additions & 0 deletions cron-delete-revisions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    add_action('rkv_revision_cron', 'rkv_revision_delete');

    // set cron schedule
    function rkv_revision_schedule() {
    if ( !wp_next_scheduled( 'rkv_revision_cron' ) ) {
    wp_schedule_event( time(), 'daily', 'rkv_revision_cron');
    }
    }
    add_action('wp', 'rkv_revision_schedule');

    // run deletion on revisions
    function rkv_revision_delete() {

    // query revisions and get array of IDs
    $args = array(
    'fields' => 'ids',
    'post_type' => 'revision',
    'numberposts' => -1
    );

    $revisions = get_posts($args);

    // loop through and delete each
    foreach ($revisions as $revision):

    wp_delete_post( $revision );

    endforeach;
    }