Wordpress REST API 开发

简介

Wordpress v4.4以后,已经内置了WP REST API。

接口文档:https://developer.wordpress.org/rest-api/


The WordPress REST API provides an interface for applications to interact with your WordPress site by sending and receiving data as JSON (JavaScript Object Notation) objects. It is the foundation of the WordPress Block Editor, and can likewise enable your theme, plugin or custom application to present new, powerful interfaces for managing and publishing your site content.


RESTful API 路由地址

所有接口地址都以 /wp-json/ 开始,比如获取文章列表的地址是 http://oursite.com/wp-json/wp/v2/posts

Posts	                /wp/v2/posts
Post Revisions	        /wp/v2/posts//revisions
Categories	            /wp/v2/categories
Tags	                /wp/v2/tags
Pages	                /wp/v2/pages
Page Revisions	        /wp/v2/pages//revisions
Comments	            /wp/v2/comments
Taxonomies	            /wp/v2/taxonomies
Media	                /wp/v2/media
Users	                /wp/v2/users
Post Types	            /wp/v2/types
Post Statuses	        /wp/v2/statuses
Settings	            /wp/v2/settings
Themes	                /wp/v2/themes
Search	                /wp/v2/search
Block Types	            /wp/v2/block-types
Blocks	                /wp/v2/blocks
Block Revisions	        /wp/v2/blocks//autosaves/
Block Renderer	        /wp/v2/block-renderer
Block Directory Items	/wp/v2/block-directory/search
Plugins	                /wp/v2/plugins



输出友好数据

在 /wp-inclue/functions.php 中找到该函数,添加 JSON_UNESCAPED_UNICODE。

function wp_json_encode( $data, $options = 0, $depth = 512 ) {
	// $json = json_encode( $data, $options, $depth );
	$json = json_encode( $data, JSON_UNESCAPED_UNICODE, $depth );

	.....

	// return json_encode( $data, $options, $depth );
	return json_encode( $data, JSON_UNESCAPED_UNICODE, $depth );
}



未完待续

随机推荐
Centos 用户和组管理
Android 学习笔记(一)
Apache、PHP 配置 open_basedir,以及性能问题
sql 之 union && union all 以及安全问题
CSS中比一像素还要细的边框
Photoshop 的图层混合模式
axios跨域访问
Photoshop CC 2018中如何设置19号笔刷
Windows无法删除文件夹 系统找不到指定文件
“关于”中故事删减之前