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

推荐订阅源

T
Tenable Blog
H
Heimdal Security Blog
K
Kaspersky official blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Schneier on Security
G
GRAHAM CLULEY
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
CERT Recently Published Vulnerability Notes
Google DeepMind News
Google DeepMind News
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
C
Cisco Blogs
Cyberwarzone
Cyberwarzone
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
Security Archives - TechRepublic
Security Archives - TechRepublic
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
V
Visual Studio Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Jina AI
Jina AI
P
Proofpoint News Feed
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
S
Security Affairs
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
N
News | PayPal Newsroom
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
NISL@THU
NISL@THU

知更鸟

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