【问题标题】:alternative of curl_setopt in wordpress在 wordpress 中替代 curl_setopt
【发布时间】:2017-07-29 18:23:08
【问题描述】:

我有这段代码,它使用 curl 替换删除图像,它可以正常工作,但我想使用 wordpress 本机函数来完成此操作。

function image( $destination_path, $remote_image_link ) {
    $ch =  curl_init( $remote_image_link );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    $result = curl_exec( $ch );

    if ( $result ) {
        $rv = file_put_contents( $destination_path, $result );
    }
}

想用wp_remote 或其他一些功能实现相同的功能。任何帮助都会很棒

【问题讨论】:

标签: php wordpress


【解决方案1】:

答案很简单。

wp_remote_get 输出是一个大数组,在该数组主体中包含主要细节,因为这里我只有一个链接需要做

$result = wp_remote_get($remote_image_link['body']); 

希望对 wp 文档不清楚的人有所帮助

【讨论】:

    猜你喜欢
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-28
    • 2016-05-09
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多