kucrut/bridge

额外的REST API端点和功能

安装: 268

依赖项: 1

建议者: 0

安全: 0

星标: 7

关注者: 2

分支: 0

开放问题: 0

类型:wordpress-plugin

v0.9.0 2021-02-25 13:44 UTC

This package is auto-updated.

Last update: 2024-08-25 21:06:47 UTC


README

此插件是为了在WordPress和Minnie之间搭建桥梁而构建的。它修改了一些WP API请求的结果。

要求

  • WordPress 4.5
  • WP API 2.0-beta13

更多桥梁

端点

信息

端点: /wp-json/bridge/v1/info

{
  "url": "https://kucrut.org/wp",
  "home": "https://kucrut.org",
  "name": "Dzikri Aziz",
  "description": "WordPress Developer, Traveler.",
  "lang": "en-US",
  "html_dir": "ltr",
  "settings": {
    "archive": {
      "per_page": 11
    },
    "comments": {
      "per_page": 50,
      "threads": true,
      "threads_depth": 3
    }
  }
}

结果修改

要获取修改后的结果,必须首先注册一个 "客户端ID"。

/**
 * Register to the Bridge plugin
 *
 * @param   array  $client_ids Client IDs.
 * @wp_hook filter bridge_client_ids
 * @return  array
 */
function minnie_register_to_bridge( $client_ids ) {
	$client_ids[] = 'minnie';

	return $client_ids;
}
add_filter( 'bridge_client_ids', 'minnie_register_to_bridge' );

然后,每个API请求都必须包含一个 X-Requested-With 头,并将值设置为注册的客户端ID,在这种情况下为 minnie

术语

从术语链接中去除主页URL。

原始结果

[
  {
    "id": 3,
    "count": 0,
    "description": "",
    "link": "http://example.org/blog/type/aside/",
    "name": "Aside",
    "slug": "post-format-aside",
    "taxonomy": "post_format"
  }
]

修改后的结果

[
  {
    "id": 3,
    "count": 0,
    "description": "",
    "link": "/blog/type/aside/",
    "name": "Aside",
    "slug": "post-format-aside",
    "taxonomy": "post_format"
  }
]

文章

对文章端点的请求的结果将进行以下修改

  • 主页URL从 linkcontent.rendered 中去除。
  • title 新增一项:from_content。它是从文章内容生成的,在文章没有标题但仍然希望在客户端应用程序上显示生成的标题时非常有用。
  • 添加了 date_formattedmodified_formatted,因此您无需在客户端应用程序中对文章日期进行格式化。
  • categoriestagsformats 的值转换为 WP_Term 对象。
  • 当请求文章预览(通过将 preview 参数设置为 1)时,标题和内容将被替换为文章最新修订版中的标题和内容。

原始结果

{
  "id": 1,
  "date": "2016-02-20T02:09:47",
  "date_gmt": "2016-02-20T02:09:47",
  "guid": {
    "rendered": "http://src.wordpress-develop.dev/?p=1"
  },
  "modified": "2016-05-24T11:34:19",
  "modified_gmt": "2016-05-24T11:34:19",
  "slug": "hello-world",
  "type": "post",
  "link": "http://src.wordpress-develop.dev/blog/2016/02/20/hello-world/",
  "title": {
    "rendered": "Hello world!"
  },
  "content": {
    "rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n"
  },
  "excerpt": {
    "rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n"
  },
  "author": 1,
  "featured_media": 0,
  "comment_status": "open",
  "ping_status": "open",
  "sticky": false,
  "format": "aside",
  "categories": [
    1
  ],
  "tags": [
    5
  ],
  "formats": [
    3
  ]
 }

修改后的结果

{
  "id": 1,
  "date": "2016-02-20T02:09:47",
  "date_gmt": "2016-02-20T02:09:47",
  "guid": {
    "rendered": "http://src.wordpress-develop.dev/?p=1"
  },
  "modified": "2016-05-24T11:34:19",
  "modified_gmt": "2016-05-24T11:34:19",
  "slug": "hello-world",
  "type": "post",
  "link": "/blog/2016/02/20/hello-world/",
  "title": {
    "rendered": "Hello world!",
    "from_content": "Welcome to WordPress. This is your first pos…"
  },
  "content": {
    "rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n"
  },
  "excerpt": {
    "rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n"
  },
  "author": 1,
  "featured_media": 0,
  "comment_status": "open",
  "ping_status": "open",
  "sticky": false,
  "format": "aside",
  "categories": [
    {
      "id": 1,
      "name": "Uncategorized",
      "slug": "uncategorized",
      "description": "",
      "link": "/blog/category/uncategorized/"
    }
  ],
  "tags": [
    {
      "id": 5,
      "name": "misc",
      "slug": "misc",
      "description": "",
      "link": "/blog/tag/misc/"
    }
  ],
  "formats": [
    {
      "id": 3,
      "name": "Aside",
      "slug": "post-format-aside",
      "description": "",
      "link": "/blog/type/aside/"
    }
  ],
  "date_formatted": "February 20, 2016",
  "modified_formatted": "May 24, 2016",
}

附件

除了上述修改外,对附件/媒体端点的请求结果还将进行以下修改

  • 添加了 parent_post

修改后的结果

{
  "parent_post": {
    "id": 1,
    "link": "/blog/2016/02/20/hello-world/",
    "title": {
      "rendered": "Hello world!"
    }
  }
}

评论

原始结果

{
  "id": 1,
  "post": 1,
  "parent": 0,
  "author": 0,
  "author_name": "Mr WordPress",
  "author_url": "https://wordpresstheme.cn/",
  "date": "2016-02-20T02:09:47",
  "date_gmt": "2016-02-20T02:09:47",
  "content": {
    "rendered": "<p>Hi, this is a comment.<br />\nTo delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.</p>\n"
  },
  "link": "http://src.wordpress-develop.dev/blog/2016/02/20/hello-world/#comment-1",
  "status": "approved",
  "type": "comment",
  "author_avatar_urls": {
    "24": "http://1.gravatar.com/avatar/?s=24&d=mm&r=g",
    "48": "http://1.gravatar.com/avatar/?s=48&d=mm&r=g",
    "96": "http://2.gravatar.com/avatar/?s=96&d=mm&r=g"
  },
  "_links": {
    "self": [
      {
        "href": "http://src.wordpress-develop.dev/wp-json/wp/v2/comments/1"
      }
    ],
    "collection": [
      {
        "href": "http://src.wordpress-develop.dev/wp-json/wp/v2/comments"
      }
    ],
    "up": [
      {
        "embeddable": true,
        "post_type": "post",
        "href": "http://src.wordpress-develop.dev/wp-json/wp/v2/posts/1"
      }
    ]
  }
}

修改后的结果

{
  "id": 1,
  "post": 1,
  "parent": 0,
  "author": 0,
  "author_name": "Mr WordPress",
  "author_url": "https://wordpresstheme.cn/",
  "date": "2016-02-20T02:09:47",
  "date_gmt": "2016-02-20T02:09:47",
  "content": {
    "rendered": "<p>Hi, this is a comment.<br />\nTo delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.</p>\n"
  },
  "link": "/blog/2016/02/20/hello-world/#comment-1",
  "status": "approved",
  "type": "comment",
  "author_avatar_urls": {
    "24": "http://2.gravatar.com/avatar/?s=24&d=mm&r=g",
    "48": "http://1.gravatar.com/avatar/?s=48&d=mm&r=g",
    "96": "http://0.gravatar.com/avatar/?s=96&d=mm&r=g"
  },
  "children_count": 0,
  "date_formatted": "February 20, 2016 at 2:09 am",
  "_links": {
    "self": [
      {
        "href": "http://src.wordpress-develop.dev/wp-json/wp/v2/comments/1"
      }
    ],
    "collection": [
      {
        "href": "http://src.wordpress-develop.dev/wp-json/wp/v2/comments"
      }
    ],
    "up": [
      {
        "embeddable": true,
        "post_type": "post",
        "href": "http://src.wordpress-develop.dev/wp-json/wp/v2/posts/1"
      }
    ]
  }
}

变更日志

0.8.0

  • 修复与WordPress 4.7的兼容性

0.7.0

  • 支持自定义分类法

0.6.0

  • 添加 /info 端点

0.5.0

  • 实时预览

0.4.0

  • 评论修改

0.3.0

  • 从菜单项的URL中去除 home_url()

0.2.1

  • langhtml_dir 添加到索引响应中

0.2.0

  • 移除菜单和文章格式(现在作为独立插件)

0.1.0

  • 初始版本