我目前正在建立一个我在Wordpress中构建的现有网站。我取得了不错的进步,但我遇到了麻烦。我很清楚Wordpress已经有数以千计的插件已经可以使用,但是我已经决定要试一试并尝试构建我自己的插件。我在互联网上看到一篇文章是一个很好的起点 - 但是我收到了一个错误,而且我不确定如何修复它。
我正在使用本网站上发布的以下教程 - http://starkod.net/build-wordpress-contact-forms-plugin-save-to-db-and-send-email/
到目前为止,按照教程中的步骤,我已经能够在插件菜单中显示插件 - 激活插件 - 在激活插件时,自定义表被添加到数据库中以存储任何记录,联系表单响应的菜单项在wordpress仪表板中可见,但之后我收到以下错误 -
解析错误:语法错误,意外' =',期待')'
错误表示它基于代码的第73行
convertPointToView
第73行代码从这里开始 -
sceneWidth
如果有人可以帮我解决这个问题,我将不胜感激。
答案 0 :(得分:1)
提供的代码的问题在于,您当前拥有>
的每个地方都应该>
。像这样(我"美化"它有点):
//if you want to have both logged in and not logged in users submitting, you have to add both actions!
add_action( 'admin_post_add_foobar', 'starkod_admin_add_foobar' );
add_action( 'admin_post_nopriv_add_foobar', 'starkod_admin_add_foobar' );
function starkod_admin_add_foobar() {
global $wpdb;
$data = array(
'name' => sanitize_text_field( $_POST['name'] ),
'email' => isset( $_POST['email'] ) ? sanitize_email( $_POST['email'] ) : null,
'msg' => sanitize_text_field( $_POST['msg'] ),
'time' => current_time( 'mysql ')
);
$table_name = $wpdb->prefix.'starkod';
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
// send Email for admin
wp_mail(
get_option( 'admin_email' ),
'starkod Contact Form',
'Name : ' . $data['name'] .
' phone : ' . $data['phone'] .
' email : ' . $data['email'] .
' The message: ' . $data['msg'] .
' Time : ' . $data['time'],
$headers
);
if ( $wpdb->insert( $table_name, $data ) ) {
$_SESSION['message'] = "Your Message received , thanks ";
} else {
$_SESSION['message'] = "there's problem try again please";
}
//redirect back to where user was comming
wp_redirect( $_SERVER['HTTP_REFERER'] );
//request handlers should die() when they complete their task
}