edit-comments.php comment_row_actions ajax problem

I resolved this issue by using the wp-ajax environment. Essentially, I created the callback function for the comment_row_actions filter which created the link pointing to admin-ajax.php in the admin directory with a query string. Then I created the add_action to run in the wp_ajax environment with a redirect back to the referring page. I couldn’t come up with a solution that routed through comment.php.

Code below:

function my_filter_comment_row_actions($actions, $comment) {
if ($comment->comment_approved == '0') {
            //build link
            $nonce = wp_create_nonce('mynonce');
            $screen = get_current_screen();
            $args = array(
                'c' => $comment->comment_ID,
                'action' => 'my_ajax_action',
                'another_query' => '1',
                '_wpnonce' => $nonce,
                'refer' => $screen->parent_file
            );
            $link = esc_url(add_query_arg($args, admin_url('admin-ajax.php')));
            $actions['the_new_link'] = sprintf('<a href="https://wordpress.stackexchange.com/questions/268236/%s" style="color:green">The New Link Text</a>', $link);
        }
        return $actions;
    }
add_filter('comment_row_actions', 'my_filter_comment_row_actions', 10, 2);

So there’s the filter with callback to create the link. Now to the “AJAX” which really isn’t AJAX.

function my_approve_comment_with_tracking() {
        if (wp_verify_nonce($_REQUEST['_wpnonce'], 'mynonce')) {
            //do stuff
            wp_redirect(admin_url($_REQUEST['refer']));
        } else wp_redirect(home_url());
        exit;
    }
    add_action('wp_ajax_my_ajax_action', 'my_approve_comment_with_tracking');

Hope this helps someone.

Leave a Comment

deneme bonusu veren sitelerbahis siteleripulibet girişdeneme bonusutürkçe altyazılı pornocanlı bahis casinocanlı bahis casino siteleriOnwin Güncel Girişholiganbetholiganbet girişholiganbet güncel giriş