diff --git a/revision-history/revision_history.php b/revision-history/revision_history.php index 7fe3151..40dade7 100644 --- a/revision-history/revision_history.php +++ b/revision-history/revision_history.php @@ -1,9 +1,9 @@ post_title .= ""; + } + $post->post_title .= " (Revision: " . $rev_date . ")"; + if ($title_class) { + $post->post_title .= ""; + } + } +} + +function rh_get_the_revision_post() { if (valid_revision_id()) { $revision = $_GET['revision']; $post = get_post($revision); - if ($post != null) { - # reset posts so the revision is displayed instead of the original - global $posts; - $posts = array($post); + } else { + $post = get_post(get_the_ID()); + } + return $post; +} + +function rh_revision_str($post = null) { + if ($post == null) { + if (valid_revision_id()) { + $post = rh_get_the_revision_post($revision); } } + if ($post != null) { + $modified = strtotime($post->post_modified_gmt . ' +0000'); + return sprintf('%s at %s', date(get_option('date_format'), $modified), date(get_option('time_format'), $modified)); + } else { + return "Latest"; + } } -add_filter('the_content', 'display_post_revisions'); +function rh_the_revision($before = '', $after = '') { + echo $before . rh_revision_str() . $after; +} + + +if (get_option( 'rh_use_shortcode' ) == '0'){ + add_filter('the_content', 'display_post_revisions'); +}; + + +add_shortcode("revisions", "display_post_revisions"); function display_post_revisions($content) { $post = get_post(get_the_ID()); - + // if we are visiting a revision we need to adjust the post // so we can still get the revision history. if ( $post && $post->post_type == "revision" ) { $post = get_post($post->post_parent); } - $page_name = 'show_page_revisions'; - $post_name = 'show_post_revisions'; + $page_name = 'rh_show_page_revisions'; + $post_name = 'rh_show_post_revisions'; + $shortcode_name = 'rh_use_shortcode'; $page_val = get_option( $page_name ); $post_val = get_option( $post_name ); - - if ( $post && (( $post->post_type == "post" && $post_val) || + $shortcode_val = get_option( $shortcode_name ); + + + + if ($post && (( $post->post_type == "post" && $post_val) || ($post->post_type == "page" && $page_val)) ) { $revisions = list_post_revisions($post); if ( $revisions ) { @@ -73,19 +129,38 @@ function display_post_revisions($content) { } + + + function list_post_revisions( $post ) { if ( $revisions = wp_get_post_revisions( $post->ID ) ) { - $items = ''; + $autosave_name = 'rh_show_autosaves'; + $show_autosaves = get_option( $autosave_name ); $revision_id = (valid_revision_id()) ? $revision_id = $_GET['revision'] : $post->ID; + $current_revision_date = rh_revision_str($post); + $current_revision_author = get_author_name($post->post_author); + $current_revision_url = get_permalink($post); + if ($revision_id == $post->ID) { + $items .= "
  • $current_revision_date by $current_revision_author (displayed above)
  • "; + } else { + $items .= "
  • $current_revision_date by $current_revision_author
  • "; + } foreach ( $revisions as $revision ) { - $date = wp_post_revision_title( $revision, 0 ); + $is_autosave = wp_is_post_autosave($revision); + if ( !$show_autosaves && $is_autosave ) { + continue; + } + $rev_date = rh_revision_str($revision); $name = get_author_name( $revision->post_author ); $query_string = get_query_string($revision); $items .= "
  • "; if ($revision_id == $revision->ID) { - $items .= "$date by $name (displayed above)"; + $items .= "$rev_date by $name (displayed above)"; } else { - $items .= "$date by $name"; + $items .= "$rev_date by $name"; + } + if ($is_autosave) { + $items .= " [autosave]"; } $items .= "
  • "; } @@ -107,8 +182,12 @@ function get_query_string($revision) { return $query_string; } -add_option('show_page_revisions', '0'); -add_option('show_post_revisions', '0'); +add_option('rh_show_page_revisions', '0'); +add_option('rh_show_post_revisions', '0'); +add_option('rh_show_autosaves', '0'); +add_option('rh_adjust_title', '0'); +add_option('rh_title_class', 'rh-title'); +add_option('rh_use_shortcode', '0'); // Hook for adding admin menus add_action('admin_menu', 'add_revision_history'); @@ -121,22 +200,33 @@ function add_revision_history() { function add_revision_history_options_page() { // variables for the field and option names - $page_name = 'show_page_revisions'; - $post_name = 'show_post_revisions'; - $page_field_name = 'show_page_revisions'; - $post_field_name = 'show_post_revisions'; + $page_name = 'rh_show_page_revisions'; + $post_name = 'rh_show_post_revisions'; + $shortcode_name = 'rh_use_shortcode'; + $autosaves_name = 'rh_show_autosaves'; + $adjust_title_name = 'rh_adjust_title'; + $title_class_name = 'rh_title_class'; $hidden_field_name = 'submit_hidden'; // get the current values $page_val = get_option( $page_name ); $post_val = get_option( $post_name ); + $shortcode_val = get_option( $shortcode_name ); + $autosaves_val = get_option( $autosaves_name ); + $adjust_title_val = get_option( $adjust_title_name ); + $title_class_val = get_option( $title_class_name ); // See if the user has posted us some information // If they did, this hidden field will be set to 'Y' if( $_POST[ $hidden_field_name ] == 'Y' ) { // get the values from the POST - $new_page_val = ($_POST[ $page_field_name ] == "on") ? "1" : "0"; - $new_post_val = ($_POST[ $post_field_name ] == "on") ? "1" : "0"; + $new_page_val = ($_POST[ $page_name ] == "on") ? "1" : "0"; + $new_post_val = ($_POST[ $post_name ] == "on") ? "1" : "0"; + $new_shortcode_val = ($_POST[ $shortcode_name ] == "on") ? "1" : "0"; + $new_autosaves_val = ($_POST[ $autosaves_name ] == "on") ? "1" : "0"; + $new_adjust_title_val = ($_POST[ $adjust_title_name ] == "on") ? "1" : "0"; + $new_title_class_val = ($_POST[ $title_class_name ] == "") ? "" : $_POST[ $title_class_name ]; + // save the new values if ( $new_page_val != $page_val ) { update_option( $page_name, $new_page_val ); @@ -146,6 +236,22 @@ function add_revision_history_options_page() { update_option( $post_name, $new_post_val ); $post_val = $new_post_val; } + if ( $new_shortcode_val != $shortcode_val ) { + update_option( $shortcode_name, $new_shortcode_val ); + $shortcode_val = $new_shortcode_val; + } + if ( $new_autosaves_val != $autosaves_val ) { + update_option( $autosaves_name, $new_autosaves_val ); + $autosaves_val = $new_autosaves_val; + } + if ( $new_adjust_title_val != $adjust_title_val ) { + update_option( $adjust_title_name, $new_adjust_title_val ); + $adjust_title_val = $new_adjust_title_val; + } + if ( $new_title_class_val != $title_class_val ) { + update_option( $title_class_name, $new_title_class_val ); + $title_class_val = $new_title_class_val; + } // Feedback that we've updated the options ?>

    @@ -153,20 +259,74 @@ function add_revision_history_options_page() { } // END CHECKING POST ?>
    - " . __( 'Revision History Options', 'mt_trans_domain' ) . ""; ?> + " . __( 'Revision History Settings', 'mt_trans_domain' ) . ""; ?>
    -

    - /> - -

    -

    - /> - -

    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + Page revisions + + /> + +
    + Post revisions + + /> + +
    + Autosave revisions + + /> + +
    + Modify post title + + /> + +  If you need more control use rh_the_revision in your theme. +
    + + + + A child span is added to the post header, with the specified class. +
    + Use Shortcode + + /> + +