Skip to content

Support editing posts of custom post types#299

Open
crazytonyli wants to merge 19 commits intotrunkfrom
custom-post-support
Open

Support editing posts of custom post types#299
crazytonyli wants to merge 19 commits intotrunkfrom
custom-post-support

Conversation

@crazytonyli
Copy link
Contributor

There are two issues in loading custom posts from the editor

  1. A request to wp/v2/post/<id> is sent out when preparing editor. This URL is hard-coded.
  2. A JS exception is thrown when editing a custom post. The JS code contains a hard-coded list of "post entities", which appears to be the root cause.

This PR adds restBase and restNamespace to EditorConfiguration. The values will be used to fix the hard-coded wp/v2/post request. They are passed to the JS library and are added to the "post entities" list.

The second commit of this PR updates the Demo project to browse custom posts and allows opening them in the GBK editor. You can checkout this commit to reproduce the issue locally.

Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tested well for me. I noted the correct post type is provided to the WebView configuration. I was unable to verify the correct post type is loaded due to the issue with the Preload Editor button noted in an inline comment.

We might should address the inline comments before merging.

@crazytonyli
Copy link
Contributor Author

@dcalhoun Thanks for the review. I have fixed all the issues.

Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest iteration tested well for me.

Approving this to keep things moving forward, but we should address the inline comments before merging to avoid confusing outcomes in the demo app.

Also, will you please open an integration PR for WordPress-iOS?

I recommend using referencing a GBK commit hash for the integration to start. Once the WordPress-iOS PR is approved, we can publish a GBK pre-release and use that.

Comment on lines +71 to +76
let configuration = viewModel.editorConfiguration.toBuilder()
.setPostType(viewModel.postTypeDetails)
.setPostID(Int(post.id))
.setTitle(post.title?.raw ?? "")
.setContent(post.content.raw ?? "")
.build()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't take into consideration the toggles controlling the native inserter and network logging. The result is the editor opening with the default false value for both.

This isn't a regression with the GBK library, but it's an oddity for the demo app. So, not a blocker, but we ideally address this oversight.

if (
options.path === disabledPath ||
options.path?.startsWith( `${ disabledPath }?` )
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcalhoun This is a new change in the library after your approval.

I found a bug where the post editor content (after opening an existing custom post) shows on screen initially, but disappears in about a second afterwards. This issue only occurs on bundle editor, and does not occurs when using make dev-server.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I imagine the reason it only showcased itself intermittently is due to a race condition.

This change makes sense given we intentionally disable API requests for entity content since we seed the title and content from the native host app.

@crazytonyli
Copy link
Contributor Author

crazytonyli commented Feb 3, 2026

@dcalhoun I have integrated this PR in wordpress-mobile/WordPress-iOS#25208

if (
options.path === disabledPath ||
options.path?.startsWith( `${ disabledPath }?` )
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I imagine the reason it only showcased itself intermittently is due to a race condition.

This change makes sense given we intentionally disable API requests for entity content since we seed the title and content from the native host app.

@dcalhoun
Copy link
Member

dcalhoun commented Feb 3, 2026

I'll also a note couple of oddities, but I believe they are not strictly related to these changes.

When switching post types...

  • The preloading status note never resets.
  • The editor incorrectly hides the progress bar when opening.

Ideally, both of these reset when switching post types as we need to fetch the newly selected post type.

@crazytonyli
Copy link
Contributor Author

@dcalhoun Thanks for finding all those issues. The demo app should be in a better shape now. 🤞

Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest changes worked well for me. 🚀

The only remaining demo app oddity I encountered is that the Local Caches section intermittently gets stuck in a loading state. I'm unsure of the reproduction steps. However, I can reproduce this on the trunk branch, so I believe it is independent of the proposed changes.

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.

2 participants