As part of our work to improve sharing into the app, we can implement URL scheme support for creating new posts and pages.
We should follow the x-callback-url specification common on iOS. Here’s a first proposal at how this could look:
Endpoint
/new
(Potentially also /new-post
and /new-page
?)
Opens the editor, with some content pre-populated specified by the parameters below.
Parameters
title
(optional) Title of the postcontent
(optional) Post body text contentsite_name
(optional) Site name we could use to match against the user’s list of sites. If one matches, we’ll pop the editor for that site, otherwise we’ll use the default site. The UniversalLinkRouter
in the app already can handle this – see NewPostForSiteRoute
, NewPostNavigationAction
, and NavigationActionHelpers
.format
(optional) Format of the post content provided. Allowed values are text
, markdown
, html
?Optional extras
I think we should just ship the above first and then look at usage to assess whether to extend this feature. If we did extend it, we could look at adding parameters for other post metadata such as:
tags
(optional) Comma-separated list of tags to apply to the post.categories
(optional) Comma-separated list of categories to apply to the post.post_format
(optional) We’d attempt to match this to a post format on the site, such as aside
.slug
(optional) Post URL slugexcerpt
(optional) Post excerptis_sticky
(optional) true
or false
scheduled
(optional) If a valid ISO8601 date is provided, schedule the post for that date.visibility
(optional) public
or private
status
(optional) published
or draft
Example
wordpress://x-callback-url/new?title=My%20Awesome%20Post&content=My%20post&site_name=Stay%20Frosty&format=text
I dug up our previous implementation: https://github.com/wordpress-mobile/WordPress-iOS/blob/d89b7ec712be1f2e11fb1228089771a25f5587c5/WordPress/Classes/ViewRelated/System/WPTabBarController.m#L388
My preference would be to make the new version compatible with the old one, since it's apparently still in use (or would be 😉)
This means naming the endpoint newpost
. We could, of course, support multiple names 😀
The old endpoint also supported parameters for tags
, and image
, although I'm not yet sure what format the image
param took. If the code is easy to resurrect, then I will, otherwise I'll probably leave media out of this version with the thought that media support may work better in the share extension, or that future support for TextBundle
may be a better fit.
Nice detective work :) It looks like the image handling was simply taking a URL to an image and using it to populate an <img>
tag – I think that's probably not worth resurrecting.
x-callback-url
are great for automatization (Siri shortcuts, etc..), but not ideal for improving sharing from other apps as they'll need to implement custom code only for WordPress instead of just using the iOS share extension.
Said so, I can't imagine WordPress posts without images, so adding them to the parameters would be awesome. Using url parameters the only options is to base64 encode the images, but it should work just fine.
In our app Bear we're already using the base64 encoding to allows image inserting, if you need any info I'll be happy to provide these.
Most helpful comment
x-callback-url
are great for automatization (Siri shortcuts, etc..), but not ideal for improving sharing from other apps as they'll need to implement custom code only for WordPress instead of just using the iOS share extension.Said so, I can't imagine WordPress posts without images, so adding them to the parameters would be awesome. Using url parameters the only options is to base64 encode the images, but it should work just fine.
In our app Bear we're already using the base64 encoding to allows image inserting, if you need any info I'll be happy to provide these.