$defaults, 'page' => $defaults);
update_option('revision-control', $defaults);
}
$current_post = rc_get_page_id();
//Post or Page:
if ( ! $type = rc_get_page_type($current_post) )
return;
$revision_status = isset($defaults[ $type ]) ? $defaults[ $type ] : true;
define('RC_REVISION_DEFAULT', $revision_status);
if ( $current_post ) {
//Handle per-post/page settings.
$post_revision_status = get_post_meta($current_post, '_revision-control', true);
if ('' !== trim($post_revision_status) ) {
$revision_status = $post_revision_status;
//Eugh.. maybe_serialize() bug #7383 means integers/booleans are stored as string!
if ( is_string($revision_status) ) {
$revision_status = (int)$revision_status;
if ( 1 == $revision_status )
$revision_status = true;
}
}
}
@define('WP_POST_REVISIONS', $revision_status);
}
/**
* Determines if this is a Page or a Post, Or other.
*/
function rc_get_page_type( $id = 0 ) {
global $pagenow;
if ( isset($_POST['post_type']) )
return $_POST['post_type'];
else if ( 'page.php' == $pagenow || 'page-new.php' == $pagenow)
return 'page';
else if ( 'post.php' == $pagenow || 'post-new.php' == $pagenow)
return 'post';
else if ( $id && $post = get_post($id) )
return $post->post_type;
return false;
}
/**
* Determines the post/page's ID based on the 'post' and 'post_ID' POST/GET fields.
*/
function rc_get_page_id() {
foreach ( array( 'post_ID', 'post' ) as $field )
if ( isset( $_REQUEST[ $field ] ) )
return absint($_REQUEST[ $field ]);
if ( isset($_REQUEST['revision']) )
if ( $post = get_post( $id = absint($_REQUEST['revision']) ) )
return absint($post->post_parent);
return false;
}
/**
* Custom Revisions box
* Should use the API, But remove_meta_box followed by add_meta_box doesnt appear to add the new box
*/
function rc_meta_box_manip($page, $context) {
global $wp_meta_boxes;
$type = version_compare($GLOBALS['wp_version'], '2.6.999', '>') ? 'normal' : 'advanced';
if ( 'dashboard' == $page )
return;
if ( $type != $context )
return;
if ( isset($wp_meta_boxes[ $page ][ $type ][ 'core' ][ 'revisionsdiv' ]) )
$wp_meta_boxes[ $page ][ $type ][ 'core' ][ 'revisionsdiv' ]['callback'] = 'rc_revisions_meta_box';
else
add_meta_box('revisionsdiv', __('Post Revisions'), 'rc_revisions_meta_box', $page, $type, 'core');
}
/**
* The new Revision Meta box
*/
function rc_revisions_meta_box( $post ) {
rc_list_post_revisions();
?>
:
/>
/>
1 ) echo ' checked="checked"' ?>/>
'ASC' ) );
//Number to delete, based on option.
$delete = count($revisions) - $number_to_delete;
if ( $delete < 1 )
return;
$revisions = array_slice( $revisions, 0, $delete );
foreach ( (array)$revisions as $revision )
if ( false === strpos( $revision->post_name, 'autosave' ) )
wp_delete_post_revision( $revision->ID );
}
}
/**
* Copy of wp_list_post_revisions() w/ non-list support stripped out.
*
*/
function rc_list_post_revisions( $post_id = 0 ) {
if ( !$post = get_post( $post_id ) )
return;
if ( !$revisions = wp_get_post_revisions( $post->ID ) )
return;
$titlef = _c( '%1$s by %2$s|post revision 1:datetime, 2:name' );
echo "
\n";
foreach ( $revisions as $revision ) {
if ( !current_user_can( 'read_post', $revision->ID ) )
continue;
$date = wp_post_revision_title( $revision );
$name = get_author_name( $revision->post_author );
$title = sprintf( $titlef, $date, $name );
if ( current_user_can( 'edit_post', $revision->ID ) && ! wp_is_post_autosave( $revision ) ) {
$url = wp_nonce_url('admin-post.php?action=delete-revision&revision=' . $revision->ID, 'delete_revision-' . $revision->ID);
$title .= sprintf(' %s', js_escape(__('Are you sure you wish to delete this Revision?', 'revision-control')), __('(delete)', 'revision-control'));
}
echo "\t- $title
\n";
}
echo "
";
}
/**
* Deletes a Revision
*/
add_action('admin_post_delete-revision', 'rc_delete_revision');
function rc_delete_revision() {
$revision = absint($_REQUEST['revision']);
if ( $revision ) {
check_admin_referer('delete_revision-' . $revision);
if ( current_user_can('delete_post', $revision) )
wp_delete_post_revision( $revision );
}
wp_safe_redirect(wp_get_referer());
}
/**
* Add the Plugin action link.
*/
add_filter('plugin_action_links', 'rc_plugins_filter', 10, 2);
function rc_plugins_filter($links, $plugin) {
static $this_plugin;
if( ! $this_plugin )
$this_plugin = plugin_basename(__FILE__);
if( $plugin == $this_plugin ) {
$links = array_merge( array('' . __('Revisions', 'revision-control') . ''), $links);
remove_filter('plugin_action_links', 'rc_plugins_filter'); //Nice citizens, We dont *really* need to check anymore.
}
return $links;
}
/**
* The admin page, Handles saving the setting too.
* checked() / selected() cannot save us, need a === instead of ==
*/
function rc_admin() {
$defaults = get_option('revision-control');
if ( 'POST' == strtoupper($_SERVER['REQUEST_METHOD']) ) {
check_admin_referer('update-options');
foreach ( array('post', 'page') as $field ) {
if ( ! isset($_POST['revision-control-' . $field]) )
continue;
switch ( $_POST['revision-control-' . $field] ) {
case 'true':
$defaults[ $field ] = true;
break;
case 'false':
$defaults[ $field ] = 0;
break;
case 'number':
$defaults[ $field ] = (int)$_POST['revision-control-' . $field . '-number'];
break;
}
}
if ( $defaults !== get_option('revision-control') ) {
update_option('revision-control', $defaults);
echo '' . __('Settings saved.', 'revision-control') . '
';
}
}
?>
Error: You have defined WP_POST_REVISIONS in your wp-config.php file, In order to use this plugin you will need to remove it.', 'revision-control') ?>
basename = plugin_basename(__FILE__);
$this->folder = dirname($this->basename);
//Set the version of the DD32 library this plugin requires.
$GLOBALS['dd32_version'] = isset($GLOBALS['dd32_version']) ? max($GLOBALS['dd32_version'], $this->dd32_requires) : $this->dd32_requires;
add_action('init', array(&$this, 'load_dd32'), 20);
//Register general hooks.
add_action('admin_init', array(&$this, 'admin_init'));
}
function load_dd32() {
//Load common library
include 'inc/class.dd32.php';
}
function admin_init() {
DD32::add_changelog($this->basename, 'http://svn.wp-plugins.org/revision-control/trunk/readme.txt');
}
}
add_action('init', create_function('', '$GLOBALS["revision-control"] = new revision_control();'), 5);
?>