这很简单,只需使用您的网站主页url:)
之后,只需在通过POST
HTTP方法和带有回调的挂钩。
add_action( \'wp_loaded\', function() {
if ( $_SERVER[\'REQUEST_METHOD\'] === \'POST\' ) {
// fire the custom action
do_action(\'onchangeapi\', new PostListener($_POST));
}
} );
现在是listener类
class PostListener {
private $valid = false;
/**
* @param array $postdata $_POST array
*/
public function __construct(array $postdata) {
$this->valid = $this->validatePostData($postdata);
}
/**
* Runs on \'onchangeapi\' action
*/
public function __invoke() {
if ($this->valid) {
// do whatever you need to do
exit();
}
}
/**
* @param array $postdata $_POST array
* @return bool
*/
private function validatePostData(array $postdata) {
// check here the $_POST data, e.g. if the post data actually comes
// from the api, autentication and so on
}
}