个性化阅读
专注于IT技术分析

将代码添加到Customizer的section出错

PHP的新手, 正在尝试学习。我收到此错误:

由于文件wp-content / themes / softwarehill / customizer.php的第54行出现错误, 你的PHP代码更改已回滚。请修正并​​尝试再次保存。

语法错误, 意外的’if'(T_IF), 期望的函数(T_FUNCTION)或const(T_CONST)

似乎在代码的卫生部分中

class New_Customizer {

private static $instance;

public function register_footer_input() {
add_action( 'wp_footer', array( $this, 'foot_html' ) );
}
public function add_item_to_customizer( $wp_customize ) {

$wp_customize->add_section( 'section_foot_html', array(

'title' => 'Footer HTML', 'description'   => 'It is recommended to type code in a text editor and then paste it into the field below', ) );

$wp_customize->add_setting( 'custom_foot_html', array(

'transport' => 'refresh', 'sanitize_callback' => 'sanitize_html', ) );

$wp_customize->add_control( 'custom_foot_html', array(

'label' => 'Custom footer HTML', 'description' => 'Please copy and paste HTML Code Here', 'section' => 'foot_html', 'settings' => 'custom_foot_html', 'type'  => 'textarea', ) );
}

public function foot_html() {

$footer_html = get_theme_mod( 'custom_foot_html', '' );
if ( $footer_html !== '' ) { echo trim( $footer_html ); }
}

/**
 * Adds sanitization callback function: footer html code
 */

if( ! function_exists( 'sanitize_html' ) ) {

function sanitize_html( $input ) {
 return trim( $input );

}
}

new New_Customizer();

#1


你可能忘记了关闭班级的括号

class New_Customizer {

    private static $instance;

    public function register_footer_input() {
        add_action( 'wp_footer', array( $this, 'foot_html' ) );
    }

    public function add_item_to_customizer( $wp_customize ) {

        $wp_customize->add_section( 'section_foot_html', array(
            'title' => 'Footer HTML', 'description'   => 'It is recommended to type code in a text editor and then paste it into the field below', ) );
        $wp_customize->add_setting( 'custom_foot_html', array(
            'transport' => 'refresh', 'sanitize_callback' => 'sanitize_html', ) );

        $wp_customize->add_control( 'custom_foot_html', array(
            'label' => 'Custom footer HTML', 'description' => 'Please copy and paste HTML Code Here', 'section' => 'foot_html', 'settings' => 'custom_foot_html', 'type'  => 'textarea', ) );
    }
}
赞(0)
未经允许不得转载:srcmini » 将代码添加到Customizer的section出错

评论 抢沙发

评论前必须登录!