<?php
/*
Plugin Name: فیلتر لینکها در کامنت
Plugin URI: http://wordpress.org/plugins/hello-dolly/
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page.
Author: hiwa bayazidi
Version: 1.0.0
Author URI: http://ma.tt/
*/
define('PLAGIN_PATH', plugin_dir_url(__FILE__));
define('ASSET_PATH', PLAGIN_PATH . 'assets/');
define('_INC_PATH', PLAGIN_PATH . '_inc/');
defined('ABSPATH') || exit;
function custom_comment_edit($content)
{
// STAGE 1 : REMOVE LINK AND CHANGE TO THE VALUE :
// return strip_tags($content);
// STAGE 2 : REMOVE THE INNER ATTRIBUTE OF THE HERF REPLACE TO # :
// preg_match_all('~<a\s[^>]*href=["\']([^"\']+)["\'][^>]*>(.*?)<\/a>~i', $content, $matches);
// foreach ($matches[1] as $index => $url) {
// $content = str_replace($url, "#", $content);
// }
// return $content;
//STAGE 3 : REMOVE THE LINK AND CREATE STARS REPALCED THE INNER ATTR :
preg_match_all('~<a\s[^>]*href=["\']([^"\']+)["\'][^>]*>(.*?)<\/a>~i', $content, $matches);
foreach ($matches[1] as $index => $url) {
$stars = str_repeat("*", strlen($matches[2][$index]));
$content = str_replace($matches[2][$index], $stars, $content);
}
return $content;
}
add_filter('comment_text', 'custom_comment_edit');