问问题
406 次
1 回答
1
我很难找到一种纯 PHP 方法来使用钩子来做到这一点,但我认为没有。注释表中的大部分 HTML 都是通过文件中的 echo 输出的wp-admin/includes/class-wp-comments-list-table.php
,可以轻松扩展,但我没有看到指示 Wordpress 加载扩展类的方法。
无论如何,这是一个 Wordpress 插件,它注册一个钩子,admin_footer
如果正在查看的页面是edit-comments.php
.
您可以将其放在一个.php
文件中并将其添加到您的wp-content/plugins
文件夹中。转到 WP Admin,然后激活插件。我叫它Comment IP Address Blacklist Lookup
。
这是代码。我不打算用它做任何事情,所以我将它作为 GPL 代码发布。随时寻求帮助或提出任何改进建议。
<?php
/*
Plugin Name: Comment IP Address Blacklist Lookup
Plugin URI: http://example.com
Description: Changes the IP address link in the comment list to MXToolbox.com's blacklist check
Author: Drew Phillips
Version: 0.1
Author URI: https://www.drew.co.il
*/
/* Copyright (C) 2012 Drew Phillips
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once ABSPATH . '/wp-includes/pluggable.php';
// Admin menu and admin functions below...
add_action('admin_footer', 'replace_admin_footer');
function replace_admin_footer()
{
if (basename($_SERVER['SCRIPT_FILENAME']) == 'edit-comments.php') {
echo <<<EOD
<script type="text/javascript">
<!--
function replace_comments()
{
var links = document.getElementsByTagName('a');
var i, link, match;
for (i in links) {
link = links[i];
if ( null != (match = link.href.match(/edit-comments\.php\?s=(\d+\.\d+\.\d+\.\d+)&mode=detail/))) {
link.href = "http://www.mxtoolbox.com/SuperTool.aspx?action=blacklist:" + match[1];
link.target = "_blank";
}
}
}
replace_comments();
-->
EOD;
}
}
于 2012-07-16T23:43:27.073 回答