WordPress.org

Make WordPress Core

Ticket #20480: 20480.2.diff

File 20480.2.diff, 1.3 KB (added by coffee2code, 22 months ago)

Adds wp_unique_post_slug filter as proposed in 20480.patch; adds pre_wp_unique_post_slug filter; adds some phpDoc

  • wp-includes/post.php

     
    28212821 * Computes a unique slug for the post, when given the desired slug and some post details. 
    28222822 * 
    28232823 * @since 2.8.0 
     2824 * @uses $wpdb 
     2825 * @uses $wp_rewrite 
     2826 * @uses apply_filters() Calls 'pre_wp_unique_post_slug' with empty string and 
     2827 *  all function arguments 
     2828 * @uses apply_filters() Calls 'wp_unique_post_slug' with resultant unique slug, 
     2829 *  all function arguments, and the original slug 
    28242830 * 
    28252831 * @global wpdb $wpdb 
    28262832 * @global WP_Rewrite $wp_rewrite 
     
    28352841        if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) 
    28362842                return $slug; 
    28372843 
     2844        $override_slug = apply_filters( 'pre_wp_unique_post_slug', '', $slug, $post_ID, $post_status, $post_type, $post_parent ); 
     2845        if ( $override_slug ) 
     2846                return $override_slug; 
     2847 
    28382848        global $wpdb, $wp_rewrite; 
    28392849 
     2850        $original_slug = $slug; 
     2851 
    28402852        $feeds = $wp_rewrite->feeds; 
    28412853        if ( ! is_array( $feeds ) ) 
    28422854                $feeds = array(); 
     
    28872899                } 
    28882900        } 
    28892901 
    2890         return apply_filters( 'wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent ); 
     2902        return apply_filters( 'wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ); 
    28912903} 
    28922904 
    28932905/**