aaroneaton / better-yourls

Source code for the Better YOURLS WordPress plugin
21 stars 6 forks source link

[Request] Create/retrieve missing shortlinks for published posts #5

Open dgw opened 8 years ago

dgw commented 8 years ago

On my installation (WP 4.3.1 with Better YOURLS 2.0), old posts without shortlinks have /?p=1234 in the shortlink header tag. I've manually edited the postmeta table to move existing shorturls from old posts that had them generated by other plugins, but there are still several hundred that don't have YOURLS links.

I propose that Better YOURLS generate or retrieve a shortlink from the configured YOURLS instance if a post is viewed but doesn't have a shortlink.

Obviously this introduces the potential for the YOURLS instance delaying page load while the plugin waits for an API response. One mitigation option is to have the plugin only wait a couple seconds at most for YOURLS to return a shortlink. Ideally it would complete the request no matter what, even if it lets the page continue to load—but WordPress might not be able to do that. At worst, the plugin can simply try again the next time the post is requested.

The main alternative I can think of is to backfill shortlinks in a background job, the way, say, Broken Link Checker processes URLs—but that sounds a LOT more complicated to program. Since each post only needs to have a shortlink fetched/generated once, it's probably not worth the effort to code up background workers or wp-cron jobs.

Thoughts?

ChrisWiegman commented 8 years ago

I think this can work, but I need to look at what hook would be most appropriate.

ChrisWiegman commented 8 years ago

Looking at this I can't help but think it should be doing this (some of the filters will fire on front-page load). The exception here would be if the page had been cached. I look at my own instance and the history of generation (it takes a few weeks but all posts eventually appear) as evidence that this is happening. Is this not the case on your site?