Php Wordpress插件短代码中的操作挂钩

Php Wordpress插件短代码中的操作挂钩,php,wordpress,http-post,Php,Wordpress,Http Post,我正在开发一个Wordpress插件,在使用我的短代码中的一个操作获取$\u POST数据时遇到了问题。我正在解析的表单位于我添加了短代码的页面上 以下是我得到的: function wpd_post_parse() { $string = 'wp hook: ' . var_dump($_POST) . "\r\n"; //$string = 'wp hook: first name: ' . $_POST["first_name"] . "\r\n"; //$st

我正在开发一个Wordpress插件,在使用我的短代码中的一个操作获取$\u POST数据时遇到了问题。我正在解析的表单位于我添加了短代码的页面上

以下是我得到的:

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 
更新:感谢您迄今为止的帮助。我试图在表单提交中获取$\u POST值(名字),但该值不在$\u POST[“first\u name”]内。打印到文件中的所有内容都是“wp hook:first name:”下面是代码的外观:

//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' );

这种方法不起作用,在Wordpress上造成了站点范围的问题。我把我的代码从注册页面移到了填写好的表格的re direct页面上。从那里,我能够捕获我正在寻找的表单数据。

这种方法不起作用,它在Wordpress上造成了站点范围的问题。我把我的代码从注册页面移到了填写好的表格的re direct页面上。从那里我可以捕获我正在寻找的表单数据