user2321959
user2321959

Reputation: 94

Error in code adding section to Customizer

Pretty novice at PHP, trying to learn. I'm getting this error:

Your PHP code changes were rolled back due to an error on line 54 of file wp-content/themes/softwarehill/customizer.php. Please fix and try saving again.

syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) or const (T_CONST)

Appears to be in the sanitation part of the code

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();

Upvotes: 0

Views: 517

Answers (1)

Mike Foxtech
Mike Foxtech

Reputation: 1651

you probably forgot to close the bracket in the class

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',) );
    }
}

Upvotes: 1

Related Questions