本教程演示了安裝和使用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
>