0

I have updated my Wordpress version from 4.3.1 to 4.5.2 and apparently it broke a custom function I've made in the past.
What it does: Display a anchor below comments, next to Approve/Answer/Edit/Spam/Delete in the backend. On anchor click it does redirect me to "wp-admin/cust_comment.php?c=ID&action=(un)highlightcomment&_wpnonce=HASH". From this point it should update the comments meta_key "highlight" to 1 or 0. But instead all I'm receiving is a blank page.

cust_comment.php

custom "wp-admin/comment.php"

<?php
require_once( dirname( __FILE__ ) . '/admin.php' );
wp_reset_vars( array('action') );
$comment_id = absint( $_GET['c'] );

switch( $action ) {

    case 'highlightcomment'    :
    case 'unhighlightcomment'  :

        $noredir = isset($_REQUEST['noredir']);

        if ( !$comment = get_comment($comment_id) )
            comment_footer_die( __( 'Invalid comment ID.' ) . sprintf(' <a href="%s">' . __('Go back') . '</a>.', 'edit-comments.php') );
        if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
            comment_footer_die( __('You are not allowed to edit comments on this post.') );

        if ( '' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), 'comment.php') )
            $redir = wp_get_referer();
        elseif ( '' != wp_get_original_referer() && ! $noredir )
            $redir = wp_get_original_referer();
        elseif ( in_array( $action, array( 'highlightcomment', 'unhighlightcomment' ) ) )
            $redir = admin_url('edit-comments.php?p=' . absint( $comment->comment_post_ID ) );
        else
            $redir = admin_url('edit-comments.php');

        $redir = remove_query_arg( array('highlighted', 'unhighlighted'), $redir );

        switch ($action) {

            case 'highlightcomment' :
                update_comment_meta($comment_id, 'highlight', 1);
                $redir = add_query_arg( array('highlighted' => '1'), $redir );
                break;

            case 'unhighlightcomment' :
                update_comment_meta($comment_id, 'highlight', 0);
                $redir = add_query_arg( array('unhighlighted' => '1'), $redir );
                break;
        }

        wp_redirect( $redir );
        die;

        break;

    default:
        wp_die( __('Unknown action.') );

} // end switch

functions.php

add_filter('comment_row_actions', 'cust_hightlight_comment_action', 10, 2);
function cust_hightlight_comment_action($actions, $comment) {

    $highlight_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );

    $url = "cust_comment.php?c=$comment->comment_ID";
    $highlight_url =  $url . "&action=highlightcomment&$highlight_nonce";
    $unhighlight_url = $url . "&action=unhighlightcomment&$highlight_nonce";

    if (!get_comment_meta( $comment->comment_ID, 'highlight', true) )
        $actions['highlighter'] = "<a href='$highlight_url' class='vim-a'>" . _x( 'Highlight' ) . '</a>';
    else
        $actions['unhighlighter'] = "<a href='$unhighlight_url' class='vim-u'>" . _x( 'Don\'t highlight') . '</a>';

    return $actions;
}
  • 1
    What have you done to make sure that this code is actually what is breaking your site? – cjbj Jun 9 '16 at 8:35
  • It is not breaking the site. Only the action seems not to be executed/received which results in a blank page. – AlexG Jun 9 '16 at 8:41
  • 1
    What's the value of $action just before and after wp_reset_vars()? It may be that it's not getting set properly, or that you need to declare global $action; before using it in the switch statement. – Morgan Estes Jun 10 '16 at 5:24
0

I've found the source of the problem, I have redeclared the function comment_footer_die(). Which wordpress obviously can't accept. My supplied code works as intended.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.