惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

知更鸟

WordPress临时缓存管理工具:Transients Manager WordPress后台桌面模式:Desktop Mode WordPress 7.0 发布 分类批量操作插件:Term Management Tools 附件重命名插件:Media File Renamer WordPress 7.0 RC3发布,正式版最终发布日期为 2026 年5月20日 特色图像工具:XO Featured Image Tools 乌克兰挺住,俄罗斯加油,我试一下新浪图片外链 固态硬盘基准测试:AS SSD Benchmark
WordPress编辑评论时修改评论者的IP地址
知更鸟 · 2026-05-25 · via 知更鸟

默认WordPress后台编辑评论时,不能修改评论者的IP,只能进入数据库wp_comments表中修改。可以通过下面的代码在编辑评论页面添加IP修改表单。

WordPress编辑评论时修改评论者的IP地址

将代码添加到当前主题functions.php函数模板中即可。

// 后台评论编辑页添加IP输入框
add_action( 'add_meta_boxes_comment', 'custom_comment_ip_meta_box' );
function custom_comment_ip_meta_box() {
	// 仅管理员可见
	if ( ! current_user_can( 'moderate_comments' ) ) {
		return;
	}

	add_meta_box(
		'comment-ip-address',
		'评论 IP 地址',
		'custom_render_comment_ip_meta_box',
		'comment',
		'normal',
		'high'
	);
}

// 渲染IP输入框
function custom_render_comment_ip_meta_box( $comment ) {
	// CSRF 安全验证
	wp_nonce_field( 'save_comment_ip_action', 'comment_ip_nonce' );

	// 获取当前评论IP
	$ip = $comment->comment_author_IP;
	?>
	<div class="comment-ip-field">
		<p>
			<label for="comment_author_ip" class="strong">IP 地址:</label>
			<input 
				type="text" 
				name="comment_author_ip" 
				id="comment_author_ip" 
				value="<?php echo esc_attr( trim( $ip ) ); ?>" 
				class="regular-text"
				placeholder="例如:192.168.1.1"
			/>
		</p>
	</div>
	<?php
}

// 保存IP地址
add_action( 'edit_comment', 'custom_save_comment_ip' );
function custom_save_comment_ip( $comment_id ) {
	if ( ! current_user_can( 'moderate_comments' ) ) {
		wp_die( '您没有权限修改评论IP' );
	}

	if ( ! isset( $_POST['comment_ip_nonce'] ) || ! wp_verify_nonce( $_POST['comment_ip_nonce'], 'save_comment_ip_action' ) ) {
		wp_die( '安全校验失败,请刷新页面重试' );
	}

	if ( ! isset( $_POST['comment_author_ip'] ) ) {
		return;
	}

	// 获取并清理IP
	$raw_ip = trim( $_POST['comment_author_ip'] );
	// 验证是否为合法IP地址
	if ( ! empty( $raw_ip ) && ! WP_Http::is_ip_address( $raw_ip ) ) {
		wp_die( '请输入合法的 IP 地址' );
	}

	// 更新IP字段
	global $wpdb;
	$wpdb->update(
		$wpdb->comments,
		array( 'comment_author_IP' => $raw_ip ),
		array( 'comment_ID' => $comment_id )
	);
}

适用场景

当主题有评论IP归属地显示功能,管理员可以自己加评论,通过修改IP冒充评论者来自五湖四海....

本站文章大部分为原创,用于个人学习记录,可能对您有所帮助,仅供参考!

点赞

登录收藏

https://zmingcx.com/modify-ip-address-in-wordpress-comment-editing.html 复制链接 复制链接

weinxin

版权声明

本站原创文章转载请注明文章出处及链接,谢谢合作!

知更鸟

  • WordPress
  • functions.php