Skip to content

Commit

Permalink
Refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
gyrus committed Aug 7, 2015
1 parent ab4f29d commit 92caa14
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions lock-pages.php
Expand Up @@ -470,16 +470,25 @@ function user_can_edit( $post_id = 0 ) {
// Basic check for "edit locked page" capability
$user_can = current_user_can( $this->options[$this->prefix.'capability'] );

// Override it if page isn't locked, a specific page is being edited, and scope isn't all pages
if ( $this->options[$this->prefix.'scope'] != "all" && $post_id && ! $this->is_page_locked( $post_id ) ) {
/*
* Override (with user CAN edit) if:
* - We've got a post ID to work with
* - It's not a page, or scope for pages isn't for all, AND
* - The page isn't locked
*/
if (
$post_id &&
( get_post_type( $post_id ) != 'page' || $this->options[$this->prefix.'scope'] != "all" ) &&
! $this->is_page_locked( $post_id )
) {
$user_can = true;
}

return $user_can;
}

/**
* Does edit check based on submitted post ID instead of passed id
* Does edit check based on submitted post ID instead of passed ID
*
* @since 0.3
* @uses $_POST
Expand All @@ -495,13 +504,13 @@ function user_can_edit_submitted_post() {
* @since 0.1
*/
function is_page_locked( $post_id ) {
$page_is_locked = false;
if ( $post_id ) {
$locked_pages = $this->options[$this->prefix.'locked_pages'];
$locked_pages = explode( ',', $locked_pages );
return in_array( $post_id, $locked_pages );
} else {
return false;
$locked_pages = $this->options[$this->prefix.'locked_pages'];
$locked_pages = explode( ',', $locked_pages );
$page_is_locked = in_array( $post_id, $locked_pages );
}
return $page_is_locked;
}

/**
Expand Down Expand Up @@ -545,10 +554,11 @@ function load_js_css() {
* @global $post $pagenow
*/
function admin_body_class( $class ) {
global $post, $pagenow;
global $post;
$screen = get_current_screen();
if (
$pagenow == 'post.php' &&
$_GET["action"] == "edit" &&
$screen->base == 'post' &&
$screen->parent_base == 'edit' &&
! $this->user_can_edit( $post->ID )
) {
$class .= ' page-locked';
Expand Down

0 comments on commit 92caa14

Please sign in to comment.