我正在尝试在Wordpress主题定制器中扩展背景图像控件。我一直试图让这个代码正确,现在我认为它应该工作我在这个函数上收到一个意想不到的T_Public:
public function tab_builtins() {
我试图删除它之前的公开声明,虽然这会产生一个新问题:意外的t_function
我一直在寻找这段代码,试图改变一些小问题,但问题仍然存在。任何人都可以帮助我吗?
以下是有问题的完整代码:
function WP_Customize_Background_Image_Control_Defaults($wp_customize) {
/* Substitute the default control for our new one */
$wp_customize->remove_control( 'background_image' );
$wp_customize->add_control( new WP_Customize_Background_Image_Control_Defaults( $wp_customize ) );
class WP_Customize_Background_Image_Control_Defaults extends WP_Customize_Background_Image_Control {
public function __construct( $manager ) {
$this->add_tab( 'builtins', __('Built-ins'), array( $this, 'tab_builtins' ) );
public function tab_builtins() {
$backgrounds = array(
'/wp-content/themes/newtheme/img/backgrounds/background1.jpg', '/wp-content/themes/newtheme/img/backgrounds/background2.jpg', '/wp-content/themes/newtheme/img/backgrounds/background3.jpg', '/wp-content/themes/newtheme/img/backgrounds/background4.jpg', '/wp-content/themes/newtheme/img/backgrounds/background5.jpg'
);
if ( empty( $backgrounds ) )
return;
foreach ( (array) $backgrounds as $background )
$this->print_tab_image( esc_url_raw( $background->guid ) );
}
}
}
}
add_action( 'customize_register', 'wp_customize_background_image_control_defaults', 11, 1 );
答案 0 :(得分:2)
您错过了public function tab_builtins()
用它来正确关闭__construct
定义