WordPress.org

Make WordPress Core

Ticket #20419: 20419.diff

File 20419.diff, 9.0 KB (added by wonderboymusic, 2 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) { 
    10171017        if ( !is_null($name) ) 
    10181018                $post->post_name = sanitize_title($name ? $name : $title, $post->ID); 
    10191019 
    1020         $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent); 
    1021  
    10221020        $post->filter = 'sample'; 
    10231021 
     1022        $post->post_name = wp_unique_post_slug( $post ); 
     1023 
    10241024        $permalink = get_permalink($post, true); 
    10251025 
    10261026        // 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) { 
    27872787        if ( !isset($post_password) || 'private' == $post_status ) 
    27882788                $post_password = ''; 
    27892789 
    2790         $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent); 
    2791  
    27922790        // expected_slashed (everything!) 
    27932791        $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 ); 
    27952798        $data = wp_unslash( $data ); 
    27962799        $where = array( 'ID' => $post_ID ); 
    27972800 
    function check_and_publish_future_post($post_id) { 
    30123015 * 
    30133016 * @global wpdb $wpdb 
    30143017 * @global WP_Rewrite $wp_rewrite 
    3015  * @param string $slug the desired slug (post_name) 
    3016  * @param integer $post_ID 
    3017  * @param string $post_status no uniqueness checks are made if the post is still draft or pending 
    3018  * @param string $post_type 
    3019  * @param integer $post_parent 
     3018 * @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 
    30203023 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix) 
    30213024 */ 
    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; 
     3025function 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; 
    30253043 
    30263044        global $wpdb, $wp_rewrite; 
    30273045 
    3028         $original_slug = $slug; 
     3046        $original_slug = $post->post_name; 
    30293047 
    30303048        $feeds = $wp_rewrite->feeds; 
    30313049        if ( ! is_array( $feeds ) ) 
    30323050                $feeds = array(); 
    30333051 
    30343052        $hierarchical_post_types = get_post_types( array('hierarchical' => true) ); 
    3035         if ( 'attachment' == $post_type ) { 
     3053        if ( 'attachment' === $post->post_type ) { 
    30363054                // Attachment slugs must be unique across all types. 
    30373055                $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 ) ); 
    30393057 
    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 ) ) { 
    30413059                        $suffix = 2; 
    30423060                        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 ) ); 
    30453063                                $suffix++; 
    30463064                        } while ( $post_name_check ); 
    3047                         $slug = $alt_post_name; 
     3065 
     3066                        $post->post_name = $alt_post_name; 
    30483067                } 
    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; 
    30523071                // Page slugs must be unique within their own trees. Pages are in a separate 
    30533072                // namespace than posts so page slugs are allowed to overlap post slugs. 
    30543073                $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 ) ); 
    30563075 
    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 ) ) { 
    30583077                        $suffix = 2; 
    30593078                        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 ) ); 
    30623081                                $suffix++; 
    30633082                        } while ( $post_name_check ); 
    3064                         $slug = $alt_post_name; 
     3083                        $post->post_name = $alt_post_name; 
    30653084                } 
    30663085        } else { 
    30673086                // Post slugs must be unique across all posts. 
    30683087                $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 ) ); 
    30703089 
    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 ) ) { 
    30723091                        $suffix = 2; 
    30733092                        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 ) ); 
    30763095                                $suffix++; 
    30773096                        } while ( $post_name_check ); 
    3078                         $slug = $alt_post_name; 
     3097                        $post->post_name = $alt_post_name; 
    30793098                } 
    30803099        } 
    30813100 
    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 ); 
    30833102} 
    30843103 
    30853104/** 
    function wp_insert_attachment($object, $file = false, $parent = 0) { 
    39203939                $post_name = sanitize_title($post_name); 
    39213940 
    39223941        // 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 ) ); 
    39243943 
    39253944        if ( empty($post_date) ) 
    39263945                $post_date = current_time('mysql');