wp_refresh_post_nonces

The timeline below displays how wordpress function wp_refresh_post_nonces has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Checks nonce expiration on the New/Edit Post screen and refresh if needed.
 *
 * @since 3.6.0
 *
 * @param array  $response  The Heartbeat response.
 * @param array  $data      The $_POST data sent.
 * @param string $screen_id The screen ID.
 * @return array The Heartbeat response.
 */
function wp_refresh_post_nonces($response, $data, $screen_id)
{
    if (array_key_exists('wp-refresh-post-nonces', $data)) {
        $received = $data['wp-refresh-post-nonces'];
        $response['wp-refresh-post-nonces'] = array('check' => 1);
        $post_id = absint($received['post_id']);
        if (!$post_id) {
            return $response;
        }
        if (!current_user_can('edit_post', $post_id)) {
            return $response;
        }
        $response['wp-refresh-post-nonces'] = array('replace' => array('getpermalinknonce' => wp_create_nonce('getpermalink'), 'samplepermalinknonce' => wp_create_nonce('samplepermalink'), 'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'), '_ajax_linking_nonce' => wp_create_nonce('internal-linking'), '_wpnonce' => wp_create_nonce('update-post_' . $post_id)));
    }
    return $response;
}

WordPress Version: 5.5

/**
 * Check nonce expiration on the New/Edit Post screen and refresh if needed
 *
 * @since 3.6.0
 *
 * @param array  $response  The Heartbeat response.
 * @param array  $data      The $_POST data sent.
 * @param string $screen_id The screen ID.
 * @return array The Heartbeat response.
 */
function wp_refresh_post_nonces($response, $data, $screen_id)
{
    if (array_key_exists('wp-refresh-post-nonces', $data)) {
        $received = $data['wp-refresh-post-nonces'];
        $response['wp-refresh-post-nonces'] = array('check' => 1);
        $post_id = absint($received['post_id']);
        if (!$post_id) {
            return $response;
        }
        if (!current_user_can('edit_post', $post_id)) {
            return $response;
        }
        $response['wp-refresh-post-nonces'] = array('replace' => array('getpermalinknonce' => wp_create_nonce('getpermalink'), 'samplepermalinknonce' => wp_create_nonce('samplepermalink'), 'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'), '_ajax_linking_nonce' => wp_create_nonce('internal-linking'), '_wpnonce' => wp_create_nonce('update-post_' . $post_id)));
    }
    return $response;
}

WordPress Version: 5.3

/**
 * Check nonce expiration on the New/Edit Post screen and refresh if needed
 *
 * @since 3.6.0
 *
 * @param array  $response  The Heartbeat response.
 * @param array  $data      The $_POST data sent.
 * @param string $screen_id The screen id.
 * @return array The Heartbeat response.
 */
function wp_refresh_post_nonces($response, $data, $screen_id)
{
    if (array_key_exists('wp-refresh-post-nonces', $data)) {
        $received = $data['wp-refresh-post-nonces'];
        $response['wp-refresh-post-nonces'] = array('check' => 1);
        $post_id = absint($received['post_id']);
        if (!$post_id) {
            return $response;
        }
        if (!current_user_can('edit_post', $post_id)) {
            return $response;
        }
        $response['wp-refresh-post-nonces'] = array('replace' => array('getpermalinknonce' => wp_create_nonce('getpermalink'), 'samplepermalinknonce' => wp_create_nonce('samplepermalink'), 'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'), '_ajax_linking_nonce' => wp_create_nonce('internal-linking'), '_wpnonce' => wp_create_nonce('update-post_' . $post_id)));
    }
    return $response;
}

WordPress Version: 5.0

/**
 * Check nonce expiration on the New/Edit Post screen and refresh if needed
 *
 * @since 3.6.0
 *
 * @param array  $response  The Heartbeat response.
 * @param array  $data      The $_POST data sent.
 * @param string $screen_id The screen id.
 * @return array The Heartbeat response.
 */
function wp_refresh_post_nonces($response, $data, $screen_id)
{
    if (array_key_exists('wp-refresh-post-nonces', $data)) {
        $received = $data['wp-refresh-post-nonces'];
        $response['wp-refresh-post-nonces'] = array('check' => 1);
        if (!$post_id = absint($received['post_id'])) {
            return $response;
        }
        if (!current_user_can('edit_post', $post_id)) {
            return $response;
        }
        $response['wp-refresh-post-nonces'] = array('replace' => array('getpermalinknonce' => wp_create_nonce('getpermalink'), 'samplepermalinknonce' => wp_create_nonce('samplepermalink'), 'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'), '_ajax_linking_nonce' => wp_create_nonce('internal-linking'), '_wpnonce' => wp_create_nonce('update-post_' . $post_id)));
    }
    return $response;
}

WordPress Version: 4.5

/**
 * Check nonce expiration on the New/Edit Post screen and refresh if needed
 *
 * @since 3.6.0
 *
 * @param array  $response  The Heartbeat response.
 * @param array  $data      The $_POST data sent.
 * @param string $screen_id The screen id.
 * @return array The Heartbeat response.
 */
function wp_refresh_post_nonces($response, $data, $screen_id)
{
    if (array_key_exists('wp-refresh-post-nonces', $data)) {
        $received = $data['wp-refresh-post-nonces'];
        $response['wp-refresh-post-nonces'] = array('check' => 1);
        if (!$post_id = absint($received['post_id'])) {
            return $response;
        }
        if (!current_user_can('edit_post', $post_id)) {
            return $response;
        }
        $response['wp-refresh-post-nonces'] = array('replace' => array('getpermalinknonce' => wp_create_nonce('getpermalink'), 'samplepermalinknonce' => wp_create_nonce('samplepermalink'), 'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'), '_ajax_linking_nonce' => wp_create_nonce('internal-linking'), '_wpnonce' => wp_create_nonce('update-post_' . $post_id)), 'heartbeatNonce' => wp_create_nonce('heartbeat-nonce'));
    }
    return $response;
}

WordPress Version: 4.3

/**
 * Check nonce expiration on the New/Edit Post screen and refresh if needed
 *
 * @since 3.6.0
 */
function wp_refresh_post_nonces($response, $data, $screen_id)
{
    if (array_key_exists('wp-refresh-post-nonces', $data)) {
        $received = $data['wp-refresh-post-nonces'];
        $response['wp-refresh-post-nonces'] = array('check' => 1);
        if (!$post_id = absint($received['post_id'])) {
            return $response;
        }
        if (!current_user_can('edit_post', $post_id)) {
            return $response;
        }
        $response['wp-refresh-post-nonces'] = array('replace' => array('getpermalinknonce' => wp_create_nonce('getpermalink'), 'samplepermalinknonce' => wp_create_nonce('samplepermalink'), 'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'), '_ajax_linking_nonce' => wp_create_nonce('internal-linking'), '_wpnonce' => wp_create_nonce('update-post_' . $post_id)), 'heartbeatNonce' => wp_create_nonce('heartbeat-nonce'));
    }
    return $response;
}

WordPress Version: 3.9

/**
 * Check nonce expiration on the New/Edit Post screen and refresh if needed
 *
 * @since 3.6.0
 */
function wp_refresh_post_nonces($response, $data, $screen_id)
{
    if (array_key_exists('wp-refresh-post-nonces', $data)) {
        $received = $data['wp-refresh-post-nonces'];
        $response['wp-refresh-post-nonces'] = array('check' => 1);
        if (!$post_id = absint($received['post_id'])) {
            return $response;
        }
        if (!current_user_can('edit_post', $post_id) || empty($received['post_nonce'])) {
            return $response;
        }
        if (2 === wp_verify_nonce($received['post_nonce'], 'update-post_' . $post_id)) {
            $response['wp-refresh-post-nonces'] = array('replace' => array('getpermalinknonce' => wp_create_nonce('getpermalink'), 'samplepermalinknonce' => wp_create_nonce('samplepermalink'), 'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'), '_ajax_linking_nonce' => wp_create_nonce('internal-linking'), '_wpnonce' => wp_create_nonce('update-post_' . $post_id)), 'heartbeatNonce' => wp_create_nonce('heartbeat-nonce'));
        }
    }
    return $response;
}

WordPress Version: 3.7

/**
 * Check nonce expiration on the New/Edit Post screen and refresh if needed
 *
 * @since 3.6
 */
function wp_refresh_post_nonces($response, $data, $screen_id)
{
    if (array_key_exists('wp-refresh-post-nonces', $data)) {
        $received = $data['wp-refresh-post-nonces'];
        $response['wp-refresh-post-nonces'] = array('check' => 1);
        if (!$post_id = absint($received['post_id'])) {
            return $response;
        }
        if (!current_user_can('edit_post', $post_id) || empty($received['post_nonce'])) {
            return $response;
        }
        if (2 === wp_verify_nonce($received['post_nonce'], 'update-post_' . $post_id)) {
            $response['wp-refresh-post-nonces'] = array('replace' => array('autosavenonce' => wp_create_nonce('autosave'), 'getpermalinknonce' => wp_create_nonce('getpermalink'), 'samplepermalinknonce' => wp_create_nonce('samplepermalink'), 'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'), '_ajax_linking_nonce' => wp_create_nonce('internal-linking'), '_wpnonce' => wp_create_nonce('update-post_' . $post_id)), 'heartbeatNonce' => wp_create_nonce('heartbeat-nonce'));
        }
    }
    return $response;
}