Rob*_*ert 3 php wordpress wordpress-theming
我正在构建自己的wordperss主题,当开始使用WordPress定制器主题选项时,我遇到了一些麻烦.
基本上我试图创建一个textarea和我读过的东西我需要创建一个扩展类,然后在WordPress的add_control函数下调用它.
我已经尝试过这一切,并且在定制器模式下一切运行良好但是一旦我进入网站的任何其他部分,我就会收到此错误:
致命错误:找不到类'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
}
}
Run Code Online (Sandbox Code Playgroud)
我需要将其包装在条件标签中吗?如果是这样那将是什么?
我做错了吗?
fan*_*son 13
澄清@ 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
}
Run Code Online (Sandbox Code Playgroud)
小智 5
在类定义之前需要以下行:
include_once ABSPATH . 'wp-includes/class-wp-customize-control.php';
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题并从谷歌登陆这里,希望这对某人有所帮助!
| 归档时间: |
|
| 查看次数: |
6050 次 |
| 最近记录: |