本教程演示了安装和使用WP-API与Oauth一起使用的WP-API,oauth是一个提供类似REST的API端点的WordPress插件。 未经验证的用户可以读取内容,而经过验证的用户(通过OAuth或Cookie)可以编写内容。 该过程不是直观的,因此本指南简化了设置,假设基本终端和流浪熟悉。
密钥概念:
/wp-json/posts
> oauth1处理身份验证,需要wp-cli
使用宅基地改进的实例:
修改
'sgit clone https://github.com/swader/homestead_improved hi_wp_github cd hi_wp_github sed -i '' "s@map\: \.@map\: $PWD@g" Homestead.yaml
Homestead.yaml
sites
(确保
sites: - map: test.app to: /home/vagrant/Code/wptest
>
test.app
>安装WordPress:/etc/hosts
configure
。 通过您的浏览器访问网站。cd ~/Code wget https://wordpress.org/latest.tar.gz tar -xvzf latest.tar.gz mv wordpress wptest cd wptest cp wp-config-sample.php wp-config.php
wp-config.php
WP-API设置:
>通过WordPress插件管理器安装WP-API插件(版本1.2。*或更高版本)。 安装后,应返回JSON帖子数组。 但是,内容提交需要进一步的步骤。
/wp-json/posts
OAuth服务器设置:
安装oauth1插件:wp-cli
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp
cd ~/Code/wptest git clone https://github.com/WP-API/OAuth1 wp-content/plugins/oauth-server
wp oauth1 add
>在您的VM中创建一个新项目(
),将新站点添加到>:
)。 在submitter
>目录中创建Homestead.yaml
,
sites: - map: test.app to: /home/vagrant/Code/wptest - map: test2.app to: /home/vagrant/Code/submitter
以下各节详细介绍了3腿OAuth Flow和API相互作用的 结论: > 以上是WP API和OAUTH-使用WordPress使用WordPress的WordPress的详细内容。更多信息请关注PHP中文网其他相关文章!vagrant provision
index.php
安装所需的作曲家软件包:callback.php
credentials.php
submitter
修改WordPresscredentials.php
以允许重定向:git clone https://github.com/swader/homestead_improved hi_wp_github
cd hi_wp_github
sed -i '' "s@map\: \.@map\: $PWD@g" Homestead.yaml
index.php
>,callback.php
和makepost.php
>