ActionScheduler_wpPostStore::set_unique_post_slug( string $override_slug, string $slug, int $post_ID, string $post_status, string $post_type )
Create a (probably unique) post name for scheduled actions in a more performant manner than wp_unique_post_slug().
Description Description
When an action’s post status is transitioned to something other than ‘draft’, ‘pending’ or ‘auto-draft, like ‘publish’ or ‘failed’ or ‘trash’, WordPress will find a unique slug (stored in post_name column) using the wp_unique_post_slug() function. This is done to ensure URL uniqueness. The approach taken by wp_unique_post_slug() is to iterate over existing post_name values that match, and append a number 1 greater than the largest. This makes sense when manually creating a post from the Edit Post screen. It becomes a bottleneck when automatically processing thousands of actions, with a database containing thousands of related post_name values.
WordPress 5.1 introduces the ‘pre_wp_unique_post_slug’ filter for plugins to address this issue.
We can short-circuit WordPress’s wp_unique_post_slug() approach using the ‘pre_wp_unique_post_slug’ filter. This method is available to be used as a callback on that filter. It provides a more scalable approach to generating a post_name/slug that is probably unique. Because Action Scheduler never actually uses the post_name field, or an action’s slug, being probably unique is good enough.
For more backstory on this issue, see:
Parameters Parameters
- $override_slug
-
(Required) Short-circuit return value.
- $slug
-
(Required) The desired slug (post_name).
- $post_ID
-
(Required) Post ID.
- $post_status
-
(Required) The post status.
- $post_type
-
(Required) Post type.
Return Return
(string)
Source Source
File: packages/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php