php - wp_remote_post() 函数的 php 致命错误
问题描述
我尝试在 wordpress 中远程添加一个帖子条目(来自我的 wordpress 网站之外的网站)。这是我使用的代码:
<?php
$url = 'https://mywpsite.com/wp-json/wp/v2/posts';
$user = 'wpuser';
$pass = 'xxxx yyyy xxxx yyyy'; //Password for use with Application Passwords Plugin
$headers = [
'Authorization' => 'Basic ' . base64_encode( $user . ':' . $pass ),
'cache-control' => 'no-cache',
];
$body = [
'status' => 'draft',
'type' => 'post',
'title' => 'Title of my Post',
'content' => 'My Content',
];
$args = [
'headers' => $headers,
'body' => $body,
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'cookies' => [],
];
$response = wp_remote_post( $url, $args );
if ( is_wp_error( $response ) ) {
print_r( $response->get_error_message() );
}
?>
提供商的 Web 服务器上的错误日志显示:“PHP 致命错误:未捕获的错误:调用未定义的函数 wp_remote_post() in ...” 我检查了 php.ini -> cURL 支持已启用,allow_url_fopen 已打开。我还在 .htaccess 中添加了重写规则。关于检查或做什么的任何想法?
解决方案
推荐阅读
- python - 与字典比较时,列表索引超出范围
- python-3.x - 仅当调用了与该视图核心扩展的模板时,如何在 django 视图中执行 api 调用
- python - 了解自定义登录表单类中的 def clean(self) 方法
- oracle - 如何将此 pl/sql 更改为函数?
- r - 向量对之间的最小绝对差(贪心算法)
- excel - 带有 SUM 的 Excel IF 语句
- excel - Excel:在单元格的索引中引用表格标题
- c - 在 C 中将矩阵提高到 n 次方
- typescript - ES6 代理:设置属性陷阱与去抖动,是否可以避免回调字典?
- python - 将两行合并为一行并转换为 NA