-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevision-shortcode.php
49 lines (44 loc) · 1.3 KB
/
revision-shortcode.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
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
Plugin Name: WP Document Revisions - Revision Shortcode
Plugin URI: http://
Description: Code sample to demonstrate short code to list revisions
Version: 1.0
Author: Benjamin J. Balter
Author URI: http://ben.balter.com
License: GPL2
*/
/**
* Callback to display revisions
* @param $atts array attributes passed via short code
* @returns string a UL with the revisions
*/
function wpdr_shotcode( $atts ) {
//extract args
extract( shortcode_atts( array(
'id' => null,
), $atts ) );
//get WPDR object
$wpdr = Document_Revisions::$instance;
$revisions = $wpdr->get_revisions( $id );
//buffer output to return rather than echo directly
ob_start();
?>
<ul class="revisions">
<?php
//loop through each revision
foreach ( $revisions as $revision ) { ?>
<li>
<a href="<?php echo get_permalink( $revision->ID ); ?>" title="<?php echo $revision->post_date; ?>" class="timestamp" id="<?php echo strtotime( $revision->post_date ); ?>">
<?php echo human_time_diff( strtotime( $revision->post_date ), current_time('timestamp') ); ?>
</a> by <?php echo get_the_author_meta( 'display_name', $revision->post_author ); ?>
</li>
<?php } ?>
</ul>
<?php
//grab buffer contents and clear
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode( 'reisions', 'wpdr_shortcode' );