Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooking in to publish action from share extension? #10742

Closed
ChrisHardie opened this issue Jan 3, 2019 · 10 comments
Closed

Hooking in to publish action from share extension? #10742

ChrisHardie opened this issue Jan 3, 2019 · 10 comments

Comments

@ChrisHardie
Copy link

Expected behavior

For a WordPress theme with custom functionality that hooks into post status transitions (e.g. draft to publish), I expect that post publishing actions taken by the mobile app would trigger the same actions.

Actual behavior

Posts created via the iOS share extension do not seem to trigger any of the usual post status transitions, and so the related theme functionality is never called.

Steps to reproduce the behavior

I've tried hooking in to:

  • publish_post
  • draft_to_publish
  • new_to_publish
  • pending_to_publish
  • future_to_publish

and none of them seem to work. My current workaround is to publish the post via the app, then edit via wp-admin and change from Published to Draft and then back to Published.

I see a similar question was asked in #4053 but it would be great to get some more clarity here.

Tested on [device], iOS [version], WPiOS [version]

Tested on an iPhone XR using iOS 12.1.2 and WPiOS 11.4.1.

@rachelmcr
Copy link
Member

cc @aerych as you answered the previous issue mentioned here.

@aerych
Copy link
Member

aerych commented Jan 4, 2019

Hey @ChrisHardie.

The share extension publishes a new post by calling https://public-api.wordpress.com/rest/v1.1/sites/site/posts/new API endpoint (docs) specifying a post status of "publish". I'm not too familiar with the available post status transition hooks or how they work, but my guess would be you're not seeing them fired because the post never transitions from one status to another -- its created with the publish status.

The publish_post hook, just by its name, suggests that it should be triggered (should it?) and if its not then I'd probably take a look into the endpoint code to see if there is some kind of oversight there.

Not sure if this is helpful. Let me know.

@ChrisHardie
Copy link
Author

Thanks @aerych - from what I can tell in inspecting traffic between the mobile app and the self-hosted site, everything is being done via XMLRPC, not via the REST API. The post publish action seems to call <methodName>metaWeblog.newPost</methodName> in the XMLRPC request, with a post_status value of publish.

Obviously the REST API would be preferred but it sounds like XMLRPC is still in place for self-hosted sites for now? Given that, should we keep pursuing why that method apparently doesn't call the publish_post action?

Also ccing @jackmcconnell in case you can shed light on the solution you found in the other thread.

@jackmcconnell
Copy link

@ChrisHardie I didn't find a solution in the end. Hoping that the REST API will provide a better solution in the future as inserting a post directly via XML-RPC without passing it through many of the post publish hooks will probably cause issues for many plugins, BNFW included.

@aerych
Copy link
Member

aerych commented Jan 7, 2019

Thanks @aerych - from what I can tell in inspecting traffic between the mobile app and the self-hosted site, everything is being done via XMLRPC, not via the REST API.

Hey @ChrisHardie. The issue description mentioned Posts created via the iOS share extension so I tailored my reply accordingly. The share extension is only available to sites that can use the WordPress.com REST API. Self-hosted sites would need to be Jetpack connected to use the extension. We actually have an issue to add self-hosted support but we haven't gotten around to it yet.

But you're right, the XML-RPC API is used for self-hosted sites that are not connected to Jetpack, and its using the deprecated metaWeblog.newPost call. If the self-hosted site has the Jetpack plugin connected then the app will use the WordPress.com REST API instead.

@aerych
Copy link
Member

aerych commented Jan 7, 2019

@ChrisHardie @jackmcconnell Do the v2 REST endpoints for publishing and modifying posts trigger the hooks as expected?

@ChrisHardie
Copy link
Author

Just noting again that for now, based on my web server logs, it does seem that the file upload is happening via XML-RPC and not REST endpoints. This is a self-hosted site connected via Jetpack. All of the calls look like POST /xmlrpc.php?for=jetpack - I don't see any calls to the REST API.

@aerych
Copy link
Member

aerych commented Feb 7, 2019

based on my web server logs

@ChrisHardie is this how you've been inspecting network traffic between the app and the self-hosted site, or have you been using something like Charles Proxy to view traffic?

WordPress.com's REST API makes calls to Jetpack connected blog via the xmlrpc.php?for=jetpack path. I would expect to see these calls from any interaction with a self-hosted site via Calypso, OR from calls the apps make to the WordPress.com REST API that are proxied to the Jetpack connected self-hosted site. The apps do not make any direct queries to xmlrpc.php?for=jetpack.

@aerych
Copy link
Member

aerych commented Feb 7, 2019

Based on the above, its looking like the issue has more to do with the interaction between the WordPress.com API and a Jetpack connected blog and not something specific to the app. If this is the case I think we close the issue here and follow up with the Jetpack team to see what options there might be.
@ChrisHardie what do you think?

@ChrisHardie
Copy link
Author

Hi. I re-architected my solution and am happy to report that hooking in to rest_api_inserted_post now seems to work correctly (for content shared via the mobile app share extension to a self-hosted site connected via Jetpack).

We can close this issue - thank you for your time on it.

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

No branches or pull requests

4 participants