Skip to content

Commit

Permalink
Allow Docs history to be enabled even when WP_POST_REVISIONS is set t…
Browse files Browse the repository at this point in the history
…o false

Define 'BP_DOCS_REVISIONS' constant to override WP_POST_REVISIONS settings for
the bp_doc post type.

Fixes #281
  • Loading branch information
boonebgorges committed Jul 1, 2014
1 parent 960b1c9 commit 9c586a3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
4 changes: 3 additions & 1 deletion bp-docs.php
Expand Up @@ -342,7 +342,9 @@ function load_doc_extras() {
$this->hierarchy = new BP_Docs_Hierarchy;

// Don't load the History component if post revisions are disabled
if ( defined( 'WP_POST_REVISIONS' ) && WP_POST_REVISIONS ) {
$wp_post_revisions = defined( 'WP_POST_REVISIONS' ) && WP_POST_REVISIONS;
$bp_docs_revisions = defined( 'BP_DOCS_REVISIONS' ) && BP_DOCS_REVISIONS;
if ( $wp_post_revisions || $bp_docs_revisions ) {
require_once( BP_DOCS_INCLUDES_PATH . 'addon-history.php' );
$this->history = new BP_Docs_History;
}
Expand Down
6 changes: 3 additions & 3 deletions includes/addon-history.php
Expand Up @@ -104,7 +104,7 @@ function setup_action() {
break;

// Revisions disabled and we're not looking at an autosave
if ( ( ! WP_POST_REVISIONS || !post_type_supports( $post->post_type, 'revisions') ) && !wp_is_post_autosave( $this->revision ) ) {
if ( ! wp_revisions_enabled( $post ) && !wp_is_post_autosave( $this->revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ function setup_action() {
else
break; // Don't diff two unrelated revisions

if ( ! WP_POST_REVISIONS || !post_type_supports( $post->post_type, 'revisions' ) ) { // Revisions disabled
if ( ! wp_revisions_enabled( $post ) ) { // Revisions disabled

if (
// we're not looking at an autosave
Expand Down Expand Up @@ -184,7 +184,7 @@ function setup_action() {
break;

// Revisions disabled and we're not looking at an autosave
if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $this->revision ) ) {
if ( ! wp_revisions_enabled( $post ) && !wp_is_post_autosave( $this->revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
Expand Down
16 changes: 11 additions & 5 deletions includes/caps.php
Expand Up @@ -58,17 +58,23 @@ function bp_docs_map_meta_caps( $caps, $cap, $user_id, $args ) {
// Reset all caps. We bake from scratch
$caps = array();

// Admins can do everything
if ( user_can( $user_id, 'bp_moderate' ) ) {
return array( 'exist' );
}

$doc = bp_docs_get_doc_for_caps( $args );

if ( empty( $doc ) ) {
break;
}

// Special case: view_history requires post revisions
// @todo Move this to addon-history
if ( 'bp_docs_view_history' === $cap && ! wp_revisions_enabled( $doc ) ) {
return array( 'do_not_allow' );
}

// Admins can do everything
if ( user_can( $user_id, 'bp_moderate' ) ) {
return array( 'exist' );
}

$doc_settings = bp_docs_get_doc_settings( $doc->ID );

// Caps are stored without the 'bp_docs_' prefix,
Expand Down
24 changes: 24 additions & 0 deletions includes/functions.php
Expand Up @@ -770,3 +770,27 @@ function bp_docs_get_doc_ids_accessible_to_current_user() {
$items_sql = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s AND ID NOT IN $exclude_sql", bp_docs_get_post_type_name() );
return $wpdb->get_col( $items_sql );
}

/**
* Determine how many revisions to retain for Docs.
*
* @since 1.8
*
* @return int
*/
function bp_docs_revisions_to_keep( $num, $post ) {
if ( bp_docs_get_post_type_name() !== $post->post_type ) {
return $num;
}

if ( defined( 'BP_DOCS_REVISIONS' ) ) {
if ( true === BP_DOCS_REVISIONS ) {
$num = -1;
} else {
$num = intval( BP_DOCS_REVISIONS );
}
}

return intval( $num );
}
add_filter( 'wp_revisions_to_keep', 'bp_docs_revisions_to_keep', 10, 2 );

0 comments on commit 9c586a3

Please sign in to comment.