/**
  * Saves the post meta.
  *
  * @since  1.0.0
  * @access public
  * @param  int     $post_id
  * @param  object  $post
  * @return void
  */
 public function update($post_id, $post = '')
 {
     // Fix for attachment save issue in WordPress 3.5.
     // @link http://core.trac.wordpress.org/ticket/21963
     if (!is_object($post)) {
         $post = get_post();
     }
     // Verify the nonce.
     if (!isset($_POST['members_cp_meta']) || !wp_verify_nonce($_POST['members_cp_meta'], 'members_cp_meta_nonce')) {
         return;
     }
     /* === Roles === */
     // Get the current roles.
     $current_roles = members_get_post_roles($post_id);
     // Get the new roles.
     $new_roles = isset($_POST['members_access_role']) ? $_POST['members_access_role'] : '';
     // If we have an array of new roles, set the roles.
     if (is_array($new_roles)) {
         members_set_post_roles($post_id, array_map('members_sanitize_role', $new_roles));
     } elseif (!empty($current_roles)) {
         members_delete_post_roles($post_id);
     }
     /* === Error Message === */
     // Get the old access message.
     $old_message = members_get_post_access_message($post_id);
     // Get the new message.
     $new_message = isset($_POST['members_access_error']) ? stripslashes(wp_filter_post_kses(addslashes($_POST['members_access_error']))) : '';
     // If we have don't have a new message but do have an old one, delete it.
     if ('' == $new_message && $old_message) {
         members_delete_post_access_message($post_id);
     } else {
         if ($new_message !== $old_message) {
             members_set_post_access_message($post_id, $new_message);
         }
     }
 }
/**
 * Gets the error message to display for users who do not have access to view the given post.
 * The function first checks to see if a custom error message has been written for the
 * specific post.  If not, it loads the error message set on the plugins settings page.
 *
 * @since  0.2.0
 * @access public
 * @param  int     $post_id
 * @return string
 */
function members_get_post_error_message($post_id)
{
    // Get the error message for the specific post.
    $message = members_get_post_access_message($post_id);
    // Use default error message if we don't have one for the post.
    if (!$message) {
        $message = members_get_setting('content_permissions_error');
    }
    // Return the error message.
    return apply_filters('members_post_error_message', sprintf('<div class="members-access-error">%s</div>', $message));
}