先完成 AI 串接 wordpress 紀錄學習內容的部分。
安裝 Simple JWT Login

安裝後測試,並沒有跟 WordPress API 介接

詢問 ChatGpt ,就自動幫我刻了插件
藉由 ChatGpt 自己刻了一個 JWT 與 API 驗證結合的功能

使用 Postman 呼叫取得 Token

到建立的 ChatGPT > 建立新動作

將 Postman 取得的 API 金鑰設定給 ChatGPT

請 ChatGPT 產生 wordpress API 的 Schema
openapi: 3.1.0
info:
title: WordPress REST API – CREATE endpoints only (wp/v2)
version: 0.3.3
description: |
精簡版 OpenAPI(只含 **新增/建立** 的 POST),並加上 operationId。
為了相容你的檢視器,僅保留單一 security scheme(bearerAuth)。
servers:
description: Production
tags:
- name: posts
- name: pages
- name: media
- name: taxonomies
- name: users
paths:
/wp-json/wp/v2/posts:
post:
operationId: createPost
summary: 新增文章
description: 需驗證(具備 `edit_posts` 權限)。
tags: [posts]
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/PostCreate" }
responses:
"201":
description: 已建立
headers:
Location:
description: 新資源 URL
schema: { type: string, format: uri }
content:
application/json:
schema: { $ref: "#/components/schemas/Post" }
"400": { description: 參數錯誤 }
"401": { description: 未授權 }
"403": { description: 權限不足 }
/wp-json/wp/v2/pages:
post:
operationId: createPage
summary: 新增頁面
description: 需驗證(`edit_pages`)。
tags: [pages]
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
# 某些工具不接受 allOf 引用,這裡直接使用 PostCreate(單純 object)
schema: { $ref: "#/components/schemas/PostCreate" }
responses:
"201":
description: 已建立
content:
application/json:
schema: { $ref: "#/components/schemas/Page" }
"400": { description: 參數錯誤 }
"401": { description: 未授權 }
"403": { description: 權限不足 }
/wp-json/wp/v2/media:
post:
operationId: uploadMedia
summary: 上傳媒體(multipart/form-data)
description: 需驗證(`upload_files`)。
tags: [media]
security:
- bearerAuth: []
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
title: { type: string }
alt_text: { type: string }
caption: { type: string }
description: { type: string }
required: [file]
responses:
"201":
description: 已上傳
content:
application/json:
schema: { $ref: "#/components/schemas/Media" }
"400": { description: 參數錯誤 }
"401": { description: 未授權 }
"403": { description: 權限不足 }
/wp-json/wp/v2/categories:
post:
operationId: createCategory
summary: 新增分類
description: 需驗證(`manage_categories`)。
tags: [taxonomies]
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name: { type: string }
slug: { type: string }
parent: { type: integer }
description: { type: string }
required: [name]
responses:
"201":
description: 已建立
content:
application/json:
schema: { $ref: "#/components/schemas/TermCategory" }
"400": { description: 參數錯誤 }
"401": { description: 未授權 }
"403": { description: 權限不足 }
/wp-json/wp/v2/tags:
post:
operationId: createTag
summary: 新增標籤
description: 需驗證(`manage_categories` 或相近能力)。
tags: [taxonomies]
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name: { type: string }
slug: { type: string }
description: { type: string }
required: [name]
responses:
"201":
description: 已建立
content:
application/json:
schema: { $ref: "#/components/schemas/TermTag" }
"400": { description: 參數錯誤 }
"401": { description: 未授權 }
"403": { description: 權限不足 }
/wp-json/wp/v2/users:
post:
operationId: createUser
summary: 建立使用者(依站台設定可能關閉)
description: 需 `create_users`;部分主機/託管環境預設不允許此端點。
tags: [users]
security:
- bearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
username: { type: string }
name: { type: string }
first_name: { type: string }
last_name: { type: string }
email: { type: string, format: email }
url: { type: string, format: uri }
description: { type: string }
roles:
type: array
items: { type: string }
password: { type: string }
required: [username, email, password]
responses:
"201":
description: 已建立
content:
application/json:
schema: { $ref: "#/components/schemas/User" }
"400": { description: 參數錯誤 }
"401": { description: 未授權 }
"403": { description: 權限不足 }
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
schemas:
RenderedText:
type: object
properties:
rendered: { type: string, description: "HTML 內容" }
protected: { type: boolean }
Post:
type: object
properties:
id: { type: integer }
date: { type: string, format: date-time }
slug: { type: string }
status: { type: string }
type: { type: string, const: "post" }
link: { type: string, format: uri }
title: { $ref: "#/components/schemas/RenderedText" }
content: { $ref: "#/components/schemas/RenderedText" }
excerpt: { $ref: "#/components/schemas/RenderedText" }
author: { type: integer }
featured_media: { type: integer }
categories: { type: array, items: { type: integer } }
tags: { type: array, items: { type: integer } }
meta: { type: object, additionalProperties: true }
PostCreate:
type: object
properties:
slug: { type: string }
status: { type: string, enum: [publish, future, draft, pending, private], default: draft }
title:
oneOf:
- { type: string }
- $ref: "#/components/schemas/RenderedText"
content:
oneOf:
- { type: string }
- $ref: "#/components/schemas/RenderedText"
excerpt:
oneOf:
- { type: string }
- $ref: "#/components/schemas/RenderedText"
author: { type: integer }
featured_media: { type: integer }
categories: { type: array, items: { type: integer } }
tags: { type: array, items: { type: integer } }
meta: { type: object, additionalProperties: true }
required: [title]
Page:
allOf:
- $ref: "#/components/schemas/Post"
- type: object
properties:
type: { type: string, const: "page" }
Media:
type: object
properties:
id: { type: integer }
date: { type: string, format: date-time }
slug: { type: string }
link: { type: string, format: uri }
type: { type: string, const: "attachment" }
media_type: { type: string, enum: [image, file, video, audio] }
mime_type: { type: string }
source_url: { type: string, format: uri }
title: { $ref: "#/components/schemas/RenderedText" }
alt_text: { type: string }
caption: { $ref: "#/components/schemas/RenderedText" }
description: { type: string }
TermBase:
type: object
properties:
id: { type: integer }
name: { type: string }
slug: { type: string }
description: { type: string }
count: { type: integer }
parent: { type: integer }
link: { type: string, format: uri }
TermCategory:
allOf:
- $ref: "#/components/schemas/TermBase"
TermTag:
allOf:
- $ref: "#/components/schemas/TermBase"
User:
type: object
properties:
id: { type: integer }
name: { type: string }
url: { type: string, format: uri }
description: { type: string }
link: { type: string, format: uri }
slug: { type: string }
roles:
type: array
items: { type: string }
email: { type: string, format: email }
avatar_urls:
type: object
additionalProperties: { type: string, format: uri }
請 ChatGpt 產生文章測試

結果 :
