Make WordPress Core

Ticket #20419: 20419-post-obj.patch

File 20419-post-obj.patch, 5.3 KB (added by mintindeed, 12 years ago)

replace $post_ID with $post object

  • wp-includes/post.php

     
    28262826 * @global wpdb $wpdb
    28272827 * @global WP_Rewrite $wp_rewrite
    28282828 * @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
    28312832 * @param string $post_type
    28322833 * @param integer $post_parent
    28332834 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
    28342835 */
    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' ) ) )
     2836function 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 ) )
    28372849                return $slug;
    28382850
    28392851        global $wpdb, $wp_rewrite;
     
    28482860        if ( 'attachment' == $post_type ) {
    28492861                // Attachment slugs must be unique across all types.
    28502862                $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 ) );
    28522864
    28532865                if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
    28542866                        $suffix = 2;
    28552867                        do {
    28562868                                $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 ) );
    28582870                                $suffix++;
    28592871                        } while ( $post_name_check );
    28602872                        $slug = $alt_post_name;
     
    28632875                // Page slugs must be unique within their own trees. Pages are in a separate
    28642876                // namespace than posts so page slugs are allowed to overlap post slugs.
    28652877                $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 ) );
    28672879
    28682880                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 ) ) {
    28692881                        $suffix = 2;
    28702882                        do {
    28712883                                $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 ) );
    28732885                                $suffix++;
    28742886                        } while ( $post_name_check );
    28752887                        $slug = $alt_post_name;
     
    28772889        } else {
    28782890                // Post slugs must be unique across all posts.
    28792891                $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 ) );
    28812893
    28822894                if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
    28832895                        $suffix = 2;
    28842896                        do {
    28852897                                $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 ) );
    28872899                                $suffix++;
    28882900                        } while ( $post_name_check );
    28892901                        $slug = $alt_post_name;
    28902902                }
    28912903        }
    28922904
    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 );
    28942906}
    28952907
    28962908/**
  • 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);
     1037        $post->post_name = wp_unique_post_slug( $post->post_name, $post->post_status, $deprecated, $post->post_type, $post->post_parent, $post );
    10381038
    10391039        $post->filter = 'sample';
    10401040