Index: src/wp-includes/post.php
===================================================================
--- src/wp-includes/post.php	(revision 30243)
+++ src/wp-includes/post.php	(working copy)
@@ -3665,6 +3665,26 @@
 	if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) )
 		return $slug;
 
+	/**
+	 * Filter to allow setting the unique post slug before it is generated.
+	 *
+	 * Returning a non-empty value will preempt unique slug detection and
+	 * generation and will result in that value being used as the post's slug.
+	 *
+	 * @since 4.1
+	 *
+	 * @param string $default_slug  The default post slug. Default empty.
+	 * @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', '', $slug, $post_ID, $post_status, $post_type, $post_parent );
+	if ( $override_slug ) {
+		return $override_slug;
+	}
+
 	global $wpdb, $wp_rewrite;
 
 	$original_slug = $slug;
Index: tests/phpunit/tests/post.php
===================================================================
--- tests/phpunit/tests/post.php	(revision 30243)
+++ tests/phpunit/tests/post.php	(working copy)
@@ -1016,4 +1016,20 @@
 		_unregister_post_type( 'post-type-1' );
 		_unregister_post_type( 'post-type-2' );
 	}
+
+	function test_pre_wp_unique_post_slug_filter() {
+		add_filter( 'pre_wp_unique_post_slug', array( $this, 'filter_pre_wp_unique_post_slug' ), 10, 6 );
+
+		$post_id = $this->factory->post->create( array( 'title' => 'An example', 'post_status' => 'publish', 'post_type' => 'page' ) );
+		$post = get_post( $post_id );
+
+		$this->assertEquals( 'override-slug-' . $post->post_type, $post->post_name );
+
+		remove_filter( 'pre_wp_unique_post_slug', array( $this, 'filter_pre_wp_unique_post_slug' ), 10, 6 );
+	}
+
+	function filter_pre_wp_unique_post_slug( $default, $slug, $post_ID, $post_status, $post_type, $post_parent ) {
+		return 'override-slug-' . $post_type;
+	}
+
 }
