56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?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 );
|