1
我正在開發一個Wordpress插件,並且在使用短代碼內的操作獲取$ _POST數據時遇到了問題。我解析的表單位於我已將我的簡碼添加到的頁面上。Wordpress Plugin Shortcode中的動作鉤子
下面是我得到了什麼:
function wpd_post_parse() {
$string = 'wp hook: ' . var_dump($_POST) . "\r\n";
//$string = 'wp hook: first name: ' . $_POST["first_name"] . "\r\n";
//$string .= 'wp hook: last name: ' . $_POST["last_name"] . "\r\n";
//$string .= 'wp hook: email: ' . $_POST["email"] . "\r\n";
$fileName = dirname(__FILE__) . '/log.txt';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $string, FILE_APPEND);
/*
if (!empty($_POST)){
$string = 'wp hook: ' . var_dump($_POST) . "\r\n";
$fileName = dirname(__FILE__) . '/log.txt';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $string, FILE_APPEND);
}else{
$string = 'wp hook: POST empty' . "\r\n";
$fileName = dirname(__FILE__) . '/log.txt';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
}
*/
}
function mgc_init(){
$htmlStr = 'Hello World!' . "\r\n";
$fileName = dirname(__FILE__) . '/log.txt';
file_put_contents($fileName, $htmlStr, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $htmlStr, FILE_APPEND);
//Add hook to capture $_POST data
add_action('parse_request', 'wpd_post_parse');
}
add_shortcode('mgc','mgc_init'); //put this shortcode [mgc] on page in Wordpress
UPDATE:感謝您的幫助迄今。我試圖在表單提交上獲得$ _POST值(名字),但該值不在$ _POST [「first_name」]內。所有這些被打印到文件「WP鉤:第一個名字:」下面的代碼現在的樣子:
//Capture the $_POST data
function wpd_post_parse() {
//$string = 'wp hook: ' . var_dump($_POST) . "\r\n";
$string = 'wp hook: first name: ' . $_POST["first_name"] . "\r\n";
//$string .= 'wp hook: last name: ' . $_POST["last_name"] . "\r\n";
//$string .= 'wp hook: email: ' . $_POST["email"] . "\r\n";
$fileName = dirname(__FILE__) . '/log.txt';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $string, FILE_APPEND);
/*
if (!empty($_POST)){
$string = 'wp hook: ' . var_dump($_POST) . "\r\n";
$fileName = dirname(__FILE__) . '/log.txt';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $string, FILE_APPEND);
}else{
$string = 'wp hook: POST empty' . "\r\n";
$fileName = dirname(__FILE__) . '/log.txt';
file_put_contents($fileName, $string, FILE_APPEND | LOCK_EX);
}
*/
//exit;
}
function mgc_init(){
$htmlStr = 'Hello World!' . "\r\n";
$fileName = dirname(__FILE__) . '/log.txt';
file_put_contents($fileName, $htmlStr, FILE_APPEND | LOCK_EX);
//file_put_contents($fileName, $htmlStr, FILE_APPEND);
do_action('wpd_post_parse');
}
add_shortcode('mgc','mgc_init'); //put this shortcode [mgc] on thedinnerdaily.com/subscribe/ page in Wordpress
add_action('parse_request', 'wpd_post_parse');