Ticket #20419: 20419.2012-08-05.patch
File 20419.2012-08-05.patch, 8.5 KB (added by , 13 years ago) |
---|
-
wp-includes/post.php
2619 2619 if ( !isset($post_password) || 'private' == $post_status ) 2620 2620 $post_password = ''; 2621 2621 2622 $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);2623 2624 2622 // expected_slashed (everything!) 2625 2623 $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' ) ); 2624 2625 $sample_data = clone( (object) $data ); 2626 $sample_data->ID = $post_ID; 2627 $data['post_name'] = wp_unique_post_slug( $sample_data ); 2628 2626 2629 $data = apply_filters('wp_insert_post_data', $data, $postarr); 2627 2630 $data = stripslashes_deep( $data ); 2628 2631 $where = array( 'ID' => $post_ID ); … … 2839 2842 * 2840 2843 * @global wpdb $wpdb 2841 2844 * @global WP_Rewrite $wp_rewrite 2842 * @param string$slug the desired slug (post_name)2843 * @param integer $ post_ID2844 * @param string $ post_status no uniqueness checks are made if the post is still draft or pending2845 * @param string $ post_type2846 * @param integer $ post_parent2845 * @param obj $slug the desired slug (post_name) 2846 * @param integer $deprecated_post_ID 2847 * @param string $deprecated_post_status 2848 * @param string $deprecated_post_type 2849 * @param integer $deprecated_post_parent 2847 2850 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 2848 2851 */ 2849 function wp_unique_post_slug( $ slug, $post_ID, $post_status, $post_type, $post_parent) {2850 if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ))2851 return $slug;2852 function wp_unique_post_slug( $post, $deprecated_post_ID = null, $deprecated_post_status = null, $deprecated_post_type = null, $deprecated_post_parent = null ) { 2853 if ( $deprecated_post_ID || $deprecated_post_status || $deprecated_post_type || $deprecated_post_parent ) 2854 _deprecated_argument( __FUNCTION__, '3.5' ); 2852 2855 2856 if ( ! is_object($post) ) { 2857 _doing_it_wrong( __FUNCTION__, _('This function expects a post object as its only parameter.'), '3.5' ); 2858 $post = array( 2859 'ID' => $deprecated_post_ID, 2860 'post_name' => $post, // used to be $post->post_name 2861 'post_status' => $deprecated_post_status, 2862 'post_type' => $deprecated_post_type, 2863 'post_parent' => $deprecated_post_parent, 2864 ); 2865 $post = (object) $post; 2866 } 2867 2868 if ( 'publish' === $post->post_status 2869 && ( ! isset($post->filter) || 'sample' !== $post->filter ) ) 2870 return $post->post_name; 2871 2853 2872 global $wpdb, $wp_rewrite; 2854 2873 2855 $original_slug = $ slug;2874 $original_slug = $post->post_name; 2856 2875 2857 2876 $feeds = $wp_rewrite->feeds; 2858 2877 if ( ! is_array( $feeds ) ) 2859 2878 $feeds = array(); 2860 2879 2861 2880 $hierarchical_post_types = get_post_types( array('hierarchical' => true) ); 2862 if ( 'attachment' == $post _type ) {2881 if ( 'attachment' == $post->post_type ) { 2863 2882 // Attachment slugs must be unique across all types. 2864 2883 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; 2865 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $ slug, $post_ID ) );2884 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $post->post_name, $post->ID ) ); 2866 2885 2867 if ( $post_name_check || in_array( $ slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug) ) {2886 if ( $post_name_check || in_array( $post->post_name, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $post->post_name ) ) { 2868 2887 $suffix = 2; 2869 2888 do { 2870 $alt_post_name = substr ($ slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";2871 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post _ID ) );2889 $alt_post_name = substr ($post->post_name, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2890 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post->ID ) ); 2872 2891 $suffix++; 2873 2892 } while ( $post_name_check ); 2874 $ slug= $alt_post_name;2893 $post->post_name = $alt_post_name; 2875 2894 } 2876 } elseif ( in_array( $post _type, $hierarchical_post_types ) ) {2895 } elseif ( in_array( $post->post_type, $hierarchical_post_types ) ) { 2877 2896 // Page slugs must be unique within their own trees. Pages are in a separate 2878 2897 // namespace than posts so page slugs are allowed to overlap post slugs. 2879 2898 $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"; 2880 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $ slug, $post_ID, $post_parent ) );2899 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $post->post_name, $post->ID, $post_parent ) ); 2881 2900 2882 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 ) ) {2901 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_parent ) ) { 2883 2902 $suffix = 2; 2884 2903 do { 2885 $alt_post_name = substr( $ slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";2886 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post _ID, $post_parent ) );2904 $alt_post_name = substr( $post->post_name, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2905 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->ID, $post_parent ) ); 2887 2906 $suffix++; 2888 2907 } while ( $post_name_check ); 2889 $ slug= $alt_post_name;2908 $post->post_name = $alt_post_name; 2890 2909 } 2891 2910 } else { 2892 2911 // Post slugs must be unique across all posts. 2893 2912 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 2894 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $ slug, $post_type, $post_ID ) );2913 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $post->post_name, $post->post_type, $post->ID ) ); 2895 2914 2896 if ( $post_name_check || in_array( $ slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {2915 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 ) ) { 2897 2916 $suffix = 2; 2898 2917 do { 2899 $alt_post_name = substr( $ slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";2900 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post _type, $post_ID ) );2918 $alt_post_name = substr( $post->post_name, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2919 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->post_type, $post->ID ) ); 2901 2920 $suffix++; 2902 2921 } while ( $post_name_check ); 2903 $ slug= $alt_post_name;2922 $post->post_name = $alt_post_name; 2904 2923 } 2905 2924 } 2906 2925 2907 return apply_filters( 'wp_unique_post_slug', $ slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug );2926 return apply_filters( 'wp_unique_post_slug', $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent, $original_slug ); 2908 2927 } 2909 2928 2910 2929 /** … … 3718 3737 $post_name = sanitize_title($post_name); 3719 3738 3720 3739 // expected_slashed ($post_name) 3721 $post_name = wp_unique_post_slug( $post_name, $post_ID, $post_status, $post_type, $post_parent);3740 $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 ) ); 3722 3741 3723 3742 if ( empty($post_date) ) 3724 3743 $post_date = current_time('mysql'); -
wp-admin/includes/post.php
1034 1034 if ( !is_null($name) ) 1035 1035 $post->post_name = sanitize_title($name ? $name : $title, $post->ID); 1036 1036 1037 $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);1038 1039 1037 $post->filter = 'sample'; 1040 1038 1039 $post->post_name = wp_unique_post_slug( $post ); 1040 1041 1041 $permalink = get_permalink($post, true); 1042 1042 1043 1043 // Replace custom post_type Token with generic pagename token for ease of use.