ActionScheduler_wpPostStore::set_unique_post_slug()publicWC 1.0

Create a (probably unique) post name for scheduled actions in a more performant manner than wp_unique_post_slug().

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 for plugins to address this issue.

We can short-circuit WordPress's wp_unique_post_slug() approach using the pre_wp_unique_post_slug 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:

Метод класса: ActionScheduler_wpPostStore{}

Хуков нет.

Возвращает

Строку.

Использование

$ActionScheduler_wpPostStore = new ActionScheduler_wpPostStore();
$ActionScheduler_wpPostStore->set_unique_post_slug( $override_slug, $slug, $post_ID, $post_status, $post_type );
$override_slug(строка) (обязательный)
Short-circuit return value.
$slug(строка) (обязательный)
The desired slug (post_name).
$post_ID(int) (обязательный)
Post ID.
$post_status(строка) (обязательный)
The post status.
$post_type(строка) (обязательный)
Post type.

Код ActionScheduler_wpPostStore::set_unique_post_slug() WC 8.7.0

public function set_unique_post_slug( $override_slug, $slug, $post_ID, $post_status, $post_type ) {
	if ( self::POST_TYPE === $post_type ) {
		$override_slug = uniqid( self::POST_TYPE . '-', true ) . '-' . wp_generate_password( 32, false );
	}
	return $override_slug;
}