Skip to content

Conversation

@ryanshoover
Copy link
Contributor

Right now, only those who can edit_published_posts can make a revision of an existing post. There seems to be a need to allow more granular control. For instance, I may want users to be able to make edits to an existing page but not actually publish those changes until they've been reviewed by someone higher up the food chain.

This PR adds a filter to the plugin to allow the end site to override the ability to revisionize a post.

Example usage:

/**
 * Allow anyone who can edit a page to revisionize a published page.
 * They won't be able to publish the page but they will be able to submit their revision for review.
 *
 * @param  boolean $is_enabled Default permissions value
 * @param  object  $post       WP_Post object of the post in question
 * @return boolean             Can the user revisionize the post?
 */ 
function namespace_filter_revisionize_is_create_enabled( $is_enabled, $post ) {
    return ! \Revisionize\get_revision_of( $post ) && 'page' == get_post_type( $post ) && current_user_can( 'edit_pages' ) ? true : $is_enabled;
}

add_filter( 'revisionize_is_create_enabled', 'namespace_filter_revisionize_is_create_enabled', 10, 2 );

The PR also does a bit of cleanup.

  • Deletes all trailing whitespace
  • Capitalizes the P in WordPress in the readme

Copy link
Owner

@jamiechong jamiechong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanshoover Have you tested this in your own dev setup? is_create_enabled is used twice: to add the "Revisionize" link, and again as a check before actually creating a revision. However in Revisionize\create, I also check if user_can_revisionize().

So I think we need to add a filter to this method as well. And for completeness, a filter for user_can_publish_revision might be handy.

Let me know if your testing deems your existing changes sufficient (I don't see how it could work, however). Otherwise, please make those further additions and we can get this stuff merged!

Thanks for your contributions - much appreciated!

@ryanshoover
Copy link
Contributor Author

Thanks for the feedback!

In my testing, the one filter was sufficient, but the user role has the edit_posts capability. user_can_revisionize() only checks for that core cap. But filters on both user_can_revisionize() and user_can_publish_revision() are a good idea to give devs complete control over who can use the plugin.

@jamiechong jamiechong merged commit 24208db into jamiechong:master Aug 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants