wp_remote_get() 替换 file_get_contents() 函数后不起作用

问题描述 投票:0回答:1

我试图用

file_get_contents()
函数替换
wp_remote_get()
函数,因此我的程序与 file_get_contents() 完美配合,但是当我用 wp_remote_get() 替换它时,它不再工作,并且出现此错误:

致命错误:未捕获类型错误:base64_encode():参数 #1 ($string) 必须是字符串类型,给定数组

我尝试了在网上找到的其他解决方案,但它不适用于我的情况。 那么我该如何解决这个问题呢? 这是我的 php 代码:

define( 'ICON_PATH', plugins_url( 'img\sh-logo.svg', __FILE__ ) );
//define( 'BASE64_PLUGIN_ICON', base64_encode( file_get_contents(ICON_PATH) );
define( 'BASE64_PLUGIN_ICON', base64_encode( wp_remote_get(ICON_PATH)) );

提前致谢。

wordpress plugins wordpress-plugin-creation
1个回答
0
投票

出现您遇到的问题是因为 wp_remote_get() 返回一个数组,而不是像 file_get_contents() 这样的字符串。

要解决此问题,您需要从 wp_remote_get() 返回的数组中提取响应正文。

© www.soinside.com 2019 - 2024. All rights reserved.