{"id":3281,"date":"2025-06-11T20:29:52","date_gmt":"2025-06-11T12:29:52","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/wpdt\/3281.html"},"modified":"2025-06-11T20:29:52","modified_gmt":"2025-06-11T12:29:52","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bb%a5%e5%8f%8a%e5%a6%82%e4%bd%95%e5%9c%a8wordpress%e4%b8%8a%e9%99%90%e5%88%b6%e7%99%bb%e5%bd%95%e6%ac%a1%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/post\/3281.html","title":{"rendered":"\u4e3a\u4ec0\u4e48\u4ee5\u53ca\u5982\u4f55\u5728WordPress\u4e0a\u9650\u5236\u767b\u5f55\u6b21\u6570"},"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&#32593;&#31449;&#19978;&#38480;&#21046;&#29992;&#25143;&#30331;&#24405;&#27425;&#25968;&#21487;&#20197;&#38450;&#27490;&#24694;&#24847;&#27880;&#20876;&#21644;&#33258;&#21160;&#30331;&#24405;&#36134;&#25143;&#12290;&#36825;&#19981;&#20165;&#21487;&#20197;&#20445;&#25252;&#24744;&#30340;&#32593;&#31449;&#20813;&#21463;&#22403;&#22334;&#37038;&#20214;&#21644;&#26426;&#22120;&#20154;&#33258;&#21160;&#21270;&#25915;&#20987;&#65292;&#36824;&#21487;&#20197;&#25552;&#39640;&#29992;&#25143;&#20307;&#39564;&#12290;&#20197;&#19979;&#26159;&#23454;&#29616;&#36825;&#19968;&#21151;&#33021;&#30340;&#26041;&#27861;&#65306;<\/p>\n<h3>&#27493;&#39588; 1: &#21019;&#24314;&#19968;&#20010;&#33258;&#23450;&#20041;&#25554;&#20214;<\/h3>\n<p>&#39318;&#20808;&#65292;&#25105;&#20204;&#38656;&#35201;&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;PHP&#25991;&#20214;&#26469;&#22788;&#29702;&#29992;&#25143;&#30340;&#30331;&#24405;&#35831;&#27714;&#12290;&#36825;&#20010;&#25991;&#20214;&#20250;&#26816;&#26597;&#29992;&#25143;&#26159;&#21542;&#24050;&#32463;&#30331;&#24405;&#36807;&#65292;&#22914;&#26524;&#24050;&#30331;&#24405;&#21017;&#25298;&#32477;&#26032;&#30340;&#30331;&#24405;&#35831;&#27714;&#12290;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\/\/ &#33258;&#23450;&#20041;&#25554;&#20214;&#25991;&#20214;&#21517;&#65306;login_limit.php\nadd_action( 'wp_login', 'check_login_attempts' );\nfunction check_login_attempts($username) {\n    global $wpdb;\n\n    \/\/ &#33719;&#21462;&#24403;&#21069;&#30331;&#24405;&#26102;&#38388;\n    $current_time = current_time('timestamp');\n\n    \/\/ &#20174;&#25968;&#25454;&#24211;&#20013;&#33719;&#21462;&#19978;&#27425;&#30331;&#24405;&#26102;&#38388;\n    $last_login = $wpdb-&gt;get_var(\"SELECT last_login FROM wp_users WHERE user_login = '$username'\");\n\n    \/\/ &#35745;&#31639;&#20004;&#27425;&#23581;&#35797;&#20043;&#38388;&#30340;&#38388;&#38548;\n    if ($last_login &amp;&amp; (time() - $last_login &gt; 3600)) { \/\/ &#20551;&#35774;&#27599;&#23567;&#26102;&#20026;&#19968;&#27425;&#23581;&#35797;\n        return false; \/\/ &#25298;&#32477;&#26032;&#30331;&#24405;&#35831;&#27714;\n    }\n}<\/code><\/pre>\n<h3>&#27493;&#39588; 2: &#23558;&#25554;&#20214;&#28155;&#21152;&#21040;&#20027;&#39064;&#25110;&#23433;&#35013;&#21040;Wordpress&#26680;&#24515;<\/h3>\n<p>&#23558;&#19978;&#36848;&#20195;&#30721;&#20445;&#23384;&#20026;<code>login_limit.php<\/code>&#25991;&#20214;&#65292;&#24182;&#23558;&#20854;&#25918;&#32622;&#22312;&#20027;&#39064;&#30446;&#24405;&#19979;&#65288;&#20363;&#22914;<code>\/wp-content\/plugins\/login-limit<\/code>)&#65292;&#25110;&#32773;&#36890;&#36807;FTP&#19978;&#20256;&#33267;&#26381;&#21153;&#22120;&#30340;<code>wp-content\/plugins<\/code>&#30446;&#24405;&#12290;<\/p>\n<p>&#28982;&#21518;&#65292;&#22312;&#20027;&#39064;&#27169;&#26495;&#25991;&#20214;&#20013;&#35843;&#29992;&#27492;&#25554;&#20214;&#20989;&#25968;&#65292;&#20197;&#30830;&#20445;&#27599;&#27425;&#30331;&#24405;&#26102;&#37117;&#25191;&#34892;&#26816;&#26597;&#12290;<\/p>\n<h3>&#27493;&#39588; 3: &#27979;&#35797;&#25554;&#20214;<\/h3>\n<p>&#25171;&#24320;&#24744;&#30340;WordPress&#21518;&#21488;&#65292;&#23548;&#33322;&#21040;&ldquo;&#25554;&#20214;&rdquo; -&gt; &ldquo;&#21551;&#29992;&#25554;&#20214;&rdquo;&#65292;&#25214;&#21040;&#24182;&#28608;&#27963;&#24744;&#21018;&#21018;&#21019;&#24314;&#30340;&#25554;&#20214;&#12290;&#29616;&#22312;&#65292;&#24403;&#24744;&#23581;&#35797;&#37325;&#22797;&#30331;&#24405;&#26102;&#65292;&#31995;&#32479;&#24212;&#35813;&#20250;&#25552;&#31034;&#24744;&#36755;&#20837;&#27491;&#30830;&#30340;&#23494;&#30721;&#65292;&#32780;&#19981;&#26159;&#20801;&#35768;&#20877;&#27425;&#30331;&#24405;&#12290;<\/p>\n<h3>&#25928;&#26524;&#35828;&#26126;<\/h3>\n<ul>\n<li><strong>&#23433;&#20840;&#24615;<\/strong>&#65306;&#36890;&#36807;&#38480;&#21046;&#29992;&#25143;&#30331;&#24405;&#27425;&#25968;&#65292;&#24744;&#21487;&#20197;&#26174;&#33879;&#20943;&#23569;&#22403;&#22334;&#37038;&#20214;&#12289;&#33258;&#21160;&#21270;&#33050;&#26412;&#21644;&#20854;&#20182;&#19981;&#27491;&#24403;&#34892;&#20026;&#23545;&#24744;&#30340;&#32593;&#31449;&#30340;&#24433;&#21709;&#12290;<\/li>\n<li><strong>&#29992;&#25143;&#20307;&#39564;<\/strong>&#65306;&#36991;&#20813;&#39057;&#32321;&#34987;&#38459;&#27490;&#30331;&#24405;&#30340;&#24773;&#20917;&#65292;&#20174;&#32780;&#25552;&#21319;&#29992;&#25143;&#28385;&#24847;&#24230;&#21644;&#20307;&#39564;&#12290;<\/li>\n<\/ul>\n<p>&#20197;&#19978;&#23601;&#26159;&#22914;&#20309;&#22312;WordPress&#19978;&#38480;&#21046;&#30331;&#24405;&#27425;&#25968;&#30340;&#22522;&#26412;&#26041;&#27861;&#12290;&#35831;&#27880;&#24847;&#65292;&#34429;&#28982;&#36825;&#31181;&#26041;&#27861;&#33021;&#26377;&#25928;&#22320;&#20445;&#25252;&#24744;&#30340;&#32593;&#31449;&#65292;&#20294;&#24182;&#19981;&#24847;&#21619;&#30528;&#23436;&#20840;&#26080;&#25032;&#21487;&#20987;&#12290;&#22914;&#26524;&#24744;&#21457;&#29616;&#26377;&#22823;&#37327;&#24322;&#24120;&#30331;&#24405;&#35831;&#27714;&#65292;&#21487;&#33021;&#38656;&#35201;&#36827;&#19968;&#27493;&#35843;&#26597;&#26159;&#21542;&#23384;&#22312;&#20854;&#20182;&#23433;&#20840;&#28431;&#27934;&#25110;&#20854;&#20182;&#24694;&#24847;&#27963;&#21160;&#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&#19978;&#38480;&#21046;&#30331;&#24405;&#27425;&#25968;&#21487;&#20197;&#36890;&#36807;&#35774;&#32622;&#19968;&#20123;&#23433;&#20840;&#31574;&#30053;&#26469;&#23454;&#29616;&#12290;&#36825;&#20123;&#31574;&#30053;&#21487;&#20197;&#24110;&#21161;&#38450;&#27490;&#24694;&#24847;&#29992;&#25143;&#28389;&#29992;&#24744;&#30340;&#32593;&#31449;&#65292;&#20174;&#32780;&#25552;&#39640;&#20854;&#23433;&#20840;&#24615;&#12290;&#20197;&#19979;&#26159;&#19968;&#20123;&#26041;&#27861;&#21644;&#27493;&#39588;&#65306;<\/p>\n<h3>1. &#20462;&#25913;WordPress&#37197;&#32622;&#25991;&#20214;&#65288;wp-config.php&#65289;<\/h3>\n<p>&#39318;&#20808;&#65292;&#24744;&#38656;&#35201;&#20462;&#25913;<code>wp-config.php<\/code>&#25991;&#20214;&#20013;&#30340;&#26576;&#20123;&#35774;&#32622;&#20197;&#38480;&#21046;&#30331;&#24405;&#23581;&#35797;&#27425;&#25968;&#12290;<\/p>\n<p><strong>&#26041;&#27861;&#19968;&#65306;&#36890;&#36807;<code>ini_set()<\/code>&#20989;&#25968;<\/strong><\/p>\n<p>&#25171;&#24320;<code>wp-config.php<\/code>&#25991;&#20214;&#65292;&#25214;&#21040;&#22914;&#19979;&#34892;&#65306;<\/p>\n<pre><code class=\"language-php\">define('WP_ALLOW_IP', true);<\/code><\/pre>\n<p>&#23558;<code>true<\/code>&#25913;&#20026;<code>false<\/code>&#65292;&#36825;&#26679;&#21487;&#20197;&#38459;&#27490;IP&#22320;&#22336;&#34987;&#20801;&#35768;&#30331;&#24405;&#12290;<\/p>\n<p><strong>&#26041;&#27861;&#20108;&#65306;&#20351;&#29992;<code>add_filter()<\/code>&#36807;&#28388;&#22120;<\/strong><\/p>\n<p>&#21019;&#24314;&#19968;&#20010;&#33258;&#23450;&#20041;&#36807;&#28388;&#22120;&#65292;&#22914;<code>login_attempts_filtered<\/code>&#65292;&#24182;&#28155;&#21152;&#20197;&#19979;&#20195;&#30721;&#65306;<\/p>\n<pre><code class=\"language-php\">function login_attempts_filtered($allowed, $ip) {\n    if ($allowed &amp;&amp; $ip == $_SERVER['REMOTE_ADDR']) {\n        \/\/ &#22914;&#26524;&#30331;&#24405;&#25104;&#21151;&#65292;&#20943;&#23569;&#22833;&#36133;&#27425;&#25968;\n        return false;\n    }\n    \/\/ &#21542;&#21017;&#65292;&#22686;&#21152;&#22833;&#36133;&#27425;&#25968;\n    return true;\n}\nadd_filter('login_attempts_allowed', 'login_attempts_filtered');<\/code><\/pre>\n<p><strong>&#26041;&#27861;&#19977;&#65306;&#20351;&#29992;<code>wp_login_time<\/code>&#21442;&#25968;<\/strong><\/p>\n<p>&#24744;&#21487;&#20197;&#20026;&#27599;&#20010;&#29992;&#25143;&#30340;&#30331;&#24405;&#26102;&#38388;&#35774;&#23450;&#19968;&#20010;&#38408;&#20540;&#65292;&#22914;&#26524;&#36229;&#36807;&#36825;&#20010;&#38408;&#20540;&#65292;&#21017;&#31105;&#27490;&#35813;&#29992;&#25143;&#20877;&#27425;&#30331;&#24405;&#12290;<\/p>\n<pre><code class=\"language-php\">$login_time = time() - get_option('login_time_threshold');\nif (isset($_POST['login'])) {\n    if ($_SESSION['time'] &lt; $login_time) {\n        wp_die(\"Too many failed logins in the last hour.\");\n    }\n    update_user_meta(get_current_user_id(), 'last_login', time());\n}<\/code><\/pre>\n<p>&#36825;&#37324;&#35774;&#32622;&#20102;&#19968;&#20010;&#38408;&#20540;&#65292;&#22914;&#26524;&#24403;&#21069;&#29992;&#25143;&#30331;&#24405;&#26102;&#38388;&#23567;&#20110;&#38408;&#20540;&#65292;&#21017;&#19981;&#20801;&#35768;&#20182;&#20204;&#20877;&#27425;&#30331;&#24405;&#12290;<\/p>\n<h3>2. &#20351;&#29992;&#22806;&#37096;&#25554;&#20214;<\/h3>\n<p>&#26377;&#35768;&#22810;&#25554;&#20214;&#21487;&#20197;&#24110;&#21161;&#24744;&#25511;&#21046;&#29992;&#25143;&#30331;&#24405;&#27425;&#25968;&#65292;&#20363;&#22914;&ldquo;Login Time Limit&rdquo;&#25110;&ldquo;Limit Login Attempts&rdquo;&#12290;<\/p>\n<p><strong>&#20363;&#23376;&#20195;&#30721;<\/strong><\/p>\n<p>&#20551;&#35774;&#24744;&#27491;&#22312;&#20351;&#29992;&ldquo;Limit Login Attempts&rdquo;&#25554;&#20214;&#65306;<\/p>\n<ul>\n<li>&#22312;&#25554;&#20214;&#30446;&#24405;&#19979;&#21019;&#24314;&#19968;&#20010;&#21517;&#20026;<code>functions.php<\/code>&#30340;&#26032;&#25991;&#20214;&#12290;<\/li>\n<li>&#28155;&#21152;&#20197;&#19979;&#20195;&#30721;&#65306;\n<pre><code class=\"language-php\">\/\/ Check if the user has more than one login attempt\nif (!empty($_GET['limit_login_attempts'])) {\nif ($_GET['limit_login_attempts'] &gt; 0) {\n    $max_attempts = intval($_GET['limit_login_attempts']);\n    $attempt_count = isset($_SESSION['attempts']) ? $_SESSION['attempts'] : 0;\n    if ($attempt_count &gt;= $max_attempts) {\n        echo \"You have reached your maximum number of attempts.\";\n        exit;\n    } else {\n        $_SESSION['attempts']++;\n    }\n} else {\n    echo \"Invalid limit value.\";\n    exit;\n}\n}<\/code><\/pre><\/li>\n<li>&#26356;&#26032;WordPress&#20027;&#39064;&#20197;&#21551;&#29992;&#25554;&#20214;&#65292;&#28982;&#21518;&#28608;&#27963;&#25554;&#20214;&#12290;<\/li>\n<\/ul>\n<h3>3. &#35774;&#32622;&#35775;&#38382;&#26435;&#38480;<\/h3>\n<p>&#38500;&#20102;&#19978;&#36848;&#26041;&#27861;&#22806;&#65292;&#36824;&#21487;&#20197;&#26681;&#25454;&#29992;&#25143;&#30340;&#35282;&#33394;&#25110;&#31649;&#29702;&#21592;&#26435;&#38480;&#35774;&#32622;&#19981;&#21516;&#30340;&#30331;&#24405;&#38480;&#21046;&#12290;<\/p>\n<h4>&#31034;&#20363;&#20195;&#30721;<\/h4>\n<p>&#21019;&#24314;&#19968;&#20010;&#26032;&#21151;&#33021;&#65292;&#29992;&#20110;&#26816;&#26597;&#29992;&#25143;&#26159;&#21542;&#20855;&#26377;&#29305;&#23450;&#35282;&#33394;&#65292;&#20197;&#20915;&#23450;&#20182;&#20204;&#30340;&#30331;&#24405;&#27425;&#25968;&#65306;<\/p>\n<pre><code class=\"language-php\">\/**\n * Checks if a user has the required role for certain actions.\n *\n * @param string $role The role to check against.\n * @return bool True if the user has the required role, false otherwise.\n *\/\nfunction has_required_role($role) {\n    global $current_user;\n\n    \/\/ Replace with actual logic to determine if user is allowed to use this function\n    return in_array($role, array('admin', 'editor'));\n}\n\n\/\/ Example usage:\nif (has_required_role('admin')) {\n    \/\/ Do something only when user has admin role\n} else {\n    \/\/ Only do something when user has editor role\n}<\/code><\/pre>\n<p>&#36890;&#36807;&#20197;&#19978;&#26041;&#27861;&#65292;&#24744;&#21487;&#20197;&#26377;&#25928;&#22320;&#38480;&#21046;WordPress&#19978;&#30340;&#30331;&#24405;&#27425;&#25968;&#65292;&#30830;&#20445;&#21482;&#26377;&#25480;&#26435;&#30340;&#29992;&#25143;&#25165;&#33021;&#30331;&#24405;&#21040;&#24744;&#30340;&#32593;&#31449;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312;WordPress&#32593;&#31449;&#19978;&#38480;&#21046;&#29992;&#25143;&#30331;&#24405;&#27425;&#25968;&#21487;&#20197;&#38450;&#038;#2..<\/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":[2107,2106],"tuisongtax":[],"class_list":["post-3281","post","type-post","status-publish","format-standard","hentry","category-wpdt","tag-cjyy","tag-cjzn"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/3281","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=3281"}],"version-history":[{"count":0,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/3281\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=3281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/categories?post=3281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=3281"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=3281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}