Make WordPress Core

Ticket #39493: 39493.2.diff

File 39493.2.diff, 2.2 KB (added by SergeyBiryukov, 8 years ago)
  • src/wp-includes/post-template.php

     
    616616                if ( is_single() ) {
    617617                        $classes[] = 'single';
    618618                        if ( isset( $post->post_type ) ) {
    619                                 $classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id );
     619                                $post_type_class = sanitize_html_class( $post->post_type, $post_id );
     620                                $classes[] = 'single-' . $post_type_class;
     621                                $classes[] = 'single-' . $post_type_class . '-' . sanitize_html_class( $post->post_name, $post_id );
    620622                                $classes[] = 'postid-' . $post_id;
    621623
    622624                                // Post Format
     
    641643
    642644                        $page_id = $wp_query->get_queried_object_id();
    643645
    644                         $post = get_post($page_id);
     646                        $post = get_post( $page_id );
    645647
     648                        $classes[] = 'page-' . sanitize_html_class( $post->post_name, $page_id );
    646649                        $classes[] = 'page-id-' . $page_id;
    647650
    648651                        if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {
  • tests/phpunit/tests/post/getBodyClass.php

     
    9292                $this->assertContains( "single-format-standard", $class );
    9393        }
    9494
     95        /**
     96         * @ticket 39493
     97         */
     98        public function test_singular_body_classes_should_contain_post_slug() {
     99                $post_id = self::factory()->post->create();
     100                $this->go_to( get_permalink( $post_id ) );
     101
     102                $class = get_body_class();
     103                $post = get_post( $post_id );
     104                $this->assertContains( "single-post-{$post->post_name}", $class );
     105        }
     106
     107        /**
     108         * @ticket 39493
     109         */
     110        public function test_singular_body_classes_should_contain_page_slug() {
     111                $post_id = self::factory()->post->create( array(
     112                        'post_type' => 'page',
     113                ) );
     114                $this->go_to( get_permalink( $post_id ) );
     115
     116                $class = get_body_class();
     117                $post = get_post( $post_id );
     118                $this->assertContains( "page-{$post->post_name}", $class );
     119        }
     120
    95121        public function test_page_template_body_classes_no_template() {
    96122                $post_id = self::factory()->post->create( array(
    97123                        'post_type' => 'page',