Skip to content

refactor: migrate POST posts update endpoint from PHP to TypeScript#4

Open
xavierandueza wants to merge 1 commit into
masterfrom
refactor/php-to-typescript-for-single-endpoint
Open

refactor: migrate POST posts update endpoint from PHP to TypeScript#4
xavierandueza wants to merge 1 commit into
masterfrom
refactor/php-to-typescript-for-single-endpoint

Conversation

@xavierandueza
Copy link
Copy Markdown
Owner

Summary

  • Migrates the POST /wp/v2/posts/{id} (update post) endpoint from the PHP WP_REST_Posts_Controller to a TypeScript Next.js App Router API route
  • Removes the PHP update_item(), update_item_permissions_check() methods, and the EDITABLE route registration, while preserving all shared methods used by other CRUD operations
  • Implements the full update flow in TypeScript: authentication, authorization, input validation, database update, post-update operations (format, featured media, sticky, template, terms, meta), and response serialization
  • Adds Next.js infrastructure (package.json, tsconfig.json, MySQL2 connection pool) as part of the gradual PHP-to-TypeScript migration

Details

The TypeScript implementation faithfully replicates the PHP logic:

  • Auth: WordPress Application Password authentication via HTTP Basic Auth
  • Capabilities: edit_post meta capability mapping matching map_meta_cap() behavior
  • Validation: Zod schema matching the WordPress REST API post schema with all field types
  • Database: Direct MySQL queries against wp_posts, wp_postmeta, wp_term_relationships, and wp_options tables within a single transaction
  • Response: Matches the WordPress REST API response format including dates, taxonomy terms, featured media, sticky status, and template

Test plan

  • Verify TypeScript compiles with npx tsc --noEmit
  • Verify PHP file has no syntax errors
  • Verify GET and DELETE post endpoints still function correctly
  • Verify the new TypeScript endpoint accepts POST/PUT/PATCH requests
  • Test authentication with WordPress Application Passwords
  • Test post update with various field combinations (title, content, status, etc.)

…to TypeScript

Replace the PHP update post endpoint (WP_REST_Posts_Controller::update_item)
with a TypeScript Next.js API route. This is part of the gradual migration
of the WordPress REST API from PHP to TypeScript.

PHP changes:
- Remove EDITABLE route registration from register_routes()
- Remove update_item_permissions_check() method
- Remove update_item() method
- Shared methods (prepare_item_for_database, handle_terms, etc.) preserved

TypeScript implementation:
- Next.js App Router API route at /api/sites/[site]/posts/[postId]
- MySQL2 connection pool with transaction support
- WordPress Application Password authentication
- Full capability resolution (edit_post meta cap mapping)
- Zod request validation matching WP REST API schema
- Complete update flow: permissions, validation, DB update,
  post-update operations (format, media, sticky, template, terms, meta)
- Response serialization matching WP REST API format
@xavierandueza xavierandueza marked this pull request as ready for review February 13, 2026 13:09
@xavierandueza xavierandueza reopened this Feb 13, 2026
@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Feb 13, 2026

📚 Documentation update workflow has been queued for reopened PR (Job ID: 698f22b7eedcb468ab9b03b0). The documentation bot will propose changes (if relevant) shortly.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Feb 13, 2026

📊 PR Analysis Summary

Files Changed: 24 file(s)
Additions: +3107 lines
Deletions: -177 lines

Changed Files
  • .gitignore
  • next.config.ts
  • package-lock.json
  • package.json
  • src/app/api/sites/[site]/posts/[postId]/route.ts
  • src/config/database.ts
  • src/lib/auth/authenticate.ts
  • src/lib/auth/capabilities.ts
  • src/lib/db/connection.ts
  • src/lib/db/queries/options.ts
  • src/lib/db/queries/postmeta.ts
  • src/lib/db/queries/posts.ts
  • src/lib/db/queries/terms.ts
  • src/lib/db/queries/users.ts
  • src/lib/errors/wp-error.ts
  • src/lib/services/post-response.service.ts
  • src/lib/services/post-update.service.ts
  • src/lib/types/index.ts
  • src/lib/validation/date.ts
  • src/lib/validation/post-update-schema.ts
  • src/lib/validation/slug.ts
  • src/lib/validation/status.ts
  • tsconfig.json
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Relevant Documentation Pages

Docs impacted by this PR
  • getpost
  • updatepost
  • deletepost
  • be-devenv
  • be-get-started-with-wp-env
  • be-get-started-with-wp-scripts
  • be-nodejs-development-environment
  • admin-development
  • be-data-basics-setup

ℹ️ Documentation Updates

No automatic documentation updates were applied.


This analysis was automatically generated by the ReadMe AI Documentation Bot.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Feb 13, 2026

📚 Documentation update workflow has been queued for reopened PR (Job ID: 698f2563eedcb468ab9b03b8). The documentation bot will propose changes (if relevant) shortly.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Feb 13, 2026

📊 PR Analysis Summary

Files Changed: 24 file(s)
Additions: +3107 lines
Deletions: -177 lines

Changed Files
  • .gitignore
  • next.config.ts
  • package-lock.json
  • package.json
  • src/app/api/sites/[site]/posts/[postId]/route.ts
  • src/config/database.ts
  • src/lib/auth/authenticate.ts
  • src/lib/auth/capabilities.ts
  • src/lib/db/connection.ts
  • src/lib/db/queries/options.ts
  • src/lib/db/queries/postmeta.ts
  • src/lib/db/queries/posts.ts
  • src/lib/db/queries/terms.ts
  • src/lib/db/queries/users.ts
  • src/lib/errors/wp-error.ts
  • src/lib/services/post-response.service.ts
  • src/lib/services/post-update.service.ts
  • src/lib/types/index.ts
  • src/lib/validation/date.ts
  • src/lib/validation/post-update-schema.ts
  • src/lib/validation/slug.ts
  • src/lib/validation/status.ts
  • tsconfig.json
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Relevant Documentation Pages

Docs impacted by this PR
  • getpost
  • updatepost
  • deletepost
  • admin-application-passwords
  • createpost
  • admin-hardening
  • plugins-http-api
  • createapplicationpassword
  • admin-brute-force
  • be-data-basics-setup

✅ Documentation Changes Applied

🔗 View changes in ReadMe


This analysis was automatically generated by the ReadMe AI Documentation Bot.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Feb 17, 2026

📚 Documentation update workflow has been queued for reopened PR (Job ID: 6994ebdea0f3185b35c76740). The documentation bot will propose changes (if relevant) shortly.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Feb 17, 2026

📚 Documentation update workflow has been queued for reopened PR (Job ID: 6994fce2a0f3185b35c76770). The documentation bot will propose changes (if relevant) shortly.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Feb 17, 2026

📊 PR Analysis Summary

Files Changed: 24 file(s)
Additions: +3107 lines
Deletions: -177 lines

Changed Files
  • .gitignore
  • next.config.ts
  • package-lock.json
  • package.json
  • src/app/api/sites/[site]/posts/[postId]/route.ts
  • src/config/database.ts
  • src/lib/auth/authenticate.ts
  • src/lib/auth/capabilities.ts
  • src/lib/db/connection.ts
  • src/lib/db/queries/options.ts
  • src/lib/db/queries/postmeta.ts
  • src/lib/db/queries/posts.ts
  • src/lib/db/queries/terms.ts
  • src/lib/db/queries/users.ts
  • src/lib/errors/wp-error.ts
  • src/lib/services/post-response.service.ts
  • src/lib/services/post-update.service.ts
  • src/lib/types/index.ts
  • src/lib/validation/date.ts
  • src/lib/validation/post-update-schema.ts
  • src/lib/validation/slug.ts
  • src/lib/validation/status.ts
  • tsconfig.json
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Relevant Documentation Pages

Docs impacted by this PR
  • updatepost
  • updatepage
  • getpost
  • updatemedia
  • be-data-basics-setup
  • createpost
  • listposts
  • themes-build-process
  • be-building-a-list-of-pages
  • be-get-started-with-wp-scripts

✅ Documentation Changes Applied

🔗 View changes in ReadMe


This analysis was automatically generated by the ReadMe AI Documentation Bot.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Feb 20, 2026

📚 Documentation Changes Applied

🔗 View changes in ReadMe

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Feb 24, 2026

📚 Documentation Changes Applied

🔗 View changes in ReadMe

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Feb 26, 2026

📚 No documentation updates were needed for this PR.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Mar 17, 2026

Documentation Changes Added

Page Section Action Preview
updatepostAPI Reference🔵 UpdatedPreview

🔗 View all changes in ReadMe


Actions

  • Merge doc branch with PR merge
  • Delete doc branch with PR close

@readme-agent-staging
Copy link
Copy Markdown

readme-agent-staging Bot commented Mar 26, 2026

📚 No documentation updates were needed for this PR.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Mar 26, 2026

Documentation Changes Added

Page Section Action Summary
updatepostAPI Reference📝 UpdatedUpdated the request body schema to explicitly list all supported post update fields (matching the new TypeScript Zod validation schema), added missing fields to TypeScript code example interface, and updated description to reflect PUT/PATCH support.

🔗 View all changes in ReadMe


Actions

  • Merge documentation branch with PR merge
  • Delete documentation branch with PR close

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Apr 1, 2026

Documentation Changes Added

Page Section Action Summary
updatepostAPI Reference📝 UpdatedUpdated endpoint URL from /wp-json/wp/v2/posts/{id} to /api/sites/{site}/posts/{postId} and authentication from Bearer token to HTTP Basic Auth with Application Passwords to reflect the migration from PHP to TypeScript.
updatepostAPI Reference📝 UpdatedUpdated code examples to use the new /api/sites/{site}/posts/{postId} endpoint URL and HTTP Basic Auth with Application Passwords authentication.
updatepostAPI Reference📝 UpdatedUpdated code examples to use the new /api/sites/{site}/posts/{postId} endpoint URL and HTTP Basic Auth with Application Passwords authentication.

🔗 View all changes in ReadMe


Actions

  • Merge documentation branch with PR merge
  • Delete documentation branch with PR close

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Apr 8, 2026

Documentation Changes Added

Page Section Action Summary
updatepostAPI Reference📝 UpdatedUpdated endpoint URL from /wp/v2/posts/{id} to /api/sites/{site}/posts/{postId}, changed authentication from Bearer token to HTTP Basic Auth with Application Passwords, updated code examples, and updated OAS definition to reflect the TypeScript migration.

🔗 View all changes in ReadMe


Actions

  • Merge documentation branch with PR merge
  • Delete documentation branch with PR close

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Apr 10, 2026

Documentation Changes Added

Page Section Action Summary
updatepostAPI Reference📝 UpdatedUpdate endpoint path, authentication method, code examples, and response to reflect migration from PHP to TypeScript with new /api/sites/{site}/posts/{postId} path and HTTP Basic Auth
listpostsAPI Reference📝 UpdatedUpdate the card link text for the Update a post endpoint to reflect the new API path
createpostAPI Reference📝 UpdatedUpdate the card link text for the Update a post endpoint to reflect the new API path
getpostAPI Reference📝 UpdatedUpdate the card link text for the Update a post endpoint to reflect the new API path
deletepostAPI Reference📝 UpdatedUpdate the card link text for the Update a post endpoint to reflect the new API path

🔗 View all changes in ReadMe


Actions

  • Merge documentation branch with PR merge
  • Delete documentation branch with PR close

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Apr 24, 2026

⚠️ The documentation bot was unable to process documentation updates (Job ID: 69eb03ec7e30b762e6da71fc).

You can re-trigger by reopening this PR.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Apr 24, 2026

Documentation Changes Added

Page Section Action Summary
updatepostAPI Reference📝 UpdatedUpdated endpoint URL from /wp/v2/posts/{id} to /api/sites/{site}/posts/{postId}, changed authentication from Bearer token to HTTP Basic Auth with Application Passwords, and updated all code examples to reflect the migrated TypeScript endpoint.
getpostAPI Reference📝 UpdatedUpdated the Update a post card description to reflect the new endpoint path.
listpostsAPI Reference📝 UpdatedUpdated the Update a post card description to reflect the new endpoint path.
deletepostAPI Reference📝 UpdatedUpdated the Update a post card description to reflect the new endpoint path.
createpostAPI Reference📝 UpdatedUpdated the Update a post card description to reflect the new endpoint path.

🔗 View all changes in ReadMe


Actions

  • Merge documentation branch with PR merge
  • Delete documentation branch with PR close

If neither actions are selected, on PR close/merge the docs branch in ReadMe will remain open.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Apr 24, 2026

Documentation Changes Added

Page Section Action Summary
updatepostAPI Reference📝 UpdatedUpdated endpoint URL from /wp/v2/posts/{id} to /api/sites/{site}/posts/{postId}, changed authentication from Bearer token to HTTP Basic Auth with Application Passwords, and updated the OAS definition to reflect the migrated TypeScript endpoint.

🔗 View all changes in ReadMe


Actions

  • Merge documentation branch with PR merge
  • Delete documentation branch with PR close

If neither actions are selected, on PR close/merge the docs branch in ReadMe will remain open.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Apr 24, 2026

Documentation Changes Added

Page Section Action Summary
updatepostAPI Reference📝 UpdatedUpdate the Update a post endpoint to reflect migration from PHP to TypeScript with new path /api/sites/{site}/posts/{postId} and HTTP Basic Auth authentication

🔗 View all changes in ReadMe


Actions

  • Merge documentation branch with PR merge
  • Delete documentation branch with PR close

If neither actions are selected, on PR close/merge the docs branch in ReadMe will remain open.

@readme-pr-app
Copy link
Copy Markdown

readme-pr-app Bot commented Apr 24, 2026

Documentation Changes Added

Page Section Action Summary
updatepostAPI Reference📝 UpdatedUpdated the Update a post endpoint to reflect migration from PHP to TypeScript: new endpoint path /api/sites/{site}/posts/{postId}, HTTP Basic Auth with Application Passwords, PUT/PATCH support, and block_version in response.

🔗 View all changes in ReadMe


Actions

  • Merge documentation branch with PR merge
  • Delete documentation branch with PR close

If neither actions are selected, on PR close/merge the docs branch in ReadMe will remain open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant