WordPress.org

Make WordPress Core

Ticket #20419: 20419.2012-08-05.patch

File 20419.2012-08-05.patch, 8.5 KB (added by mintindeed, 21 months ago)
  • wp-includes/post.php

     
    26192619        if ( !isset($post_password) || 'private' == $post_status ) 
    26202620                $post_password = ''; 
    26212621 
    2622         $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); 
    2623  
    26242622        // expected_slashed (everything!) 
    26252623        $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 
    26262629        $data = apply_filters('wp_insert_post_data', $data, $postarr); 
    26272630        $data = stripslashes_deep( $data ); 
    26282631        $where = array( 'ID' => $post_ID ); 
     
    28392842 * 
    28402843 * @global wpdb $wpdb 
    28412844 * @global WP_Rewrite $wp_rewrite 
    2842  * @param string $slug the desired slug (post_name) 
    2843  * @param integer $post_ID 
    2844  * @param string $post_status no uniqueness checks are made if the post is still draft or pending 
    2845  * @param string $post_type 
    2846  * @param integer $post_parent 
     2845 * @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 
    28472850 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 
    28482851 */ 
    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; 
     2852function 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' ); 
    28522855 
     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 
    28532872        global $wpdb, $wp_rewrite; 
    28542873 
    2855         $original_slug = $slug; 
     2874        $original_slug = $post->post_name; 
    28562875 
    28572876        $feeds = $wp_rewrite->feeds; 
    28582877        if ( ! is_array( $feeds ) ) 
    28592878                $feeds = array(); 
    28602879 
    28612880        $hierarchical_post_types = get_post_types( array('hierarchical' => true) ); 
    2862         if ( 'attachment' == $post_type ) { 
     2881        if ( 'attachment' == $post->post_type ) { 
    28632882                // Attachment slugs must be unique across all types. 
    28642883                $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 ) ); 
    28662885 
    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 ) ) { 
    28682887                        $suffix = 2; 
    28692888                        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 ) ); 
    28722891                                $suffix++; 
    28732892                        } while ( $post_name_check ); 
    2874                         $slug = $alt_post_name; 
     2893                        $post->post_name = $alt_post_name; 
    28752894                } 
    2876         } elseif ( in_array( $post_type, $hierarchical_post_types ) ) { 
     2895        } elseif ( in_array( $post->post_type, $hierarchical_post_types ) ) { 
    28772896                // Page slugs must be unique within their own trees. Pages are in a separate 
    28782897                // namespace than posts so page slugs are allowed to overlap post slugs. 
    28792898                $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 ) ); 
    28812900 
    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 ) ) { 
    28832902                        $suffix = 2; 
    28842903                        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 ) ); 
    28872906                                $suffix++; 
    28882907                        } while ( $post_name_check ); 
    2889                         $slug = $alt_post_name; 
     2908                        $post->post_name = $alt_post_name; 
    28902909                } 
    28912910        } else { 
    28922911                // Post slugs must be unique across all posts. 
    28932912                $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 ) ); 
    28952914 
    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 ) ) { 
    28972916                        $suffix = 2; 
    28982917                        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 ) ); 
    29012920                                $suffix++; 
    29022921                        } while ( $post_name_check ); 
    2903                         $slug = $alt_post_name; 
     2922                        $post->post_name = $alt_post_name; 
    29042923                } 
    29052924        } 
    29062925 
    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 ); 
    29082927} 
    29092928 
    29102929/** 
     
    37183737                $post_name = sanitize_title($post_name); 
    37193738 
    37203739        // 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 ) ); 
    37223741 
    37233742        if ( empty($post_date) ) 
    37243743                $post_date = current_time('mysql'); 
  • wp-admin/includes/post.php

     
    10341034        if ( !is_null($name) ) 
    10351035                $post->post_name = sanitize_title($name ? $name : $title, $post->ID); 
    10361036 
    1037         $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent); 
    1038  
    10391037        $post->filter = 'sample'; 
    10401038 
     1039        $post->post_name = wp_unique_post_slug( $post ); 
     1040 
    10411041        $permalink = get_permalink($post, true); 
    10421042 
    10431043        // Replace custom post_type Token with generic pagename token for ease of use.