Ticket #20419: 20419.diff
File 20419.diff, 9.0 KB (added by , 11 years ago) |
---|
-
wp-admin/includes/post.php
diff --git wp-admin/includes/post.php wp-admin/includes/post.php index aecc433..2abafb8 100644
function get_sample_permalink($id, $title = null, $name = null) { 1017 1017 if ( !is_null($name) ) 1018 1018 $post->post_name = sanitize_title($name ? $name : $title, $post->ID); 1019 1019 1020 $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);1021 1022 1020 $post->filter = 'sample'; 1023 1021 1022 $post->post_name = wp_unique_post_slug( $post ); 1023 1024 1024 $permalink = get_permalink($post, true); 1025 1025 1026 1026 // Replace custom post_type Token with generic pagename token for ease of use. -
wp-includes/post.php
diff --git wp-includes/post.php wp-includes/post.php index 4179e7f..5747455 100644
function wp_insert_post($postarr, $wp_error = false) { 2787 2787 if ( !isset($post_password) || 'private' == $post_status ) 2788 2788 $post_password = ''; 2789 2789 2790 $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);2791 2792 2790 // expected_slashed (everything!) 2793 2791 $data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid' ) ); 2794 $data = apply_filters('wp_insert_post_data', $data, $postarr); 2792 2793 $sample_data = clone( (object) $data ); 2794 $sample_data->ID = $post_ID; 2795 $data['post_name'] = wp_unique_post_slug( $sample_data ); 2796 2797 $data = apply_filters( 'wp_insert_post_data', $data, $postarr ); 2795 2798 $data = wp_unslash( $data ); 2796 2799 $where = array( 'ID' => $post_ID ); 2797 2800 … … function check_and_publish_future_post($post_id) { 3012 3015 * 3013 3016 * @global wpdb $wpdb 3014 3017 * @global WP_Rewrite $wp_rewrite 3015 * @param string$slug the desired slug (post_name)3016 * @param integer $ post_ID3017 * @param string $ post_status no uniqueness checks are made if the post is still draft or pending3018 * @param string $ post_type3019 * @param integer $ post_parent3018 * @param object $slug the desired slug (post_name) 3019 * @param integer $deprecated_post_ID 3020 * @param string $deprecated_post_status no uniqueness checks are made if the post is still draft or pending 3021 * @param string $deprecated_post_type 3022 * @param integer $deprecated_post_parent 3020 3023 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 3021 3024 */ 3022 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { 3023 if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) ) 3024 return $slug; 3025 function wp_unique_post_slug( $post, $deprecated_post_ID = null, $deprecated_post_status = null, $deprecated_post_type = null, $deprecated_post_parent = null ) { 3026 if ( $deprecated_post_ID || $deprecated_post_status || $deprecated_post_type || $deprecated_post_parent ) 3027 _deprecated_argument( __FUNCTION__, '3.7' ); 3028 3029 if ( ! is_object( $post ) ) { 3030 _doing_it_wrong( __FUNCTION__, _( 'This function expects a post object as its only parameter.' ), '3.7' ); 3031 $_post = array( 3032 'ID' => $deprecated_post_ID, 3033 'post_name' => $_post, // used to be $post->post_name 3034 'post_status' => $deprecated_post_status, 3035 'post_type' => $deprecated_post_type, 3036 'post_parent' => $deprecated_post_parent, 3037 ); 3038 $post = (object) $_post; 3039 } 3040 3041 if ( 'publish' === $post->post_status && ( ! isset( $post->filter ) || 'sample' !== $post->filter ) ) 3042 return $post->post_name; 3025 3043 3026 3044 global $wpdb, $wp_rewrite; 3027 3045 3028 $original_slug = $ slug;3046 $original_slug = $post->post_name; 3029 3047 3030 3048 $feeds = $wp_rewrite->feeds; 3031 3049 if ( ! is_array( $feeds ) ) 3032 3050 $feeds = array(); 3033 3051 3034 3052 $hierarchical_post_types = get_post_types( array('hierarchical' => true) ); 3035 if ( 'attachment' == $post_type ) {3053 if ( 'attachment' === $post->post_type ) { 3036 3054 // Attachment slugs must be unique across all types. 3037 3055 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; 3038 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $ slug, $post_ID ) );3056 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $post->post_name, $post->ID ) ); 3039 3057 3040 if ( $post_name_check || in_array( $ slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug) ) {3058 if ( $post_name_check || in_array( $post->post_name, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $post->post_name ) ) { 3041 3059 $suffix = 2; 3042 3060 do { 3043 $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";3044 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post _ID ) );3061 $alt_post_name = substr( $post->post_name, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3062 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->ID ) ); 3045 3063 $suffix++; 3046 3064 } while ( $post_name_check ); 3047 $slug = $alt_post_name; 3065 3066 $post->post_name = $alt_post_name; 3048 3067 } 3049 } elseif ( in_array( $post _type, $hierarchical_post_types ) ) {3050 if ( 'nav_menu_item' == $post_type )3051 return $ slug;3068 } elseif ( in_array( $post->post_type, $hierarchical_post_types ) ) { 3069 if ( 'nav_menu_item' === $post->post_type ) 3070 return $post->post_name; 3052 3071 // Page slugs must be unique within their own trees. Pages are in a separate 3053 3072 // namespace than posts so page slugs are allowed to overlap post slugs. 3054 3073 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d LIMIT 1"; 3055 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $ slug, $post_ID, $post_parent ) );3074 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $post->post_name, $post->ID, $post->post_parent ) ); 3056 3075 3057 if ( $post_name_check || in_array( $ slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {3076 if ( $post_name_check || in_array( $post->post_name, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $post->post_name ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $post->post_name, $post->post_type, $post->post_parent ) ) { 3058 3077 $suffix = 2; 3059 3078 do { 3060 $alt_post_name = _truncate_post_slug( $ slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";3061 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post _ID, $post_parent ) );3079 $alt_post_name = _truncate_post_slug( $post->post_name, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3080 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->ID, $post->post_parent ) ); 3062 3081 $suffix++; 3063 3082 } while ( $post_name_check ); 3064 $ slug= $alt_post_name;3083 $post->post_name = $alt_post_name; 3065 3084 } 3066 3085 } else { 3067 3086 // Post slugs must be unique across all posts. 3068 3087 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 3069 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $ slug, $post_type, $post_ID ) );3088 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $post->post_name, $post->post_type, $post->ID ) ); 3070 3089 3071 if ( $post_name_check || in_array( $ slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {3090 if ( $post_name_check || in_array( $post->post_name, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $post->post_name, $post->post_type ) ) { 3072 3091 $suffix = 2; 3073 3092 do { 3074 $alt_post_name = _truncate_post_slug( $ slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";3075 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post _type, $post_ID ) );3093 $alt_post_name = _truncate_post_slug( $post->post_name, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 3094 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->post_type, $post->ID ) ); 3076 3095 $suffix++; 3077 3096 } while ( $post_name_check ); 3078 $ slug= $alt_post_name;3097 $post->post_name = $alt_post_name; 3079 3098 } 3080 3099 } 3081 3100 3082 return apply_filters( 'wp_unique_post_slug', $ slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug );3101 return apply_filters( 'wp_unique_post_slug', $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent, $original_slug ); 3083 3102 } 3084 3103 3085 3104 /** … … function wp_insert_attachment($object, $file = false, $parent = 0) { 3920 3939 $post_name = sanitize_title($post_name); 3921 3940 3922 3941 // expected_slashed ($post_name) 3923 $post_name = wp_unique_post_slug( $post_name, $post_ID, $post_status, $post_type, $post_parent);3942 $post_name = wp_unique_post_slug( (object) array( 'post_name' => $post_name, 'ID' => $post_ID, 'post_status' => $post_status, 'post_type' => $post_type, 'post_parent' => $post_parent ) ); 3924 3943 3925 3944 if ( empty($post_date) ) 3926 3945 $post_date = current_time('mysql');