function frontier_edit_post_link($url, $post_id)
{
    // Redirect to frontier post unless is called from admin panel or it is a post type not allowed in frontier post
    if (is_admin() || !fp_check_post_type(get_post_type($post_id))) {
        return $url;
    } else {
        if (current_user_can('frontier_post_redir_edit')) {
            $frontier_edit_page = (int) fp_get_option('fps_page_id');
            $url = '';
            $concat = get_option("permalink_structure") ? "?" : "&";
            //set the permalink for the page itself
            $frontier_permalink = get_permalink($frontier_edit_page);
            $url = $frontier_permalink . $concat . "task=edit&postid=" . $post_id;
        }
    }
    return $url;
}
function frontier_can_delete($tmp_post)
{
    $fps_access_check_msg = "";
    $cur_user = wp_get_current_user();
    $tmp_can_do = true;
    // Check if the user is allowed to delete posts
    if (!current_user_can('frontier_post_can_delete')) {
        $tmp_can_do = false;
        $fps_access_check_msg .= __("You are not allowed to delete posts", "frontier-post") . "<br>";
    }
    // Users can not delete other users posts unless they have capability "delete_others_posts" (Administrators & Editors)
    if ($cur_user->ID != $tmp_post->post_author && !current_user_can('delete_others_posts')) {
        $tmp_can_do = false;
        $fps_access_check_msg .= __("You are not allowed to delete post from another user", "frontier-post") . "<br>";
    }
    // Check that the age of the post is below the Frontier Post setting
    if (frontier_post_age($tmp_post->post_date) > fp_get_option_int('fps_delete_max_age')) {
        $tmp_can_do = false;
        $fps_access_check_msg .= __("You are not allowed to delete post older than: ", "frontier-post") . get_option('frontier_post_delete_max_age') . " " . __("days", "frontier-post") . "<br>";
    }
    // Check that user is allowed to delete posts that already has comments
    if ((int) $tmp_post->comment_count > 0 && !fp_get_option_bool("fps_del_w_comments")) {
        $tmp_can_do = false;
        $fps_access_check_msg .= __("You are not allowed to deelete post that already has comments", "frontier-post") . "<br>";
    }
    // Check that user is allowed to delete published posts
    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 delete published posts", "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 delete", "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 deleted by the author, or users with capability delete_private_posts (admins and editors)
    if ($tmp_post->post_status == "private" && ($cur_user->ID != $tmp_post->post_author || !current_user_can('frontier_post_can_private') || !current_user_can('frontier_post_can_delete'))) {
        $tmp_can_do = false;
        $fps_access_check_msg .= __("You are not allowed to delete PRIVATE post from another user", "frontier-post") . "<br>";
    }
    return $tmp_can_do;
}