0

I was trying this code to delete code from frontend but it is giving me syntax error T_String then i tried remove the confirm string it did delete the post but then redirected me to the same post saying "cannot find what your're looking for". how can i enable deleting post from front end and redirect user homepage

current code:

    function wp_delete_post_link($link = 'Delete This', $before = '', $after = '', $title="Move this item to the Trash", $cssClass="delete-post") {
    global $post;
    if ( $post->post_type == 'page' ) {
        if ( !current_user_can( 'edit_page' ) )
            return;
    } else {
        if ( !current_user_can( 'edit_post' ) )
            return;
    }
    $delLink = wp_nonce_url( site_url() . "/wp-admin/post.php?action=trash&post=" . $post->ID, 'trash-' . $post->post_type . '_' . $post->ID);
    $link = '<a class="' . $cssClass . '" href="' . $delLink . '" onclick="javascript:if(!confirm('Are you sure you want to move this item to trash?')) return false;" title="'.$title.'" />'.$link."</a>";
    return $before . $link . $after;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.