{"id":2827,"date":"2025-06-11T07:37:41","date_gmt":"2025-06-10T23:37:41","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/wpdt\/2827.html"},"modified":"2025-06-11T07:37:41","modified_gmt":"2025-06-10T23:37:41","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-wordpress-%e8%af%84%e8%ae%ba%e4%b8%ad%e5%81%9c%e6%ad%a2%e5%ad%98%e5%82%a8-ip-%e5%9c%b0%e5%9d%80","status":"publish","type":"post","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/post\/2827.html","title":{"rendered":"\u5982\u4f55\u5728 WordPress \u8bc4\u8bba\u4e2d\u505c\u6b62\u5b58\u50a8 IP \u5730\u5740"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">Bug&#32534;&#35793;&#29422;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; WordPress &#20013;&#65292;&#22914;&#26524;&#20320;&#24076;&#26395;&#19981;&#20877;&#20445;&#23384;&#29992;&#25143;&#30340; IP &#22320;&#22336;&#20197;&#38450;&#27490;&#36319;&#36394;&#25110;&#38544;&#31169;&#38382;&#39064;&#65292;&#20320;&#21487;&#20197;&#36890;&#36807;&#20462;&#25913; <code>wp-config.php<\/code> &#25991;&#20214;&#26469;&#23454;&#29616;&#36825;&#19968;&#28857;&#12290;&#19981;&#36807;&#65292;&#22312;&#23454;&#38469;&#25805;&#20316;&#20043;&#21069;&#65292;&#35831;&#30830;&#20445;&#20320;&#20102;&#35299;&#36825;&#19968;&#27493;&#39588;&#30340;&#28508;&#22312;&#24433;&#21709;&#65292;&#22240;&#20026;&#31105;&#29992; IP &#22320;&#22336;&#23384;&#20648;&#21487;&#33021;&#20250;&#23548;&#33268;&#26576;&#20123;&#21151;&#33021;&#26080;&#27861;&#27491;&#24120;&#24037;&#20316;&#12290;<\/p>\n<h3>&#27493;&#39588; 1: &#25171;&#24320; wp-config.php &#25991;&#20214;<\/h3>\n<p>&#39318;&#20808;&#65292;&#20320;&#38656;&#35201;&#25214;&#21040;&#24182;&#25171;&#24320; <code>wp-config.php<\/code> &#25991;&#20214;&#12290;&#36825;&#20010;&#25991;&#20214;&#36890;&#24120;&#20301;&#20110;&#20320;&#30340; WordPress &#20027;&#30446;&#24405;&#19979;&#30340; <code>wp-content<\/code> &#30446;&#24405;&#19979;&#12290;<\/p>\n<pre><code class=\"language-bash\">sudo nano \/path\/to\/your-wordpress\/wp-config.php<\/code><\/pre>\n<h3>&#27493;&#39588; 2: &#20462;&#25913;&#25968;&#25454;&#24211;&#37197;&#32622;<\/h3>\n<p>&#25214;&#21040;&#20197;&#19979;&#34892;&#65306;<\/p>\n<pre><code class=\"language-php\">define('DB_CHARSET', 'utf8mb4');\ndefine('DB_COLLATE', '');<\/code><\/pre>\n<p>&#21024;&#38500;&#25110;&#32773;&#27880;&#37322;&#25481;&#36825;&#20004;&#34892;&#65292;&#28982;&#21518;&#28155;&#21152;&#20197;&#19979;&#20004;&#34892;&#65306;<\/p>\n<pre><code class=\"language-php\">$wpdb-&gt;comments_table = $table_prefix . 'comment';\n$wpdb-&gt;commentmeta_table = $table_prefix . 'commentmeta';\n$wpdb-&gt;postmeta_table = $table_prefix . 'postmeta';<\/code><\/pre>\n<p>&#36825;&#20123;&#26356;&#25913;&#20250;&#21578;&#35785; WordPress &#20351;&#29992; MySQL &#30340; UTF-8 &#23383;&#31526;&#38598;&#21644;&#23383;&#31526;&#25490;&#24207;&#35268;&#21017;&#65292;&#32780;&#19981;&#26159;&#40664;&#35748;&#30340; ANSI &#25110;&#32773;&#20854;&#20182;&#23383;&#31526;&#38598;&#12290;<\/p>\n<h3>&#27493;&#39588; 3: &#28155;&#21152;&#39069;&#22806;&#30340;&#33258;&#23450;&#20041;&#25554;&#20214;&#65288;&#21487;&#36873;&#65289;<\/h3>\n<p>&#20026;&#20102;&#36827;&#19968;&#27493;&#30830;&#20445;&#29992;&#25143;&#25968;&#25454;&#30340;&#23433;&#20840;&#24615;&#65292;&#21487;&#20197;&#32771;&#34385;&#23433;&#35013;&#19968;&#20123;&#19987;&#38376;&#29992;&#20110;&#20445;&#25252;&#29992;&#25143;&#25968;&#25454;&#23433;&#20840;&#30340;&#25554;&#20214;&#65292;&#20363;&#22914;&ldquo;WP Security Scan&rdquo;&#25110;&ldquo;Wordfence&rdquo;&#12290;&#36825;&#20123;&#25554;&#20214;&#21487;&#20197;&#24110;&#21161;&#20320;&#22312;&#27809;&#26377;&#21551;&#29992; IP &#22320;&#22336;&#23384;&#20648;&#30340;&#24773;&#20917;&#19979;&#65292;&#20173;&#28982;&#33021;&#22815;&#26377;&#25928;&#22320;&#30417;&#25511;&#21644;&#20445;&#25252;&#20320;&#30340;&#32593;&#31449;&#12290;<\/p>\n<h3>&#31034;&#20363;&#20195;&#30721;<\/h3>\n<p>&#20197;&#19979;&#26159;&#20462;&#25913;&#21518;&#30340; <code>wp-config.php<\/code> &#37096;&#20998;&#65306;<\/p>\n<pre><code class=\"language-php\">\/\/ Define database settings\ndefine('DB_NAME', 'your_database_name');\ndefine('DB_USER', 'your_username');\ndefine('DB_PASSWORD', 'your_password');\ndefine('DB_HOST', 'localhost');\n\n\/\/ Enable UTF-8 charset and collate\n$table_prefix = \"wp_\";\ndefine('DB_CHARSET', 'utf8mb4');\ndefine('DB_COLLATE', '');\n\n\/\/ Additional security measures (optional)\nrequire_once(ABSPATH . 'wp-admin\/includes\/upgrade.php');\nregister_activation_hook(__FILE__, 'my_custom_activation_callback');\nfunction my_custom_activation_callback() {\n    \/\/ Add custom activation code here if needed\n}\n\n\/\/ Custom comment table names for better security\n$wpdb-&gt;comments_table = $table_prefix . 'comment';\n$wpdb-&gt;commentmeta_table = $table_prefix . 'commentmeta';\n$wpdb-&gt;postmeta_table = $table_prefix . 'postmeta';\n\n\/\/ Other necessary configurations...<\/code><\/pre>\n<h3>&#25928;&#26524;&#35828;&#26126;<\/h3>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#20320;&#21487;&#20197;&#20851;&#38381; WordPress &#40664;&#35748;&#30340; IP &#22320;&#22336;&#23384;&#20648;&#21151;&#33021;&#65292;&#20174;&#32780;&#25552;&#39640;&#32593;&#31449;&#30340;&#23433;&#20840;&#24615;&#21644;&#29992;&#25143;&#20307;&#39564;&#12290;&#20294;&#26159;&#35831;&#27880;&#24847;&#65292;&#36825;&#31181;&#20570;&#27861;&#21487;&#33021;&#20250;&#24433;&#21709;&#26576;&#20123;&#20381;&#36182;&#20110; IP &#22320;&#22336;&#30340;&#25968;&#25454;&#20998;&#26512;&#24037;&#20855;&#65292;&#22240;&#27492;&#22312;&#23454;&#26045;&#21069;&#26368;&#22909;&#27979;&#35797;&#19968;&#19979;&#20854;&#23545;&#32593;&#31449;&#36816;&#33829;&#30340;&#24433;&#21709;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;&#21069;&#30340;Bug&#35821;&#27861;&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">&#40657;&#26495;&#21069;&#30340;Bug&#35821;&#27861;&#35762;&#24072;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; WordPress &#20013;&#65292;&#29992;&#25143;&#21487;&#20197;&#20351;&#29992; <code>comment_author_IP<\/code> &#21442;&#25968;&#26469;&#25351;&#23450;&#26159;&#21542;&#23384;&#20648;&#29992;&#25143;&#30340; IP &#22320;&#22336;&#12290;&#20197;&#19979;&#26159;&#22914;&#20309;&#35774;&#32622;&#27492;&#21442;&#25968;&#30340;&#27493;&#39588;&#65306;<\/p>\n<h3>&#27493;&#39588; 1: &#25171;&#24320; WordPress &#35774;&#32622;<\/h3>\n<p>&#39318;&#20808;&#65292;&#22312;&#24744;&#30340; WordPress &#20027;&#39064;&#25110;&#20027;&#39064;&#25991;&#20214;&#22841;&#20013;&#25214;&#21040; <code>functions.php<\/code> &#25991;&#20214;&#12290;<\/p>\n<h3>&#27493;&#39588; 2: &#28155;&#21152; <code>comment_author_IP<\/code> &#20989;&#25968;<\/h3>\n<p>&#25171;&#24320; <code>functions.php<\/code> &#25991;&#20214;&#65292;&#28982;&#21518;&#28155;&#21152;&#20197;&#19979;&#20195;&#30721;&#65306;<\/p>\n<pre><code class=\"language-php\">function wpse50468_comment_author_ip() {\n    if (isset($_POST['comment_author']) &amp;&amp; !empty($_POST['comment_author'])) {\n        $author = $_POST['comment_author'];\n        $ip_address = get_client_ip();\n        $author_ip = isset($author-&gt;IP) ? $author-&gt;IP : '';\n        $new_author = new stdClass;\n        $new_author-&gt;name = $author;\n        $new_author-&gt;ip = $ip_address;\n\n        update_user_meta(get_current_user_id(), 'comment_author', $new_author);\n    }\n}\nadd_action('init', 'wpse50468_comment_author_ip');<\/code><\/pre>\n<h3>&#27493;&#39588; 3: &#26816;&#26597;&#29992;&#25143; IP &#22320;&#22336;<\/h3>\n<p>&#35201;&#26816;&#26597;&#24403;&#21069;&#29992;&#25143;&#26159;&#21542;&#24050;&#25552;&#20379;&#26377;&#25928;&#30340; IP &#22320;&#22336;&#65292;&#35831;&#36816;&#34892;&#20197;&#19979;&#20195;&#30721;&#65306;<\/p>\n<pre><code class=\"language-php\">$user = wp_get_current_user();\nif ($user) {\n    $user_ip = get_user_meta($user-&gt;ID, 'comment_author_ip', true);\n    echo \"User IP: {$user_ip}\";\n} else {\n    echo \"No user found.\";\n}<\/code><\/pre>\n<h3>&#27493;&#39588; 4: &#24212;&#29992;&#27492;&#21151;&#33021;&#21040;&#29305;&#23450;&#35780;&#35770;&#31867;&#22411;<\/h3>\n<p>&#22914;&#26524;&#24744;&#24076;&#26395;&#20165;&#24212;&#29992;&#20110;&#29305;&#23450;&#31867;&#22411;&#30340;&#35780;&#35770;&#65288;&#20363;&#22914;&#65292;&#25991;&#31456;&#35780;&#35770;&#65289;&#65292;&#21017;&#38656;&#35201;&#21019;&#24314;&#19968;&#20010;&#33258;&#23450;&#20041;&#26631;&#31614;&#24182;&#23558;&#20854;&#24212;&#29992;&#21040;&#35813;&#35780;&#35770;&#31867;&#22411;&#19978;&#12290;&#20197;&#19979;&#26159;&#22312;&#25991;&#31456;&#35780;&#35770;&#20013;&#21551;&#29992;&#27492;&#21151;&#33021;&#30340;&#26041;&#27861;&#65306;<\/p>\n<ul>\n<li>&#21019;&#24314;&#19968;&#20010;&#33258;&#23450;&#20041;&#26631;&#31614;&#65306;\n<pre><code class=\"language-bash\">wp custom taxonomy create --name comment_author_ip --description \"Comment with author's IP address\"<\/code><\/pre><\/li>\n<li>&#26356;&#26032;&#35780;&#35770;&#27169;&#26495;&#20197;&#26174;&#31034;&#29992;&#25143; IP&#65306;\n<pre><code class=\"language-php\">\n&lt;?php\n\/\/ &#33719;&#21462;&#24403;&#21069;&#29992;&#25143;&#20449;&#24687;\n$user = wp_get_current_user();<\/code><\/pre><\/li>\n<\/ul>\n<p>\/\/ &#26816;&#26597;&#29992;&#25143;&#26159;&#21542;&#23384;&#22312;\nif (!is_wp_error($user)) {\n\/\/ &#33719;&#21462;&#24403;&#21069;&#29992;&#25143;IP&#22320;&#22336;\n$user_ip = get_user_meta($user-&gt;ID, &#8216;comment_author_ip&#8217;, true);<\/p>\n<pre><code>\/\/ &#22312;&#35780;&#35770;&#36755;&#20986;&#20013;&#26174;&#31034;&#29992;&#25143;IP\nif ($user_ip) {\n    printf('&lt;div class=\"comment-author-ip\"&gt;&lt;span&gt;%s&lt;\/span&gt;&lt;\/div&gt;', esc_html($user_ip));\n} else {\n    printf('&lt;div class=\"comment-author-ip\"&gt;&lt;span&gt;-&lt;\/span&gt;&lt;\/div&gt;');\n}<\/code><\/pre>\n<p>}\n?&gt;<\/p>\n<pre><code>\n\n&#36890;&#36807;&#19978;&#36848;&#26041;&#27861;&#65292;&#24744;&#21487;&#20197;&#22312; WordPress &#30340;&#35780;&#35770;&#34920;&#21333;&#20013;&#31105;&#29992;&#33258;&#21160;&#23384;&#20648; IP &#22320;&#22336;&#30340;&#21151;&#33021;&#12290;&#21482;&#38656;&#30830;&#20445;&#24744;&#30340;&#29992;&#25143;&#26377;&#36275;&#22815;&#26435;&#38480;&#25165;&#33021;&#35775;&#38382;&#36825;&#20123;&#21151;&#33021;&#12290;<\/code><\/pre>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312; WordPress &#20013;&#65292;&#22914;&#26524;&#20320;&#24076;&#26395;&#19981;&#20877;&#20445;&#23384;&#29992;&#25143;&#30340; ..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[59],"tuisongtax":[],"class_list":["post-2827","post","type-post","status-publish","format-standard","hentry","category-wpdt","tag-pzjc"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/2827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/comments?post=2827"}],"version-history":[{"count":0,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/2827\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=2827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/categories?post=2827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=2827"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=2827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}