Ticket #21112: 21112.2.diff
File 21112.2.diff, 2.1 KB (added by , 10 years ago) |
---|
-
src/wp-includes/post.php
3665 3665 if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) 3666 3666 return $slug; 3667 3667 3668 /** 3669 * Filter to allow setting the unique post slug before it is generated. 3670 * 3671 * Returning a non-empty value will preempt unique slug detection and 3672 * generation and will result in that value being used as the post's slug. 3673 * 3674 * @since 4.1 3675 * 3676 * @param string $default_slug The default post slug. Default empty. 3677 * @param string $slug The desired slug (post_name). 3678 * @param int $post_ID Post ID. 3679 * @param string $post_status The post status. 3680 * @param string $post_type Post type. 3681 * @param int $post_parent Post parent ID 3682 */ 3683 $override_slug = apply_filters( 'pre_wp_unique_post_slug', '', $slug, $post_ID, $post_status, $post_type, $post_parent ); 3684 if ( $override_slug ) { 3685 return $override_slug; 3686 } 3687 3668 3688 global $wpdb, $wp_rewrite; 3669 3689 3670 3690 $original_slug = $slug; -
tests/phpunit/tests/post.php
1016 1016 _unregister_post_type( 'post-type-1' ); 1017 1017 _unregister_post_type( 'post-type-2' ); 1018 1018 } 1019 1020 function test_pre_wp_unique_post_slug_filter() { 1021 add_filter( 'pre_wp_unique_post_slug', array( $this, 'filter_pre_wp_unique_post_slug' ), 10, 6 ); 1022 1023 $post_id = $this->factory->post->create( array( 'title' => 'An example', 'post_status' => 'publish', 'post_type' => 'page' ) ); 1024 $post = get_post( $post_id ); 1025 1026 $this->assertEquals( 'override-slug-' . $post->post_type, $post->post_name ); 1027 1028 remove_filter( 'pre_wp_unique_post_slug', array( $this, 'filter_pre_wp_unique_post_slug' ), 10, 6 ); 1029 } 1030 1031 function filter_pre_wp_unique_post_slug( $default, $slug, $post_ID, $post_status, $post_type, $post_parent ) { 1032 return 'override-slug-' . $post_type; 1033 } 1034 1019 1035 }