1. Expand the Quick Edit Menu Interface

We can add elements into the comments quick edit menu by hooking into the wp_comment_reply filter. This filter allows us to replace the existing menu with our own creation.

However, since we only want to insert a few new elements, and keep the rest of the interface intact, we start by copying over the HTML code from the current menu. The HTML code can be found in the wp-admin/includes/template.php file, in the wp_comment_reply function.

After we reproduce the default menu, then we can add in or change whatever elements that we want.

Lines 60-79 are our added comment fields. All the rest is from the existing quick edit menu. Below is our expanded menu, in particular, Post ID, Parent ID, and IP input boxes have been added.

Note that the fields are all currently empty. To fill our new fields, we must include the appropriate data in the comments list table, and then extract those values using javascript when the Quick Edit button is pressed.

Expanded WordPress Comments Quick Edit Menu

2. Populate Our New Quick Edit Menu Fields

To populate our new fields, we need to do 3 things –

Include the relevant data in each row of the comments list table.

Extract the relevant values using javascript and put them into the appropriate fields.

Tie our javascript code to the comments Quick Edit button.

a) Include the relevant data

We can add new data into the comments list by hooking into the comment_text filter. In this case, we are not using the filter to change the comment text, but rather to generate new data at the right place.

Line 8 – Retrieve the quick edit menu div (#editRow).Line 9 – Retrieve the current row being edited (#rowData). Note that inline-xtra-‘+id should correspond to the div name specified in our my_menu_data function.Lines 10-12 – Extract values from the current row being edited (#rowData) and insert it into our quick edit menu (#editRow).

c) Tie our javascript to the Quick Edit button

Finally, we need to call our expandedOpen javascript function when the Quick Edit button is pressed.

Line 5 – Check that we are on the comments list screen (edit-comments).

Lines 6-9 – Only include the necessary quick edit menu filters and actions when we are on the comments list screen.

If we want to add our expanded Quick Edit Menu functionality to other screens, then we simply expand our condition check on line 5. For example, we may replace line 5 with –

if (in_array($screen->id, array('edit-comments','post')) ) {

This will add the expanded functionality to the edit-comments as well as edit post screens.

WordPress 3.5

As of WordPress 3.5, the current_screen filter no longer gets called when making asynchronous (e.g. AJAX) calls to the server. Therefore, we also need to add our quick edit actions and filters to the appropriate ajax calls.

Comments

I was looking for a tut just like this – you always seem to have what I’m looking for What if I want to save a user-defined field? Would that be as easy as including a field for it with my custom ID and then saving it? For instance, instead of comment-post-id, could I use my-custom-comment-id?