Frontier Post – Who can edit a post
Below are the rules for editing a post for a user. This also controls when the edit icon (or link) is displayed on the Frontier Post list.
The rules are based on a combination of Frontier Post settings & Capabilities:
The below rules apply to users own posts
- User has Capability: frontier_post_can_edit
- User is Author of the post (post_author == current user)
- That post is not to old (Setting: Max age in days to allow edit of post)
- If the post has comments, that it is allowed to edit posts that has comments (Setting: Allow edit of posts with comments)
- If status is Published, that users are allowed to edit published posts (Setting: Allow users to change status from Published)
- That it is an allowed post type (Setting: Allowed Post Types)
*Editors can edit others users post, but all of the above conditions has to be true, except 2 (User is author). Editors are users with WordPress standard capability “edit_others_posts”.
**Administrators can always edit edit others users post, regardless of above conditions has to be true.
Private Posts can only be edited by the Author, not by Administrators or Editors.
Code:
function frontier_can_edit($tmp_post) { global $fps_access_check_msg; $cur_user = wp_get_current_user(); $tmp_can_do = true; // Check if the user is allowed to edit posts if ( !current_user_can( 'frontier_post_can_edit' ) ) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to edit posts", "frontier-post")."<br>"; } // Users can not edit other users posts unless they have capability "edit_others_posts" (Administrators & Editors) if( ($cur_user->ID != $tmp_post->post_author) && (!current_user_can( 'edit_others_posts' )) ) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to edit post from another user", "frontier-post")."<br>"; } // Check that the age of the post is below the Frontier Post setting if ( ($tmp_post->post_status == "publish") && (frontier_post_age($tmp_post->post_date) > fp_get_option_int('fps_edit_max_age')) ) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to edit post older than: ", "frontier-post").fp_get_option_int('fps_edit_max_age')." ".__("days", "frontier-post")."<br>"; } // Check that user is allowed to edit posts that already has comments if ( (intval($tmp_post->comment_count) > 0) && !fp_get_option_bool("fps_edit_w_comments") ) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to edit post that already has comments", "frontier-post")."<br>"; } // Check if user is allowed to edit a post that is already published if ( !fp_get_option("fps_change_status") && ($tmp_post->post_status == "publish") ) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to edit post that is published", "frontier-post")."<br>"; } // check if it is an allowed posttype if ( !fp_check_post_type($tmp_post->post_type) ) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to edit", "frontier-post").": ".fp_get_posttype_label($tmp_post->post_type)."<br>"; } // Always allow the boss if ( current_user_can( 'administrator' ) ) { $tmp_can_do = true; $fps_access_check_msg = ""; } // Last check, PRIVATE posts can only be edited by the author or Users with the capability edit_private_posts if ( $tmp_post->post_status == "private" && ($cur_user->ID != $tmp_post->post_author || !current_user_can( 'frontier_post_can_private' )) ) { $tmp_can_do = false; $fps_access_check_msg .= __("You are not allowed to edit PRIVATE post from another user", "frontier-post")."<br>"; } return $tmp_can_do; }
Comments
Frontier Post – Who can edit a post — No Comments
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>