我刚刚将我的站点从一台服务器移动到另一台服务器,都在bluehost上
但我得到了这个错误
Parse error: syntax error, unexpected T_FUNCTION in /home2/energzk2/public_html/wp-content/themes/energy/functions/contact.php on line 3
下面是该文件的几行代码
<?php
/*Add meta boxes to contact page*/
add_action( \'add_meta_boxes_page\', function( \\WP_Post $post ) {
global $post;
if(!empty($post)){
$pageTemplate = get_post_meta($post->ID, \'_wp_page_template\', true);
if($pageTemplate == \'page-contact.php\' ){
add_meta_box(\'contact_meta_1\', \'Contact Details\', \'contact_details\', \'page\', \'normal\', \'high\');
add_meta_box(\'contact_meta_2\', \'Social Details\', \'social_details\', \'page\', \'normal\', \'high\');
add_meta_box(\'contact_meta_3\', \'Footer Details\', \'footer_section\', \'page\', \'normal\', \'high\');
add_meta_box(\'contact_meta_4\', \'Copyright\', \'copyright\', \'page\', \'normal\', \'high\');
}
}
},1);
我尝试了@Howdy\\u McGee给出的解决方案,它奏效了。但我收到了这个警告
Warning: Unexpected character in input: \'\\\' (ASCII=92) state=1 in /home2/energzk2/public_html/wp-content/themes/energy/functions/contact.php on line 19
最合适的回答,由SO网友:Howdy_McGee 整理而成
这被称为Anonymous Function 并且仅在PHP的更高版本中受支持,特别是5.3.0 and later. 如果我是一个赌徒,我会说你的服务器有一个早期版本的PHP。请尝试以下操作:
/*Add meta boxes to contact page*/
function contact_metaboxes( \\WP_Post $post ) {
global $post;
if( ! empty( $post ) ) {
$pageTemplate = get_post_meta($post->ID, \'_wp_page_template\', true);
if($pageTemplate == \'page-contact.php\' ){
add_meta_box( \'contact_meta_1\', \'Contact Details\', \'contact_details\', \'page\', \'normal\', \'high\' );
add_meta_box( \'contact_meta_2\', \'Social Details\', \'social_details\', \'page\', \'normal\', \'high\' );
add_meta_box( \'contact_meta_3\', \'Footer Details\', \'footer_section\', \'page\', \'normal\', \'high\' );
add_meta_box( \'contact_meta_4\', \'Copyright\', \'copyright\', \'page\', \'normal\', \'high\' );
}
}
}
add_action( \'add_meta_boxes_page\', \'contact_metaboxes\', 1 );