Since the newest WP version 4.3.1, there's a change in the WordPress core JavaScript file: /wp-admin/js/edit-comments.js

At line 376, the WordPress dev added a check for how many table columns there are in the table listing the comments in the admin panel.

colspanVal = $( 'th:visible, td:visible', c ).length;

The thing is, I'm adding data to the comments and the data is actually displayed in a table; this causes the jQuery above to count those table columns and then render the reply to comment table row with a colspan of 24, which totally messes up the layout once you click 'reply' in the WordPress admin comment section.

<tr id="replyrow" class="inline-edit-row" style="">
    <td class="colspanchange" colspan="24">
        ...
    </td>
</tr>

So I figured out that I had to change the jQuery selector and exclude my table from counting th or td.

colspanVal = $( 'th:visible table:not(".timeSheetEntries"), td:visible table:not(".timeSheetEntries")', c ).length;

This tiny hack works as expected but I don't want to apply this modification every time WordPress releases an update.

How can I overwrite this WordPress JavaScript core function? Not sure if there are any actions and filters for JavaScript in WordPress?

Or should I dequeue and enqueue my custom JavaScript?

有帮助吗?

解决方案

You can't.

While manipulation of JS and HTML is possible, it is not adviceable as a long term strategy unless it was explicitly document as "the right way" in the codex, code comment, or some other core document.

In addition to the theoretical objection, right now it is hard or almost impossible to override specific JS core functions without resorting to dequeuing core files and enqueuing your version which in practice do not eliminate the need to follow up with changes to the core file and re implementing your changes with every version that changes the core file.

Your best option is probably to open a ticket on trac, explain that the change is breaking your code and why you don't have any other alternative. This will probably not help you with 4.3.1 but you might get either a better suggestion on how to do what you need without hacking the core, and maybe have the offending code reverted for 4.4.

许可以下: CC-BY-SA归因
scroll top