bloginfo(‘admin_email’)のメールアドレスを数値文字参照に変換する
- 2008年12月12日 18時59分
- WordPress MU | plugins | tips
WordPressのテンプレートにbloginfo('admin_email')と書くと、メールアドレスがそのまま書き出されます。メールアドレス収集ロボットのこともありまして、それはちょっと困ったということで、これを数値文字参照に変換してしまいます(数値文字参照が有効かどうかはさておき、ほんの少しの精神的安定のため)。
<?php
/*
Plugin Name: maaguu_replace_admin_email.php
Plugin URI: http://wp.maaguu.com/2008/12/12/replace-admin-email/
Description:
Version: 1.0
Author: maaguu
Author URI: http://maaguu.com/
*/
/* Copyright 2008 maaguu (email : info@mx.maaguu.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class maaguu_replace_admin_email
{
private $replace_admin_email;
public function __construct()
{
$this->replace_admin_email;
add_filter('option_admin_email', array($this, 'replace_admin_email'));
}
public function replace_admin_email($email)
{
for ($i = 0; $i < strlen($email); $i++)
{
$this->replace_admin_email .= '&#' . ord($email[$i]) . ';';
}
return $this->replace_admin_email;
}
}
new maaguu_replace_admin_email();
/* End of file maaguu_admin_email.php */
プラグインディレクトリに置いて有効にするだけで使えます。
しかしここで問題が。
headのメールアドレスは変換されていますが、プラグインで書き出したフッタが変換されません(^^ゞ どうしようかなあ……。
というより、このプラグイン、動作がおかしいですので使わないほうがよさげ(^^ゞ



[...] こんな関数があるのなら、bloginfo(’admin_email’)のメールアドレスを数値文字参照に変換するのは無駄でした。 [...]