在Wordpress页面中包含一个php文件。

时间:2015-10-18 14:21:29

标签: php wordpress curl

我想要包含一个php文件,该文件存储在我的wp-includes文件夹中,该文件对远程服务器执行cURL调用。现在该脚本运行良好,而且一切都很好。

我希望在其中一个Wordpress页面打开时加载它。我尝试了以下内容。

<?php include 'wp-includes/myfilename.php'; ?>

但似乎没有加载任何内容。我可以访问特定php文件的URL,它可以完美地调用cURL。如何在wordpress中包含此页面?

提前致谢。

2 个答案:

答案 0 :(得分:0)

使用get_home_path()(@codex)

<?php include get_home_path . 'wp-includes/myfilename.php'; ?>

答案 1 :(得分:0)

您可以使用wp_remote_get功能:

https://codex.wordpress.org/Function_Reference/wp_remote_get

来自文档:

  

使用GET方法从HTTP请求中检索原始响应。   结果包括HTTP标头和内容。

示例:

<?php
function get_remote_file_33199022(){
    wp_remote_get(
      'http://remote-url.com/file.php',
      array(
         'blocking' => false,
         'httpversion' => '1.1'
      )
    );
}
?>
相关问题