$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 ( (bool) $revision_status == $revision_status ) $revision_status = (bool)$revision_status; } } } @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; if ( 'advanced' != $context ) return; if ( isset($wp_meta_boxes[ $page ][ $context ][ 'core' ][ 'revisionsdiv' ]) ) $wp_meta_boxes[ $page ][ $context ][ 'core' ][ 'revisionsdiv' ]['callback'] = 'rc_revisions_meta_box'; else add_meta_box('revisionsdiv', __('Post Revisions'), 'rc_revisions_meta_box', $page, $context, '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 $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 "
' . __('Settings saved.', 'revision-control') . '