我正在尝试在 Wordpress 主题定制器中扩展背景图像控件。我一直在尝试正确获取此代码,现在我认为它应该可以工作了,我在此函数上收到了意外的 T_Public:
public function tab_builtins() {
我试图删除它之前的公共声明,尽管这会产生一个新问题:Unexpected 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 );