{"id":32902,"date":"2024-11-25T11:33:23","date_gmt":"2024-11-25T03:33:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32902\/"},"modified":"2024-11-25T11:33:23","modified_gmt":"2024-11-25T03:33:23","slug":"%e5%a6%82%e4%bd%95%e4%b8%bawordpress%e6%8f%92%e4%bb%b6%e6%b7%bb%e5%8a%a0%e9%98%b2%e6%ad%a2%e5%9e%83%e5%9c%be%e8%af%84%e8%ae%ba%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32902\/","title":{"rendered":"\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u9632\u6b62\u5783\u573e\u8bc4\u8bba\u529f\u80fd"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169397110629428.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u9632\u6b62\u5783\u573e\u8bc4\u8bba\u529f\u80fd\u63d2\u56fe\" alt=\"\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u9632\u6b62\u5783\u573e\u8bc4\u8bba\u529f\u80fd\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u9632\u6b62\u5783\u573e\u8bc4\u8bba\u529f\u80fd<\/p>\n<p>\u5728\u4f7f\u7528WordPress\u5efa\u7acb\u7f51\u7ad9\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9047\u5230\u5783\u573e\u8bc4\u8bba\u7684\u95ee\u9898\u3002\u5783\u573e\u8bc4\u8bba\u4e0d\u4ec5\u4f1a\u5360\u7528\u6570\u636e\u5e93\u7a7a\u95f4\uff0c\u800c\u4e14\u8fd8\u4f1a\u5bf9\u6211\u4eec\u7684\u7f51\u7ad9\u58f0\u8a89\u9020\u6210\u8d1f\u9762\u5f71\u54cd\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u9632\u6b62\u5783\u573e\u8bc4\u8bba\u7684\u529f\u80fd\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e00\u79cd\u7b80\u5355\u800c\u6709\u6548\u7684\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\u6765\u8fc7\u6ee4\u8bc4\u8bba\u3002\u5728WordPress\u4e2d\uff0c\u6709\u4e00\u4e2a\u540d\u4e3apre_comment_approved\u7684\u94a9\u5b50\u51fd\u6570\uff0c\u53ef\u4ee5\u7528\u4e8e\u5728\u8bc4\u8bba\u88ab\u4fdd\u5b58\u5230\u6570\u636e\u5e93\u4e4b\u524d\u5bf9\u5176\u8fdb\u884c\u8fc7\u6ee4\u3002\u901a\u8fc7\u8fd9\u4e2a\u94a9\u5b50\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u903b\u8f91\u6765\u5224\u65ad\u8bc4\u8bba\u662f\u5426\u4e3a\u5783\u573e\u8bc4\u8bba\uff0c\u5e76\u8bbe\u7f6e\u76f8\u5e94\u7684\u72b6\u6001\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u51fd\u6570\uff0c\u5728\u8bc4\u8bba\u4fdd\u5b58\u4e4b\u524d\u5224\u65ad\u662f\u5426\u4e3a\u5783\u573e\u8bc4\u8bba\uff0c\u5e76\u8bbe\u7f6e\u72b6\u6001\u4e3a\u5f85\u5ba1\u6838\uff1a<\/p>\n<pre>function filter_comment( $approved, $commentdata ) {\n    \/\/ \u5224\u65ad\u8bc4\u8bba\u662f\u5426\u4e3a\u5783\u573e\u8bc4\u8bba\u7684\u903b\u8f91\n    if ( your_spam_detection_logic() ) {\n        $approved = '0'; \/\/ \u8bbe\u7f6e\u72b6\u6001\u4e3a\u5f85\u5ba1\u6838\n    }\n    return $approved;\n}\nadd_filter( 'pre_comment_approved', 'filter_comment', 10, 2 );<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u8c03\u7528your_spam_detection_logic()\u51fd\u6570\u6765\u5224\u65ad\u8bc4\u8bba\u662f\u5426\u4e3a\u5783\u573e\u8bc4\u8bba\u3002\u8fd9\u4e2a\u51fd\u6570\u9700\u8981\u6839\u636e\u5b9e\u9645\u9700\u6c42\u6765\u7f16\u5199\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5e38\u89c1\u7684\u5783\u573e\u8bc4\u8bba\u7279\u5f81\uff0c\u6bd4\u5982\u94fe\u63a5\u6570\u91cf\u3001\u654f\u611f\u8bcd\u6c47\u3001\u91cd\u590d\u5185\u5bb9\u7b49\u7b49\u3002\u5982\u679c\u8bc4\u8bba\u88ab\u5224\u5b9a\u4e3a\u5783\u573e\u8bc4\u8bba\uff0c\u6211\u4eec\u5c06\u72b6\u6001\u8bbe\u7f6e\u4e3a\u5f85\u5ba1\u6838\uff08\u5373$approved = &#8216;0&#8217;\uff09\u3002<\/p>\n<p>\u4e3a\u4e86\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u6211\u4eec\u9700\u8981\u5c06\u4ee3\u7801\u6dfb\u52a0\u5230\u81ea\u5df1\u7684\u63d2\u4ef6\u6587\u4ef6\u4e2d\uff0c\u6216\u8005\u4f7f\u7528\u4e00\u4e2a\u81ea\u5b9a\u4e49\u529f\u80fd\u63d2\u4ef6\u3002\u5c06\u4e0a\u8ff0\u4ee3\u7801\u6dfb\u52a0\u5230\u63d2\u4ef6\u6587\u4ef6\u4e2d\u540e\uff0cWordPress\u5c06\u4f1a\u5728\u8bc4\u8bba\u4fdd\u5b58\u4e4b\u524d\uff0c\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\u6765\u8fc7\u6ee4\u8bc4\u8bba\u3002<\/p>\n<p>\u9664\u4e86\u8fc7\u6ee4\u8bc4\u8bba\uff0c\u8fd8\u53ef\u4ee5\u6dfb\u52a0\u5176\u4ed6\u7684\u5783\u573e\u8bc4\u8bba\u9632\u62a4\u63aa\u65bd\u3002\u6bd4\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528Google reCAPTCHA\u6765\u6dfb\u52a0\u9a8c\u8bc1\u7801\u9a8c\u8bc1\u529f\u80fd\u3002\u4e0b\u9762\u662f\u4e00\u6bb5\u5b9e\u73b0Google reCAPTCHA\u529f\u80fd\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>function add_recaptcha_to_comment_form() {\n    if ( your_recaptcha_verification_logic() ) {\n        \/\/ \u663e\u793aGoogle reCAPTCHA\n        echo '&lt;div class=\"g-recaptcha\" data-sitekey=\"your_recaptcha_site_key\"&gt;&lt;\/div&gt;';\n    }\n}\nadd_action( 'comment_form_after_fields', 'add_recaptcha_to_comment_form' );\n\nfunction verify_recaptcha( $approved, $commentdata ) {\n    \/\/ \u9a8c\u8bc1Google reCAPTCHA\n    if ( your_recaptcha_verification_logic() ) {\n        $response = $_POST['g-recaptcha-response'];\n        $recaptcha_secret_key = 'your_recaptcha_secret_key';\n        $verify_url = 'https:\/\/www.google.com\/recaptcha\/api\/siteverify';\n        $data = array(\n            'secret' =&amp;gt; $recaptcha_secret_key,\n            'response' =&amp;gt; $response\n        );\n        $options = array(\n            'http' =&amp;gt; array(\n                'method' =&amp;gt; 'POST',\n                'header' =&amp;gt; \"Content-Type: application\/x-www-form-urlencoded\n\",\n                'content' =&amp;gt; http_build_query( $data )\n            )\n        );\n        $context = stream_context_create( $options );\n        $result = file_get_contents( $verify_url, false, $context );\n        $result = json_decode( $result );\n        if ( ! $result-&amp;gt;success ) {\n            wp_die( 'reCAPTCHA\u9a8c\u8bc1\u5931\u8d25\uff0c\u8bf7\u91cd\u65b0\u586b\u5199\u3002' );\n        }\n    }\n    return $approved;\n}\nadd_filter( 'pre_comment_approved', 'verify_recaptcha', 10, 2 );<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5728\u8bc4\u8bba\u8868\u5355\u540e\u6dfb\u52a0\u4e86Google reCAPTCHA\u3002\u901a\u8fc7\u8c03\u7528your_recaptcha_verification_logic()\u51fd\u6570\u6765\u5224\u65ad\u662f\u5426\u9700\u8981\u663e\u793a\u9a8c\u8bc1\u7801\u3002\u5982\u679c\u9700\u8981\u663e\u793a\u9a8c\u8bc1\u7801\uff0c\u5728\u8bc4\u8bba\u88ab\u4fdd\u5b58\u4e4b\u524d\uff0c\u6211\u4eec\u5bf9\u9a8c\u8bc1\u7801\u8fdb\u884c\u9a8c\u8bc1\uff0c\u786e\u4fdd\u8bc4\u8bba\u6765\u81ea\u771f\u5b9e\u7528\u6237\u3002<\/p>\n<p>\u4ee5\u4e0a\u662f\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u9632\u6b62\u5783\u573e\u8bc4\u8bba\u529f\u80fd\u7684\u4e00\u79cd\u65b9\u6cd5\u3002\u901a\u8fc7\u81ea\u5b9a\u4e49\u51fd\u6570\u548c\u8fc7\u6ee4\u94a9\u5b50\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u6765\u5224\u65ad\u548c\u5904\u7406\u5783\u573e\u8bc4\u8bba\u3002\u540c\u65f6\uff0c\u901a\u8fc7\u5f15\u5165Google reCAPTCHA\u7b49\u9a8c\u8bc1\u673a\u5236\uff0c\u8fd8\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u9ad8\u8bc4\u8bba\u7684\u5b89\u5168\u6027\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u9632\u6b62\u5783\u573e\u8bc4\u8bba\u529f\u80fd\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u9632\u6b62\u5783\u573e\u8bc4\u8bba\u529f\u80fd \u5728\u4f7f\u7528WordPress\u5efa\u7acb\u7f51\u7ad9\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9047\u5230\u5783\u573e\u8bc4\u8bba\u7684\u95ee\u9898\u3002\u5783\u573e\u8bc4\u8bba\u4e0d\u4ec5\u4f1a\u5360\u7528\u6570\u636e\u5e93\u7a7a\u95f4\uff0c\u800c\u4e14\u8fd8\u4f1a\u5bf9\u6211\u4eec\u7684\u7f51\u7ad9\u58f0\u8a89\u9020\u6210\u8d1f\u9762\u5f71\u54cd\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u9632\u6b62\u5783\u573e\u8bc4\u8bba\u7684\u529f\u80fd\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e00\u79cd\u7b80\u5355\u800c\u6709\u6548\u7684\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\u6765\u8fc7\u6ee4\u8bc4\u8bba\u3002\u5728WordPress\u4e2d\uff0c\u6709\u4e00\u4e2a\u540d\u4e3apre_comment_approved\u7684\u94a9\u5b50\u51fd\u6570\uff0c\u53ef\u4ee5\u7528\u4e8e\u5728\u8bc4\u8bba\u88ab\u4fdd\u5b58\u5230\u6570\u636e\u5e93\u4e4b\u524d\u5bf9\u5176\u8fdb\u884c\u8fc7\u6ee4\u3002\u901a\u8fc7\u8fd9\u4e2a\u94a9\u5b50\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u903b\u8f91\u6765\u5224\u65ad\u8bc4\u8bba\u662f\u5426\u4e3a\u5783\u573e\u8bc4\u8bba\uff0c\u5e76\u8bbe\u7f6e\u76f8\u5e94\u7684\u72b6\u6001\u3002 \u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u51fd\u6570\uff0c\u5728\u8bc4\u8bba\u4fdd\u5b58\u4e4b\u524d\u5224\u65ad\u662f\u5426\u4e3a\u5783\u573e\u8bc4\u8bba\uff0c\u5e76\u8bbe\u7f6e\u72b6\u6001\u4e3a\u5f85\u5ba1\u6838\uff1a function filter_comment( $approved, $commentdata ) { \/\/ \u5224\u65ad\u8bc4\u8bba\u662f\u5426\u4e3a\u5783\u573e\u8bc4\u8bba\u7684\u903b\u8f91 if ( your_spam_detection_logic() ) { $approved = &#8216;0&#8217;; \/\/ \u8bbe\u7f6e\u72b6\u6001\u4e3a\u5f85\u5ba1\u6838 } return $approved; } add_filter( &#8216;pre_comment_approved&#8217;, &#8216;filter_comment&#8217;, 10, 2 ); \u767b\u5f55\u540e\u590d\u5236 \u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u8c03\u7528your_spam_detection_logic()\u51fd\u6570\u6765\u5224\u65ad\u8bc4\u8bba\u662f\u5426\u4e3a\u5783\u573e\u8bc4\u8bba\u3002\u8fd9\u4e2a\u51fd\u6570\u9700\u8981\u6839\u636e\u5b9e\u9645\u9700\u6c42\u6765\u7f16\u5199\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5e38\u89c1\u7684\u5783\u573e\u8bc4\u8bba\u7279\u5f81\uff0c\u6bd4\u5982\u94fe\u63a5\u6570\u91cf\u3001\u654f\u611f\u8bcd\u6c47\u3001\u91cd\u590d\u5185\u5bb9\u7b49\u7b49\u3002\u5982\u679c\u8bc4\u8bba\u88ab\u5224\u5b9a\u4e3a\u5783\u573e\u8bc4\u8bba\uff0c\u6211\u4eec\u5c06\u72b6\u6001\u8bbe\u7f6e\u4e3a\u5f85\u5ba1\u6838\uff08\u5373$approved = &#8216;0&#8217;\uff09\u3002 \u4e3a\u4e86\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u6211\u4eec\u9700\u8981\u5c06\u4ee3\u7801\u6dfb\u52a0\u5230\u81ea\u5df1\u7684\u63d2\u4ef6\u6587\u4ef6\u4e2d\uff0c\u6216\u8005\u4f7f\u7528\u4e00\u4e2a\u81ea\u5b9a\u4e49\u529f\u80fd\u63d2\u4ef6\u3002\u5c06\u4e0a\u8ff0\u4ee3\u7801\u6dfb\u52a0\u5230\u63d2\u4ef6\u6587\u4ef6\u4e2d\u540e\uff0cWordPress\u5c06\u4f1a\u5728\u8bc4\u8bba\u4fdd\u5b58\u4e4b\u524d\uff0c\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\u6765\u8fc7\u6ee4\u8bc4\u8bba\u3002 \u9664\u4e86\u8fc7\u6ee4\u8bc4\u8bba\uff0c\u8fd8\u53ef\u4ee5\u6dfb\u52a0\u5176\u4ed6\u7684\u5783\u573e\u8bc4\u8bba\u9632\u62a4\u63aa\u65bd\u3002\u6bd4\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528Google reCAPTCHA\u6765\u6dfb\u52a0\u9a8c\u8bc1\u7801\u9a8c\u8bc1\u529f\u80fd\u3002\u4e0b\u9762\u662f\u4e00\u6bb5\u5b9e\u73b0Google reCAPTCHA\u529f\u80fd\u7684\u793a\u4f8b\u4ee3\u7801\uff1a function add_recaptcha_to_comment_form() { if ( your_recaptcha_verification_logic() ) { \/\/ \u663e\u793aGoogle reCAPTCHA echo &#8216;&lt;div class=&#8221;g-recaptcha&#8221; data-sitekey=&#8221;your_recaptcha_site_key&#8221;&gt;&lt;\/div&gt;&#8217;; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-32902","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=32902"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32902\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}