WordPress maaguu (^^; com 北海道札幌でホームページ制作を楽しむ

WordPress, WordPress MU(μ) についての話題、プラグイン作成、カスタマイズ。

「WordPress MUのフッタを共用化したい」プラグインのコードってどうよ?

WordPress MUのフッタを共用化したいのコードって、変です。

普通は多分、以下のような感じに、変数や定数を初期化するはずです。あと、グローバル変数が入ってるのはまずい。

class Object
{
    private $var;

    public function __construct($var)
    {
        //初期化
        $this->var = $var;
    }

    public function getVar()
    {
        return $this->var;
    }
}

$object = new Object('hogehoge');
echo $object->getVar();

ということで、修正してみます。

<?php
/*
Plugin Name: maaguu_footer.php
Plugin URI: http://wp.maaguu.com/2008/12/11/shareing-footer-2/
Description:
Version: 1.1
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
*/

$admin_email = get_bloginfo('admin_email');
$footer_html = "
    <div id=\"ft\" class=\"c\">

        <div id=\"link\">
            <h2>link</h2>
            <ul>
                <li><a href=\"http://d.hatena.ne.jp/maa\">maaguu (^^; memo</a></li>
            </ul>
        </div>
        <!-- #link -->

        <address>
            Email to maaguu:<a href=\"mailto:" . $admin_email . "\">" . $admin_email . "</a>
            Powered by <a href=\"http://mu.wordpress.org/\">WordPress MU</a>
        </address>

    </div>
    <!-- #ft -->

</div>
<!-- #wp -->

<script type=\"text/javascript\">
var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");
document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));
</script>
<script type=\"text/javascript\">
try {
var pageTracker = _gat._getTracker(\"UA-200597-8\");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>
";

class maaguu_footer
{
    private $admin_email;
    private $footer_html;

    public function __construct($admin_email, $footer_html)
    {
        $this->admin_email = $admin_email;
        $this->footer_html = $footer_html;
        add_action('get_footer', array($this, 'echo_footer'));
    }

    public function echo_footer()
    {
        echo $this->footer_html;
    }
}

new maaguu_footer($admin_email, $footer_html);

/* End of file maaguu_footer.php */

こんな感じでどうでしょうか。

private $admin_email;$this->admin_email = $admin_email;は不要だ(^^ゞ

ポイントを現金でキャッシュバック

コメントを残す


※入力必須

※入力必須
Email to maaguu:info@mx.maaguu.com Powered by WordPress MU Clicky Web Analytics