Arakava: MU-Plugin blockiert Kommentare mit shorturl.fm (Spam, Filter erweiterbar).
This commit is contained in:
parent
97c2dae082
commit
25c58b0147
1 changed files with 56 additions and 0 deletions
56
arakava-news/mu-plugins/arakava-comment-spam-guard.php
Normal file
56
arakava-news/mu-plugins/arakava-comment-spam-guard.php
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Plugin Name: Arakava Comment Spam Guard (MU)
|
||||||
|
* Description: Markiert Kommentare mit blockierten Kurz-URL-Hosts als Spam (Standard: shorturl.fm). Erweiterbar per Filter arakava_spam_guard_blocked_hosts.
|
||||||
|
* Version: 1.0.0
|
||||||
|
* Author: Homelab / Arakava
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|int $approved Vorläufiger Freigabe-Status.
|
||||||
|
* @param array $commentdata Rohdaten vor dem Speichern.
|
||||||
|
* @return string|int
|
||||||
|
*/
|
||||||
|
function arakava_spam_guard_pre_comment_approved( $approved, $commentdata ) {
|
||||||
|
if ( is_string( $approved ) && 'spam' === $approved ) {
|
||||||
|
return $approved;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hosts = apply_filters(
|
||||||
|
'arakava_spam_guard_blocked_hosts',
|
||||||
|
array(
|
||||||
|
'shorturl.fm',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( empty( $hosts ) || ! is_array( $hosts ) ) {
|
||||||
|
return $approved;
|
||||||
|
}
|
||||||
|
|
||||||
|
$parts = array();
|
||||||
|
if ( ! empty( $commentdata['comment_content'] ) && is_string( $commentdata['comment_content'] ) ) {
|
||||||
|
$parts[] = $commentdata['comment_content'];
|
||||||
|
}
|
||||||
|
if ( ! empty( $commentdata['comment_author_url'] ) && is_string( $commentdata['comment_author_url'] ) ) {
|
||||||
|
$parts[] = $commentdata['comment_author_url'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$blob = strtolower( implode( ' ', $parts ) );
|
||||||
|
|
||||||
|
foreach ( $hosts as $host ) {
|
||||||
|
$host = strtolower( trim( (string) $host ) );
|
||||||
|
if ( '' === $host ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( false !== strpos( $blob, $host ) ) {
|
||||||
|
return 'spam';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $approved;
|
||||||
|
}
|
||||||
|
add_filter( 'pre_comment_approved', 'arakava_spam_guard_pre_comment_approved', 5, 2 );
|
||||||
Loading…
Add table
Reference in a new issue