Ticket #20419: 20419-post-obj.patch
File 20419-post-obj.patch, 5.3 KB (added by , 12 years ago) |
---|
-
wp-includes/post.php
2826 2826 * @global wpdb $wpdb 2827 2827 * @global WP_Rewrite $wp_rewrite 2828 2828 * @param string $slug the desired slug (post_name) 2829 * @param integer $post_ID 2830 * @param string $post_status no uniqueness checks are made if the post is still draft or pending 2829 * @param integer|obj $post Either a post ID or post object. Uniqueness 2830 * checks are only made if post status is "publish" 2831 * @param string $deprecated 2831 2832 * @param string $post_type 2832 2833 * @param integer $post_parent 2833 2834 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 2834 2835 */ 2835 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { 2836 if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) 2836 function wp_unique_post_slug( $slug, $post, $deprecated, $post_type, $post_parent ) { 2837 if ( $deprecated ) 2838 _deprecated_argument( __FUNCTION__, '3.5' ); 2839 2840 if ( isset($post->post_status) ) { 2841 $post_status = $post->post_status; 2842 } else { 2843 // Convert expected $post object to $post->ID for backwards compatability 2844 $post = array( 'ID' => $post ); 2845 $post = (object) $post; 2846 } 2847 2848 if ( 'publish' === ( $deprecated || $post->post_status ) ) 2837 2849 return $slug; 2838 2850 2839 2851 global $wpdb, $wp_rewrite; … … 2848 2860 if ( 'attachment' == $post_type ) { 2849 2861 // Attachment slugs must be unique across all types. 2850 2862 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; 2851 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post _ID ) );2863 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post->ID ) ); 2852 2864 2853 2865 if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) { 2854 2866 $suffix = 2; 2855 2867 do { 2856 2868 $alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2857 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post _ID ) );2869 $post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post->ID ) ); 2858 2870 $suffix++; 2859 2871 } while ( $post_name_check ); 2860 2872 $slug = $alt_post_name; … … 2863 2875 // Page slugs must be unique within their own trees. Pages are in a separate 2864 2876 // namespace than posts so page slugs are allowed to overlap post slugs. 2865 2877 $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"; 2866 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post _ID, $post_parent ) );2878 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post->ID, $post_parent ) ); 2867 2879 2868 2880 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 ) ) { 2869 2881 $suffix = 2; 2870 2882 do { 2871 2883 $alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; 2872 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post _ID, $post_parent ) );2884 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post->ID, $post_parent ) ); 2873 2885 $suffix++; 2874 2886 } while ( $post_name_check ); 2875 2887 $slug = $alt_post_name; … … 2877 2889 } else { 2878 2890 // Post slugs must be unique across all posts. 2879 2891 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; 2880 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post _ID ) );2892 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post->ID ) ); 2881 2893 2882 2894 if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) { 2883 2895 $suffix = 2; 2884 2896 do { 2885 2897 $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_type, $post _ID ) );2898 $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post->ID ) ); 2887 2899 $suffix++; 2888 2900 } while ( $post_name_check ); 2889 2901 $slug = $alt_post_name; 2890 2902 } 2891 2903 } 2892 2904 2893 return apply_filters( 'wp_unique_post_slug', $slug, $post _ID, $post_status, $post_type, $post_parent, $original_slug );2905 return apply_filters( 'wp_unique_post_slug', $slug, $post->ID, $post->post_status, $post_type, $post_parent, $original_slug ); 2894 2906 } 2895 2907 2896 2908 /** -
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);1037 $post->post_name = wp_unique_post_slug( $post->post_name, $post->post_status, $deprecated, $post->post_type, $post->post_parent, $post ); 1038 1038 1039 1039 $post->filter = 'sample'; 1040 1040