Make WordPress Core

Ticket #31168: 31168-b.patch

File 31168-b.patch, 2.1 KB (added by tyxla, 10 years ago)

Making comment_status = closed and ping_status = closed for pages by default. Adding a unit test for those.

  • src/wp-admin/includes/upgrade.php

     
    227227                                                                'post_type' => 'page',
    228228                                                                'to_ping' => '',
    229229                                                                'pinged' => '',
    230                                                                 'post_content_filtered' => ''
     230                                                                'post_content_filtered' => '',
     231                                                                'comment_status' => 'closed',
    231232                                                                ));
    232233        $wpdb->insert( $wpdb->postmeta, array( 'post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default' ) );
    233234
  • src/wp-includes/post.php

     
    30883088                'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0,
    30893089                'post_content' => '', 'post_title' => '', 'context' => '');
    30903090
     3091        if ( !empty( $postarr['post_type'] ) && $postarr['post_type'] == 'page' ) {
     3092                $defaults['ping_status'] = 'closed';
     3093        }
     3094
    30913095        $postarr = wp_parse_args($postarr, $defaults);
    30923096
    30933097        unset( $postarr[ 'filter' ] );
     
    32583262        }
    32593263
    32603264        if ( empty( $postarr['comment_status'] ) ) {
    3261                 if ( $update ) {
     3265                if ( $update || $post_type == 'page' ) {
    32623266                        $comment_status = 'closed';
    32633267                } else {
    32643268                        $comment_status = get_option('default_comment_status');
  • tests/phpunit/tests/post.php

     
    10681068                        $this->assertEquals( $post->$field, $value );
    10691069                }
    10701070        }
     1071
     1072        /**
     1073         * @ticket 31168
     1074         */
     1075        function test_wp_insert_post_page_default_comment_ping_status() {
     1076                $args = array(
     1077                        'post_type' => 'page',
     1078                        'post_title' => 'Example Page',
     1079                        'post_status' => 'publish',
     1080                );
     1081                $post_id = $this->factory->post->create( $args );
     1082                $page = get_post( $post_id );
     1083
     1084                $this->assertEquals( 'closed', $page->comment_status );
     1085                $this->assertEquals( 'closed', $page->ping_status );
     1086        }
    10711087}