SO网友:Dan.
确切的代码取决于HTTP通知如何发送到服务器以及JSON的结构,但第一个构建块是侦听传入的post
要求
有很多适合的WP挂钩。一个是init
, e、 g.:
add_action(\'init\', function() {
$user = \'the_correct_basic_auth_username\';
$password = \'the_correct_basic_auth_password\';
$has_supplied_credentials = !(empty($_SERVER[\'PHP_AUTH_USER\']) && empty($_SERVER[\'PHP_AUTH_PW\']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER[\'PHP_AUTH_USER\'] != $AUTH_USER ||
$_SERVER[\'PHP_AUTH_PW\'] != $AUTH_PASS
);
if ($is_not_authenticated) {
return;
}
/* the rest will depend on how the data is sent and the structure of the JSON.
Once you have the data in the structure you want it, you can use the update_user_meta() function to add usermeta. Or, depending on what you\'re saving, use $wpdb or a wrapper function may suite (such as wp_insert_post()) */
});
我从这里获取了基本的身份验证代码-
https://gist.github.com/rchrd2/c94eb4701da57ce9a0ad4d2b00794131