Make WordPress Core


Ignore:
Timestamp:
09/11/2022 08:44:50 PM (3 years ago)
Author:
joemcgill
Message:

Editor: Refresh nones for metaboxes after reauthentication.

This fixes an issue where metaboxes fail to save after a session expires and a user logs in again via the heartbeat API.

Props LinSoftware.
Fixes #52584.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r53572 r54122  
    10171017        $this->assertSame( 0, post_exists( $title, null, null, 'wp_tests', $post_status ) );
    10181018    }
     1019
     1020    /**
     1021     * Test refreshed nonce for metabox loader.
     1022     *
     1023     * @return void
     1024     */
     1025    public function test_user_get_refreshed_metabox_nonce() {
     1026
     1027        // Create a post by the current user.
     1028        wp_set_current_user( self::$editor_id );
     1029
     1030        $post_data = array(
     1031            'post_content' => 'Test post content',
     1032            'post_title'   => 'Test post title',
     1033            'post_excerpt' => 'Test post excerpt',
     1034            'post_author'  => self::$editor_id,
     1035            'post_status'  => 'draft',
     1036        );
     1037        $post_id   = wp_insert_post( $post_data );
     1038
     1039        // Simulate the $_POST data from the heartbeat.
     1040        $data = array(
     1041            'wp-refresh-metabox-loader-nonces' => array(
     1042                'post_id' => (string) $post_id,
     1043            ),
     1044            'wp-refresh-post-lock'             => array(
     1045                'lock'    => '1658203298:1',
     1046                'post_id' => (string) $post_id,
     1047            ),
     1048        );
     1049
     1050        // Call the function we're testing.
     1051        $response = wp_refresh_metabox_loader_nonces( array(), $data );
     1052
     1053        // Ensure that both nonces were created.
     1054        $this->assertNotEmpty( $response['wp-refresh-metabox-loader-nonces']['replace']['_wpnonce'] );
     1055        $this->assertNotEmpty( $response['wp-refresh-metabox-loader-nonces']['replace']['metabox_loader_nonce'] );
     1056    }
    10191057}
Note: See TracChangeset for help on using the changeset viewer.