From 1b389ea861a9b97d3cc40b5f474edae602986e88 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Tue, 8 Jan 2019 03:47:49 +0000 Subject: [PATCH] Permalinks: Add a `pre_wp_unique_post_slug` filter. Returning a non-`null` value on this fillter will cause `wp_unique_post_slug()` to return early with that value, skipping potentially expensive database queries on some sites. Props coffee2code, javorszky, iCaleb. Fixes #21112. Built from https://develop.svn.wordpress.org/trunk@44454 git-svn-id: http://core.svn.wordpress.org/trunk@44285 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 20 ++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 8debd3db3b..f3696341da 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -4117,6 +4117,26 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p return $slug; } + /** + * Filters the post slug before it is generated to be unique. + * + * Returning a non-null value will short-circuit the + * unique slug generation, returning the passed value instead. + * + * @since 5.1.0 + * + * @param string $override_slug Short-circuit return value. + * @param string $slug The desired slug (post_name). + * @param int $post_ID Post ID. + * @param string $post_status The post status. + * @param string $post_type Post type. + * @param int $post_parent Post parent ID. + */ + $override_slug = apply_filters( 'pre_wp_unique_post_slug', null, $slug, $post_ID, $post_status, $post_type, $post_parent ); + if ( null !== $override_slug ) { + return $override_slug; + } + global $wpdb, $wp_rewrite; $original_slug = $slug; diff --git a/wp-includes/version.php b/wp-includes/version.php index fc1ba44dd4..755fba3ea2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-44453'; +$wp_version = '5.1-alpha-44454'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.