Automattic / WPCOM-Legacy-Redirector

WordPress plugin for handling large volumes of legacy redirects in a scalable manner.
20 stars 16 forks source link

Insert redirect: allow return of inserted post ID #100

Closed GaryJones closed 3 years ago

GaryJones commented 3 years ago

The insert_legacy_redirect() method will return "True if inserted; false if not permitted; otherwise error upon validation issue.".

Rather than just returning boolean true when a redirect has been successfully inserted, we can instead return the ID of the entry so that further work may be done with it by other code.

If we updated the true return, then this may break existing === checks. Instead, we add a new param to the method and which can dictate whether true or the post ID is returned on success.

Fixes #99.

GaryJones commented 3 years ago

I am guessing we keep the return_id parameter for backward compatibility?

Yes - it is optional, so existing calls won't break, and the default value of false means the behaviour doesn't change (i.e. returns true on success by default).

For a future major release, we can change this behaviour as a breaking change, since returning a post ID would be checkable as both truthy and being able to use the post ID.