我创建了一个简单的WordPress插件,可以使用在所有网站上共享的默认设置自动设置我的新网站。
作为安装的一部分,它会创建我的隐私政策页面。但是,目前,我只是为内容插入“这是隐私政策页面”,因为它只是存储在我发送给wp_insert_post函数的变量中。我想实际插入我的完整的html格式的隐私政策,而不是虚拟文本。
我只是在寻找一些关于如何做到这一点的想法。
以下是我目前用于硬编码隐私政策插入的代码......
$my_post3 = array();
$my_post3['post_title'] = 'Privacy Policy';
$my_post3['post_content'] = 'Insert your privacy policy content here';
$my_post3['post_type'] = 'page';
//insert the default pages into the site
wp_insert_post($my_post1);
wp_insert_post($my_post2);
wp_insert_post($my_post3);
所以我只需解析一个外部.html或txt文件并将其流式传输到$ my_post3 ['post_content']变量中,保持所有html格式不变。
有什么想法吗?
答案 0 :(得分:0)
好吧,如果你有一个可以访问的文件中的内容,你可以使用file_get_contents()
:
$my_post3 = array();
$my_post3['post_title'] = 'Privacy Policy';
$my_post3['post_content'] = file_get_contents('privacy_policy.txt');
$my_post3['post_type'] = 'page';
当然要求privacy_policy.txt文件与PHP脚本位于同一目录中。如果您在其他服务器上拥有隐私权政策,您还可以使用file_get_contents
中的网址:
$my_post3['post_content'] = file_get_contents('http://www.domain.com/privacy_policy.txt');