在wordpress页面中检索$ _POST变量

时间:2013-10-27 13:43:19

标签: php wordpress post

我正在尝试为支付网关创建一个wordpress插件。网关在给定的URL上发回数据(在我的例子中:mysite.com/payment-success)。在这个URL上,我有一个设置wordpress,一旦检测到发布的变量,就会发送电子邮件,并更新该特定付款的数据库结果。

有人可以告诉我如何检索wordpress中从外部URL发送的所有POST变量。

这就是我现在正在做的事情。

    add_shortcode('payment_success_wp', array($this, 'payment_success')); //second argument is array because function is in a class file.

我在新页面上添加了上面的短代码,网址为mysite.com/payment-success。功能(短代码)实现如下。

function payment_success() {
    global $wpdb;
    $this->table_name = $wpdb->prefix . "my_payments";

    mail('myemailaddress@gmail.com', "about payments", "just chasing up" . print_r($_POST));

    if (isset($_POST['transactionstatus']) && isset($_POST['total'])) {

        $data = array(
            'payment_status' => $_POST['transactionstatus'],
        );

        $wpdb->update($this->table_name, $data, array('payment_id' => $_POST['oid']));
    }
}

当我手动调用上面的页面时,电子邮件会触发。我认为这很奇怪,但是当网关发送参数时,没有任何反应。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

用法

<?php add_shortcode( $tag , $func ); ?>

参数

  

$ tag(string)(必需)要在帖子内容中搜索的短代码标签   默认值:无

     

$ func(callable)(必需)发现短代码时挂起   默认值:无

http://codex.wordpress.org/Function_Reference/add_shortcode