add_node(array(
"id" => "antispam-plugin",
"title" => "Antispam:",
"parent" => "comments",
));
$wp_admin_bar->add_node(array(
"id" => "antispam-plugin-counter",
"title" => get_option('spams_detected', 0) . ' rejected',
"parent" => "antispam-plugin",
));
$wp_admin_bar->add_node(array(
'id' => 'antispam-github',
'href' => 'https://github.com/EugenBobrowski/antispam/issues',
"title" => 'Create Issue on GitHub',
"parent" => "antispam-plugin",
));
}
public function style()
{
?>
nonce = hash('md5', ABSPATH);
$this->localize_object = 'veritas';
$this->fields = apply_filters('antispam_fields', array(
//field name
'comment' => array(
//protect method (replace | add )
'method' => 'add',
//parent to copy and hide
'parent' => '.comment-form-comment',
),
));
foreach ($this->fields as $name => $settings) {
$this->fields[$name]['ha'] = hash('md5', ABSPATH . $name);
}
add_filter('init', array($this, 'verify_spam'));
add_action('wp_print_scripts', array($this, 'localize'));
add_filter('print_footer_scripts', array($this, 'javascript'));
return true;
}
public static function get_instance()
{
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
public function add_real_comment_field($comment_fields)
{
$real_field = str_replace('comment', $this->nonce, $comment_fields['comment']);
$comment_fields['comment'] = $comment_fields['comment'] . $real_field;
return $comment_fields;
}
public function localize()
{
wp_enqueue_script('jquery');
wp_localize_script('jquery', $this->localize_object, $this->fields);
}
public function javascript()
{
wp_enqueue_script('jquery');
ob_start();
?>
' a',
// ' veritas' => ' v',
'key' => 'k',
'$parent' => 'p',
'$clone' => 'c',
);
$js = str_replace(array_keys($x), $x, $js);
echo($js);
}
public function verify_spam($commentdata)
{
foreach ($this->fields as $name => $field) {
if (
('replace' == $field['method'] && isset($_POST['comment']) && !isset($_POST[$field['ha']]))
||
('add' == $field['method'] && !empty($_POST['comment']))
) {
$this->die_die_die();
} elseif (isset($_POST[$field['ha']])) {
$_POST['comment'] = $_POST[$field['ha']];
}
}
return $commentdata;
}
public function die_die_die()
{
$spam_detected = get_option('spams_detected', 0);
$spam_detected++;
update_option('spams_detected', $spam_detected);
wp_die(__('Sorry, comments for bots are closed.'));
}
}
Antispam::get_instance();
}