我正在构建自己的 wordpers 主题,当开始使用 WordPress Customizer 的主题选项时,我遇到了一些麻烦。
基本上我正在尝试创建一个文本区域,而我所阅读的内容我需要创建一个扩展类,然后在 WordPress 的 add_control 函数下调用它。
我已经尝试过这个并且在定制器模式下一切正常但是一旦我进入网站的任何其他部分我就会收到这个错误:
fatal error :找不到类“WP_Customize_Control”
正如我所说,它在定制器中 100% 工作,它是自己的,但包括管理员在内的任何其他页面我都会收到此消息。
这是类:
class ublxlportfolio_textarea extends WP_Customize_Control {
public $type = 'textarea';
public function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<textarea rows="5" style="width:100%;" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
</label>
<?php
}
}
我需要将它包装在条件标签中吗?如果是,那会是什么??
我做错了吗?
最佳答案
澄清@Robert 的正确答案:
WP_Customize_Control 类仅在实际使用主题定制器时加载。因此,您需要在绑定(bind)到“customize_register”操作的函数中定义您的类。
例子:
add_action( 'customize_register', 'my_customize_register' );
function my_customize_register($wp_customize) {
//class definition must be within my_customie_register function
class ublxlportfolio_textarea extends WP_Customize_Control { ... }
//other stuff
}
关于php - fatal error : Class 'WP_Customize_Control' not found - WordPress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16532397/