WordPress.org

Make WordPress Core

Ticket #34865: 34865.patch

File 34865.patch, 1.9 KB (added by jason_the_adams, 5 years ago)
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index d0bc1a3..afd6c4f 100644
    function wp_insert_post( $postarr, $wp_error = false ) { 
    29512951        $post_title = $postarr['post_title'];
    29522952        $post_content = $postarr['post_content'];
    29532953        $post_excerpt = $postarr['post_excerpt'];
     2954
    29542955        if ( isset( $postarr['post_name'] ) ) {
    29552956                $post_name = $postarr['post_name'];
    2956         }
     2957        } elseif ( $update ) {
     2958    $post_name = $post_before->post_name;
     2959  }
    29572960
    29582961        $maybe_empty = 'attachment' !== $post_type
    29592962                && ! $post_content && ! $post_title && ! $post_excerpt
  • tests/phpunit/tests/post.php

    diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
    index 71fe55e..385726e 100644
    class Tests_Post extends WP_UnitTestCase { 
    11881188                $this->assertEquals( 'Updated', $saved_post->post_content );
    11891189        }
    11901190
     1191  /**
     1192    * If a post is updated without providing a post_name param, we shouldn't
     1193    * regenerate a new post name / slug
     1194    *
     1195    * @ticket 34865
     1196    */
     1197   function test_post_updates_without_slug_provided() {
     1198       wp_set_current_user( self::$grammarian_id );
     1199
     1200       // Create a post.
     1201       $test_slug = '34865test';
     1202       $post_id = self::factory()->post->create( array(
     1203           'post_name'    => $test_slug,
     1204           'post_title'   => 'Stuff and things',
     1205           'post_status'  => 'publish'
     1206       ) );
     1207
     1208       // Edit the post - The key 'sticky' is intentionally unset.
     1209       $data = array(
     1210          'ID'         => $post_id,
     1211          'post_title' => 'Updated',
     1212          'post_status'=> 'publish'
     1213       );
     1214
     1215       wp_insert_post( $data );
     1216
     1217       // Make sure it's still sticky
     1218       $updated_post = get_post( $post_id );
     1219
     1220       $this->assertEquals($test_slug, $updated_post->post_name);
     1221   }
     1222
    11911223        /**
    11921224         * @ticket 32585
    11931225         */