Make WordPress Core

Ticket #58932: 10706.2.diff

File 10706.2.diff, 2.5 KB (added by josephscott, 3 months ago)

New diff from https://github.com/WordPress/wordpress-develop/pull/10706

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

    diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php
    index 2eaf67454394e..ba4ecdc6d3ed4 100644
    a b function _post_states( $post, $display = true ) { 
    22972297function get_post_states( $post ) {
    22982298        $post_states = array();
    22992299
     2300        if ( ! $post instanceof WP_Post ) {
     2301                return $post_states;
     2302        }
     2303
    23002304        if ( isset( $_REQUEST['post_status'] ) ) {
    23012305                $post_status = $_REQUEST['post_status'];
    23022306        } else {
  • src/wp-includes/nav-menu.php

    diff --git a/src/wp-includes/nav-menu.php b/src/wp-includes/nav-menu.php
    index 83a67cfe2a800..dc6de5c70c662 100644
    a b function wp_setup_nav_menu_item( $menu_item ) { 
    875875                                        $menu_item->type_label = $object->labels->singular_name;
    876876                                        // Denote post states for special pages (only in the admin).
    877877                                        if ( function_exists( 'get_post_states' ) ) {
    878                                                 $menu_post   = get_post( $menu_item->object_id );
    879                                                 $post_states = get_post_states( $menu_post );
    880                                                 if ( $post_states ) {
    881                                                         $menu_item->type_label = wp_strip_all_tags( implode( ', ', $post_states ) );
     878                                                $menu_post = get_post( $menu_item->object_id );
     879                                                if ( $menu_post instanceof WP_Post ) {
     880                                                        $post_states = get_post_states( $menu_post );
     881                                                        if ( $post_states ) {
     882                                                                $menu_item->type_label = wp_strip_all_tags( implode( ', ', $post_states ) );
     883                                                        }
    882884                                                }
    883885                                        }
    884886                                } else {
  • tests/phpunit/tests/admin/includesTemplate.php

    diff --git a/tests/phpunit/tests/admin/includesTemplate.php b/tests/phpunit/tests/admin/includesTemplate.php
    index 909aff217a583..436659179dd26 100644
    a b public function test_wp_add_dashboard_widget() { 
    494494                // This doesn't actually get removed due to the invalid priority.
    495495                remove_meta_box( 'dashboard2', 'dashboard', 'normal' );
    496496        }
     497
     498        /**
     499         * Tests that get_post_states() handles a null value gracefully.
     500         *
     501         * This can happen when get_post() returns null (e.g., when a post
     502         * doesn't exist) and that result is passed to get_post_states()
     503         * without being checked first.
     504         *
     505         * @ticket 58932
     506         *
     507         * @covers ::get_post_states
     508         */
     509        public function test_get_post_states_with_null_returns_empty_array() {
     510                $result = get_post_states( null );
     511                $this->assertIsArray( $result, 'get_post_states() should return an array when passed null.' );
     512                $this->assertEmpty( $result, 'get_post_states() should return an empty array when passed null.' );
     513        }
    497514}