Ошибка в разделе добавления кода в настройщик - PullRequest
0 голосов
/ 07 июля 2019

Довольно новичок в PHP, пытающийся учиться. Я получаю эту ошибку:

Изменения вашего PHP-кода были отменены из-за ошибки в строке 54 файла wp-content / themes / softwarehill / customizer.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 Ответ

1 голос
/ 08 июля 2019

Вы, вероятно, забыли закрыть скобку в классе

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',) );
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...