{"id":232335,"date":"2023-01-20T14:37:00","date_gmt":"2023-01-20T11:37:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232335"},"modified":"2023-01-29T10:36:31","modified_gmt":"2023-01-29T07:36:31","slug":"najkrashhe-efektivne-antispamove-vijavlennja-kodu-php-dlja-wordpress","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/uk\/najkrashhe-efektivne-antispamove-vijavlennja-kodu-php-dlja-wordpress\/","title":{"rendered":"\u041d\u0430\u0439\u043a\u0440\u0430\u0449\u0435 \u0435\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435 \u0430\u043d\u0442\u0438\u0441\u043f\u0430\u043c\u043e\u0432\u0435 \u0432\u0438\u044f\u0432\u043b\u0435\u043d\u043d\u044f \u043a\u043e\u0434\u0443 PHP \u0434\u043b\u044f WordPress"},"content":{"rendered":"\n<p>\u0411\u043b\u043e\u0433 WordPress \u043c\u043e\u0436\u0435 \u043e\u0442\u0440\u0438\u043c\u0443\u0432\u0430\u0442\u0438 \u0431\u0456\u043b\u044c\u0448\u0435 100 \u0441\u043f\u0430\u043c-\u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0456\u0432 (\u0441\u0442\u0432\u043e\u0440\u0435\u043d\u0438\u0445 \u0441\u043f\u0430\u043c-\u0440\u043e\u0431\u043e\u0442\u0430\u043c\u0438) \u043d\u0430 \u0434\u0435\u043d\u044c, \u0449\u043e \u0434\u0440\u0430\u0442\u0443\u0454.<\/p>\n<p><a href=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-156584-61e5bfcecc6e1.jpg\" data-rel=\"lightbox\"><img decoding=\"async\" class=\"SDStudio-light-box-enable SDStudio-editor-tools-md-imp\" src=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-156584-61e5bfcecc6e1.jpg\" alt=\"\u041d\u0430\u0439\u043a\u0440\u0430\u0449\u0435 \u0435\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435 \u0430\u043d\u0442\u0438\u0441\u043f\u0430\u043c\u043e\u0432\u0435 \u0432\u0438\u044f\u0432\u043b\u0435\u043d\u043d\u044f \u043a\u043e\u0434\u0443 PHP \u0434\u043b\u044f Wordpress\"><\/a><\/p>\n<p>wordpress-\u0441\u043f\u0430\u043c<\/p>\n<p>\u042f\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0432\u043e\u043d\u0438 \u043c\u043e\u0436\u0443\u0442\u044c \u0431\u0443\u0442\u0438 \u043e\u0442\u0440\u0438\u043c\u0430\u043d\u0456 \u043f\u043b\u0430\u0433\u0456\u043d\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438 \u044f\u043a Akismet, \u043e\u0434\u043d\u0430\u043a \u0446\u0456 \u0434\u0430\u043d\u0456 \u0432\u0441\u0435 \u0449\u0435 \u0437\u0431\u0435\u0440\u0456\u0433\u0430\u044e\u0442\u044c\u0441\u044f \u0432 \u0431\u0430\u0437\u0456 \u0434\u0430\u043d\u0438\u0445 \u0434\u043e \u0442\u043e\u0433\u043e, \u044f\u043a \u0457\u0445 \u0431\u0443\u0434\u0435 <a href=\"https:\/\/wordpress.mediadoma.com\/uk\/skorochennja-vikoristannja-bazi-danih-wordpress\/\" title=\"\u0432\u0438\u0434\u0430\u043b\u0435\u043d\u043e\">\u0432\u0438\u0434\u0430\u043b\u0435\u043d\u043e<\/a> \u0432\u0440\u0443\u0447\u043d\u0443 \u0430\u0431\u043e \u043f\u0456\u0441\u043b\u044f <a href=\"https:\/\/wordpress.mediadoma.com\/uk\/jak-nalashtuvati-scenarij-php-u-crontab-dlja-ochishhennja-kilkoh-wordpress-baz-danih-na-odnomu-serveri\/\" title=\"\u0437\u0430\u043a\u0456\u043d\u0447\u0435\u043d\u043d\u044f \u0442\u0435\u0440\u043c\u0456\u043d\u0443 \u0434\u0456\u0457\">\u0437\u0430\u043a\u0456\u043d\u0447\u0435\u043d\u043d\u044f \u0442\u0435\u0440\u043c\u0456\u043d\u0443 \u0434\u0456\u0457<\/a>.<\/p>\n<p><a href=\"https:\/\/leonax.net\/p\/6732\/block-spam-comments-from-web-page\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">LEONA<\/a> \u043f\u0440\u043e\u043f\u043e\u043d\u0443\u0454 \u0440\u043e\u0437\u0443\u043c\u043d\u0435 \u0440\u0456\u0448\u0435\u043d\u043d\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u0431\u0456\u0433\u0430\u043d\u043d\u044f \u043f\u043e\u0442\u0440\u0430\u043f\u043b\u044f\u043d\u043d\u044e \u0441\u043f\u0430\u043c-\u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0456\u0432 \u043d\u0430\u0432\u0456\u0442\u044c \u0443 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u0438\u0445. \u0412\u0456\u043d \u0437\u0430\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0439 \u043d\u0430 \u0440\u043e\u0437\u043c\u0456\u0449\u0435\u043d\u043d\u0456 \u043f\u0440\u0438\u0445\u043e\u0432\u0430\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0443 \u0444\u043e\u0440\u043c\u0456 \u0442\u0430 \u0432\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0456 \u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044f, \u043a\u043e\u043b\u0438 \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447 \u043d\u0430\u0442\u0438\u0441\u043a\u0430\u0454 \u043a\u043b\u0430\u0432\u0456\u0448\u0443 (onkeyup). \u041e\u0442\u0436\u0435, \u044f\u043a\u0449\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044f \u043d\u0435 \u0437\u0431\u0456\u0433\u0430\u044e\u0442\u044c\u0441\u044f, \u043c\u0438 \u0432\u0432\u0430\u0436\u0430\u0454\u043c\u043e, \u0449\u043e \u0446\u0435 \u043d\u0435 \u043d\u0430\u0434\u0456\u0441\u043b\u0430\u043d\u043e \u043b\u044e\u0434\u0438\u043d\u043e\u044e.<\/p>\n<p>wordpress \u043d\u0430\u0434\u0430\u0454 \u0444\u0456\u043b\u044c\u0442\u0440 <strong>preprocess_comment<\/strong>, \u0442\u043e\u043c\u0443 \u0432\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0432\u0456\u0440\u0438\u0442\u0438 \u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0456 \u0442\u0430 \u0432\u0438\u0439\u0442\u0438 \u0437\u0456 \u0441\u0442\u043e\u0440\u0456\u043d\u043a\u0438 \u0437\u0430 \u0434\u043e\u043f\u043e\u043c\u043e\u0433\u043e\u044e <strong>wp_die()<\/strong> \u0440\u0430\u043d\u0456\u0448\u0435.<\/p>\n<p>\u041e\u0444\u0456\u0446\u0456\u0439\u043d\u0438\u0439 API WP \u043f\u043e\u0432\u0456\u0434\u043e\u043c\u043b\u044f\u0454 (<a href=\"https:\/\/codex.wordpress.org\/Plugin_API\/Filter_Reference\/preprocess_comment\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">https:\/\/codex.wordpress.org\/Plugin_API\/Filter_Reference\/preprocess_comment<\/a> ), $commentdata \u043c\u0456\u0441\u0442\u0438\u0442\u044c \u0442\u0430\u043a\u0443 \u0456\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0456\u044e:<\/p>\n<pre><code>'comment_post_ID' \u00a0 \u00a0 \u00a0- The post to which the comment will apply\n\u00a0 \u00a0'comment_author' \u00a0 \u00a0 \u00a0 - (may be empty)\n\u00a0 \u00a0'comment_author_email' - (may be empty)\n\u00a0 \u00a0'comment_author_url' \u00a0 - (may be empty)\n\u00a0 \u00a0'comment_content' \u00a0 \u00a0 \u00a0- The text of the proposed comment\n\u00a0 \u00a0'comment_type' \u00a0 \u00a0 \u00a0 \u00a0 - 'pingback', 'trackback', or empty for regular comments\n\u00a0 \u00a0'user_ID' \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0- (empty if not logged in)<\/code><\/pre>\n<p>\u041f\u043e\u0442\u0456\u043c \u043c\u0438 \u043c\u043e\u0436\u0435\u043c\u043e \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u0432\u0430\u0442\u0438 \u0446\u0435\u0439 \u043f\u043b\u0430\u0433\u0456\u043d, \u0449\u043e\u0431 \u0434\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u0438 pingback\/trackback (\u0449\u043e, \u043d\u0430 \u043c\u043e\u044e \u0434\u0443\u043c\u043a\u0443, \u043a\u043e\u0440\u0438\u0441\u043d\u043e) \u0456 \u0435\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u0437\u0431\u0443\u0442\u0438\u0441\u044f \u0441\u043f\u0430\u043c-\u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0440\u0456\u0432.<\/p>\n<pre><code>$leonax_magic_lower = 328;\n$leonax_magic_upper = 3450709;\n\u00a0\nfunction leonax_anti_spam_form($fields){\n\u00a0 \u00a0 global $leonax_magic_lower, $leonax_magic_upper;\n\u00a0 \u00a0 $leonax_magic = mt_rand($leonax_magic_lower, $leonax_magic_upper);\n\u00a0 \u00a0 $fields['leonax_magic'] = &lt;&lt;&lt;EOT\n\u00a0 \u00a0 \u00a0 \u00a0 &lt;input type=\"hidden\" id=\"leonax-magic\" name=\"leonax-magic\" value=\"0\"&gt;\n\u00a0 \u00a0 \u00a0 \u00a0 &lt;script type=\"text\/javascript\"&gt;\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 jQuery(function() {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 jQuery(\"#comment\").on(\"keyup\", function() {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 jQuery(\"#leonax-magic\").val(\"$leonax_magic\");\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 });\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 })\n\u00a0 \u00a0 \u00a0 \u00a0 &lt;\/script&gt;\nEOT;\n\u00a0 \u00a0 return $fields;\n}\n\u00a0\nadd_filter('comment_form_default_fields', 'leonax_anti_spam_form');\n\u00a0\nfunction leonax_anit_spam_caught() {\n\u00a0 wp_die('&lt;strong&gt;ERROR&lt;\/strong&gt;: Looks like you are a spam bot. Please stop doing this.');\n}\n\u00a0\nfunction leonax_anti_spam_check( $commentdata) {\n\u00a0 $comment_type = '';\n\u00a0 if (isset($commentdata['comment_type'])) {\n\u00a0 \u00a0 $comment_type = trim($commentdata['comment_type']);\n\u00a0 } \u00a0 \n\u00a0 \n\u00a0if (($comment_type == 'pingback') || ($comment_type == 'trackback')) {\n\u00a0 \u00a0 return $commentdata;\n\u00a0 }\n\u00a0 $content = '';\n\u00a0 if (isset($commentdata['comment_content'])) {\n\u00a0 \u00a0 $content = trim($commentdata['comment_content']);\n\u00a0 } \u00a0 \n\u00a0 if (!strlen($content)) {\n\u00a0 \u00a0 leonax_anit_spam_caught();\n\u00a0 }\n\u00a0 \n\u00a0 if (preg_match(\"\/[a-e0-9]{25,}\/i\", $content)) { \/\/ To capture the strange IDs\n\u00a0 \u00a0 leonax_anit_spam_caught(); \u00a0\n\u00a0 }\n\u00a0\n\u00a0 global $leonax_magic_lower, $leonax_magic_upper; \u00a0\n\u00a0 \n\u00a0 if (isset($commentdata['user_ID']) &amp;&amp; $commentdata['user_ID']) { \/\/ Login-users are not bad\n\u00a0 \u00a0 return $commentdata;\n\u00a0 }\n\u00a0 \n\u00a0 if (!isset($_POST['leonax-magic'])) {\n\u00a0 \u00a0 leonax_anit_spam_caught();\n\u00a0 }\n\u00a0 $magic = intval($_POST['leonax-magic']);\n\u00a0 if ($magic &lt; $leonax_magic_lower || $magic &gt; $leonax_magic_upper) {\n\u00a0 \u00a0 leonax_anit_spam_caught();\n\u00a0 }\n\u00a0 return $commentdata;\n}\n\u00a0\nadd_filter( 'preprocess_comment', 'leonax_anti_spam_check' );<\/code><\/pre>\n<p>\u042f\u043a\u0449\u043e \u043c\u0438 \u043f\u0435\u0440\u0435\u0432\u0456\u0440\u0438\u043c\u043e \u0444\u0443\u043d\u043a\u0446\u0456\u044e\/\u0444\u0456\u043b\u044c\u0442\u0440, \u043d\u0430\u0432\u043c\u0438\u0441\u043d\u043e \u0432\u0432\u0456\u0432\u0448\u0438 \u0434\u0438\u0432\u043d\u0456 \u0456\u0434\u0435\u043d\u0442\u0438\u0444\u0456\u043a\u0430\u0442\u043e\u0440\u0438, \u043c\u0438 \u043e\u0442\u0440\u0438\u043c\u0430\u0454\u043c\u043e \u043d\u0430\u0441\u0442\u0443\u043f\u043d\u0435 (\u0456 \u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0440 \u043d\u0435 \u0431\u0443\u0434\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u043e \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043e\u0447\u0456\u043a\u0443\u0432\u0430\u043d\u043d\u044f).<\/p>\n<p>\u041f\u0440\u0438\u043c\u0456\u0442\u043a\u0430. \u0420\u043e\u0437\u043c\u0456\u0441\u0442\u0456\u0442\u044c \u043d\u0430\u0432\u0435\u0434\u0435\u043d\u0438\u0439 \u0432\u0438\u0449\u0435 \u043a\u043e\u0434 \u0443 \u043a\u0456\u043d\u0446\u0456 \u0448\u0430\u0431\u043b\u043e\u043d\u0443 <strong>functions.php<\/strong> (\u0430\u0431\u043e \u0434\u043e\u0447\u0456\u0440\u043d\u044c\u043e\u0457 \u0442\u0435\u043c\u0438).<\/p>\n<p><a href=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-156584-61e5bfd03126a.jpg\" data-rel=\"lightbox\"><img decoding=\"async\" class=\"SDStudio-light-box-enable SDStudio-editor-tools-md-imp\" src=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-156584-61e5bfd03126a.jpg\" alt=\"\u041d\u0430\u0439\u043a\u0440\u0430\u0449\u0435 \u0435\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435 \u0430\u043d\u0442\u0438\u0441\u043f\u0430\u043c\u043e\u0432\u0435 \u0432\u0438\u044f\u0432\u043b\u0435\u043d\u043d\u044f \u043a\u043e\u0434\u0443 PHP \u0434\u043b\u044f Wordpress\"><\/a><\/p>\n<p>wordpress-\u0441\u043f\u0430\u043c-\u0432\u0438\u044f\u0432\u043b\u0435\u043d\u043d\u044f<\/p>\n<p>\u0426\u0435 \u043f\u0440\u0430\u0446\u044e\u0454 \u044f\u043a \u043c\u0430\u0433\u0456\u044f!<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">\u0414\u0436\u0435\u0440\u0435\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0443:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041d\u0430\u0439\u043a\u0440\u0430\u0449\u0435 \u0435\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435 \u0432\u0438\u044f\u0432\u043b\u0435\u043d\u043d\u044f PHP-\u043a\u043e\u0434\u0443 \u0434\u043b\u044f \u0437\u0430\u0445\u0438\u0441\u0442\u0443 \u0432\u0456\u0434 \u0441\u043f\u0430\u043c\u0443 \u0434\u043b\u044f WordPress<\/p>\n","protected":false},"author":1,"featured_media":223984,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[808,869,1035,849,725],"tags":[1174],"class_list":["post-232335","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-10","category-wordpress-10","category-bezpeka","category-pidruchnyky","category-rozrobnyk","tag-affiai-uk"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/232335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/comments?post=232335"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/232335\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media\/223984"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media?parent=232335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/categories?post=232335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/tags?post=232335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}