• Resolved dlopeman

    (@dlopeman)


    I put this in my entry.php after the “Edit” bit (thus the pipe | )

    To give everyone (authors) ability to delete their post:

    <?php if (current_user_can('edit_post', $post->ID)) echo "| <a href='" . wp_nonce_url("/wp-admin/post.php?action=delete&post=$id", 'delete-post_' . $post->ID) . "'>Delete post</a>" ?>

    To give admin (you!) for easy frontend administration:

    <?php if (current_user_can('level_10')) echo "| <a href='" . wp_nonce_url("/wp-admin/post.php?action=delete&post=$id", 'delete-post_' . $post->ID) . "'>Delete post</a>" ?>

    I thought I read something about “level_?” being deprecated… anyway – works for now!

    As soon as I figure out the delete_comment part, I’ll post here.

Viewing 6 replies - 1 through 6 (of 6 total)
  • jmunn

    (@jmunn)

    Thanks.
    I guess this first bit wouldn’t work with the “let all registered users publish” option as they are not authors?

    Thread Starter dlopeman

    (@dlopeman)

    NO – but a quick google search will give you the levels…

    Or wouldn’t the current user be able to “edit_post” so then that first bit of code would work…

    Thread Starter dlopeman

    (@dlopeman)

    OH – be careful that you do not grant everyone permissions to remove ANY posts… just their own! I don’t know how MU handles this.

    Most people think they need to use MU because it means MULTI USER…

    But you should really understand what it means.

    I have MULTIPLE users on my regular WP… They can all blog. THey can all post.

    I think the MU is so they can have their own separate BLOGs… or something… So is that what you really want?

    And then why use P2 in that case?

    jmunn

    (@jmunn)

    Oh I don’t know about the WPMU. You get one thing in your head and you just kinda go for it. Not sure if it’s what I really need though.
    Thanks again for the tips! Site “looks” great btw.

    Thread Starter dlopeman

    (@dlopeman)

    Welp – been trying to get a DELETE COMMENT part working… I did, but there are a few caveats.
    First, it takes you to the backend, to confirm. Once you confirm, it takes you to the backend list of comments… instead of the page from where you came.
    Second, it breaks the AJAX for comments. YUK! I was OK with the backend redirect, because I set mine to only allow ADMINs to del/spam.
    Third, I can’t get it to display WHERE I want… maybe you guys can figure out what I’m doing wrong.

    Anyway, the code goes in functions.php…
    Go down to the function prologue_comment_frontpage(…
    Put this function above that function:

    function delete_comment_link($id) { if (current_user_can('level_10')) {
    echo '<a href="' . wp_nonce_url("/wp-admin/comment.php?action=cdc&c=$id", 'delete-comment_' . $post->ID) . '">del</a> ';
    echo '| <a href="' . wp_nonce_url("/wp-admin/comment.php?action=cdc&dt=spam&c=$id") . '">spam</a>';
    } }

    Then add stuff to the prologue_comment_frontpage(..) function:
    a variable:

    deletespam_comment = delete_comment_link(get_comment_ID());

    and the somewhere in the HTML area you would just call it:
    $deletespam_comment

    I must have altered mine too much because it is exactly that which breaks the AJAX.

    Here’s the whole snippet (NOTE: I commented out them until I have time to figure it out!):

    function delete_comment_link($id) {   if (current_user_can('level_10')) {   echo '<a href="' . wp_nonce_url("/wp-admin/comment.php?action=cdc&c=$id", 'delete-comment_' . $post->ID) . '">del</a> ';
       echo '| <a href="' . wp_nonce_url("/wp-admin/comment.php?action=cdc&dt=spam&c=$id") . '">spam</a>';
      }
    }
    
    function prologue_comment_frontpage( $comment, $args, $echocomment = true ) {
            $GLOBALS['comment'] = $comment;
            $depth = prologue_get_comment_depth( get_comment_ID() );
            $comment_text =  apply_filters( 'comment_text', $comment->comment_content );
            $comment_class = comment_class( $class = '', $comment_id = null, $post_id = null, $echo = false );
            $comment_time = get_comment_time();
            $comment_date = get_comment_date();
            $id = get_comment_ID();
            $avatar = prologue_get_avatar( $comment->user_id, $comment->comment_author_email, 32 );
            $author_link = get_comment_author_link();
            $reply_link = prologue_get_comment_reply_link(
            array('depth' => $depth, 'max_depth' => $args['max_depth'], 'before' => ' | ', 'reply_text' => __('Reply', 'p2') ),        $comment->comment_ID, $comment->comment_post_ID );        $can_edit = current_user_can( 'edit_post', $comment->comment_post_ID );        $edit_comment_url = get_edit_comment_link( $comment->comment_ID );
            $edit_link = $can_edit? " | <a class='comment-edit-link' href='$edit_comment_url' title='".attribute_escape(__('Edit comment', 'p2'))."'>".__('Edit', 'p2')."</a>" : '';
            //$deletespam_comment = delete_comment_link(get_comment_ID());
            //$deletespam_comment = $can_edit? " | <a href='" . wp_nonce_url(/wp-admin/comment.php?action=cdc&c=$id) . "'>del</a> | <a href='" . wp_nonce_url(/wp-admin/comment.php?acti
    on=cdc&dt=spam&c=$id) . "'>spam</a>" : '';
            $content_class = $can_edit? 'commentcontent comment-edit' : 'commentcontent';
            $awaiting_message = $comment->comment_approved == '0'? '<p><em>'.__('Your comment is awaiting moderation.', 'p2').'</em></p>' : '';
            $permalink = clean_url( get_comment_link() );
            $permalink_text = __('Permalink', 'p2');
            $date_time = sprintf( __('%s <em>on</em> %s', 'p2'),  get_comment_time(), get_comment_date() );
            $html = <<<HTML
    <li $comment_class id="comment-$id">
      <div>
        <div class="commenthead">
          $author_link commented at: $date_time <!-- $deletespam_comment -->
        </div>
    
        <div style="margin: 5px; position: relative; float: left; ">
          $avatar
        </div>
    
        <div class="$content_class" id="commentcontent-$id">
          $comment_text
        </div>
      </div>
    HTML;

    johnywhy

    (@johnywhy)

    problem with delete post for admin code– after it deletes, it tries to redirect browser to same post, which no longer exists.

    is there a way to specify which page to redirect to after delete?

    thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding “Delete Post or Comment” to your P2 Posts’ is closed to new replies.