WordPress - 将get_option值传递给类变量

时间:2014-10-05 13:30:28

标签: php wordpress class variables plugins

我正在编写一个WordPress插件,我希望将选项值传递给类变量。这是一个班级

class wpsmy_html_compression
{
    // protected $compress_css = ( get_option('wpsmy_combine_js') == 'on' ? true : false );
    // protected $compress_js = ( get_option('wpsmy_combine_css') == 'on' ? true : false );
    protected $compress_js = true;
    protected $compress_css = true;
    protected $info_comment = true;
    protected $remove_comments = true;

    // Variables
    protected $html;

    public function __construct($html)
    {
        if (!empty($html)) {
            $this->parseHTML($html);
        }
    }
    ...
    ...
    ...
}

这是一个电话

function wpsmy_html_compression_finish($html)
{
    return new wpsmy_html_compression($html);
}

function wpsmy_html_compression_start()
{
    ob_start('wpsmy_html_compression_finish');
}

add_action('get_header', 'wpsmy_html_compression_start');

我想要的是使用WordPress get_option将动态值(true / false)传递给类变量$compress_js$compress_css。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

为什么不使用==运算符来获取布尔值?如果get_option(...)==' on'?

$compress_css = ( get_option('wpsmy_combine_js') == 'on' );

您可以转到/wp-admin/options.php,查看"真实"期权的价值。如果它是' on'或别的什么!