Make WordPress Core

Ticket #47911: 47911_htdat_3.diff

File 47911_htdat_3.diff, 1.6 KB (added by costdev, 4 years ago)

Unit test updated with @covers tag and minor comment change for consistency.

  • src/wp-includes/canonical.php

    diff --git a/src/wp-includes/canonical.php b/src/wp-includes/canonical.php
    index 184fb756e8..aea6bf889d 100644
    a b function redirect_guess_404_permalink() { 
    952952                }
    953953
    954954                // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
    955                 $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" );
     955                $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status IN ('" . implode( "', '", get_post_stati( array( 'public' => true ) ) ) . "')" );
    956956
    957957                if ( ! $post_id ) {
    958958                        return false;
  • tests/phpunit/tests/canonical.php

    diff --git a/tests/phpunit/tests/canonical.php b/tests/phpunit/tests/canonical.php
    index 93eed462fc..e4a26f64a5 100644
    a b class Tests_Canonical extends WP_Canonical_UnitTestCase { 
    275275                $this->assertFalse( redirect_guess_404_permalink() );
    276276        }
    277277
     278        /**
     279         * Ensure public posts with custom statuses are guessed.
     280         *
     281         * @ticket 47911
     282         *
     283         * @covers ::redirect_guess_404_permalink
     284         */
     285        public function test_redirect_guess_404_permalink_with_custom_status_public() {
     286                register_post_status( 'custom', array( 'public' => true ) );
     287
     288                $post = self::factory()->post->create(
     289                        array(
     290                                'post_title'  => 'custom-status-public-guess-404-permalink',
     291                                'post_status' => 'custom',
     292                        )
     293                );
     294
     295                $this->go_to( 'custom-status-public-guess-404-permalink' );
     296
     297                $this->assertSame( get_permalink( $post ), redirect_guess_404_permalink() );
     298        }
     299
    278300        /**
    279301         * Ensure multiple post types do not throw a notice.
    280302         *