php - 将代码添加到定制器部分时出错
问题描述
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();
解决方案
您可能忘记在课堂上关闭括号
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',) );
}
}
推荐阅读
- python - PyCharm 终端无法识别 Python 或 Pip
- javascript - 如何禁用 eslint 中的单行注释?
- python - 将 python 2.7 脚本转换为 python 3.8
- graphql - 验证 graphql 查询
- android - Android Studio - Logcat 不适用于模拟器,但适用于手机
- objective-c - 如何从 Firestore 获取特定数据并在 Objective-C 中更新它
- r - 按关于 OID 的类拆分数据帧
- node.js - 使用 node.js 从 mongoDB 获取数据,连接有效,但没有数据显示
- javascript - 在 ngOnChanges 中更新 ngrx 选择器
- c++ - Mac OSX 代码设计问题