register_activation_hook
and register_deactivation_hook
refer to when the plugin is activated and deactivated, respectively, and only fire in those two instances. They’re to be used, for example, when you need to add a database table (and take it back down). You don’t need to remove your filters, either. Your plugin can just be shortened to:
function HalfSpace_filter( $content ) {
$u_agent = $_SERVER['HTTP_USER_AGENT'];
echo "hi";
if ( ( $u_agent=="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" )
|| ( $u_agent=="Googlebot/2.1 (+http://www.googlebot.com/bot.html)" )
|| ( $u_agent=="Googlebot/2.1 (+http://www.google.com/bot.html)" )
|| ( $u_agent=="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)" )
) {
echo "aaaaaaaaa";
$content = str_ireplace( "", " ",$content ); //"" is not empty. it's a persian character names halfspace.
}
return $content;
}
add_filter( 'the_title','HalfSpace_filter' );
add_filter( 'the_content','HalfSpace_filter' );
add_filter( 'comment_text','HalfSpace_filter' );