Make WordPress Core

Ticket #47911: 47911_htdat.diff

File 47911_htdat.diff, 1.6 KB (added by htdat, 2 years ago)

Updated the code provided by @goaroundagain and added a unit test for this ticket

  • src/wp-includes/canonical.php

    diff --git a/src/wp-includes/canonical.php b/src/wp-includes/canonical.php
    index 184fb756e8..185f9bfec7 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'" );
    956 
     955                $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status IN ('" . implode( "', '", get_post_stati( array( 'public' => true ) ) ) . "')" );
    957956                if ( ! $post_id ) {
    958957                        return false;
    959958                }
  • tests/phpunit/tests/canonical.php

    diff --git a/tests/phpunit/tests/canonical.php b/tests/phpunit/tests/canonical.php
    index bd0b68c038..8cd0d973e8 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        public function test_redirect_guess_404_permalink_with_custom_status_public() {
     284                register_post_status( 'custom', array( 'public' => true ) );
     285
     286                $post = self::factory()->post->create(
     287                        array(
     288                                'post_title'  => 'custom-status-public-guess-404-permalink',
     289                                'post_status' => 'custom',
     290                        )
     291                );
     292
     293                $this->go_to( 'custom-status-public-guess-404-permalink' );
     294
     295                $this->assertSame( get_permalink( $post ), redirect_guess_404_permalink() );
     296        }
     297
    278298        /**
    279299         * Ensure multiple post types do not throw a notice.
    280300         *