_wp_put_post_revision

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

WordPress Version: 6.4

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @param int|WP_Post|array|null $post     Post ID, post object OR post array.
 * @param bool                   $autosave Optional. Whether the revision is an autosave or not.
 *                                         Default false.
 * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID.'));
    }
    if (isset($post['post_type']) && 'revision' === $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post = _wp_post_revision_data($post, $autosave);
    $post = wp_slash($post);
    // Since data is from DB.
    $revision_id = wp_insert_post($post, true);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         * @since 6.4.0 The post_id parameter was added.
         *
         * @param int $revision_id Post revision ID.
         * @param int $post_id     Post ID.
         */
        do_action('_wp_put_post_revision', $revision_id, $post['post_parent']);
    }
    return $revision_id;
}

WordPress Version: 6.2

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @param int|WP_Post|array|null $post     Post ID, post object OR post array.
 * @param bool                   $autosave Optional. Whether the revision is an autosave or not.
 *                                         Default false.
 * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID.'));
    }
    if (isset($post['post_type']) && 'revision' === $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post = _wp_post_revision_data($post, $autosave);
    $post = wp_slash($post);
    // Since data is from DB.
    $revision_id = wp_insert_post($post, true);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         *
         * @param int $revision_id Post revision ID.
         */
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}

WordPress Version: 6.1

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @param int|WP_Post|array|null $post     Post ID, post object OR post array.
 * @param bool                   $autosave Optional. Whether the revision is an autosave or not.
 * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID.'));
    }
    if (isset($post['post_type']) && 'revision' === $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post = _wp_post_revision_data($post, $autosave);
    $post = wp_slash($post);
    // Since data is from DB.
    $revision_id = wp_insert_post($post, true);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         *
         * @param int $revision_id Post revision ID.
         */
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}

WordPress Version: 5.8

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @param int|WP_Post|array|null $post     Post ID, post object OR post array.
 * @param bool                   $autosave Optional. Is the revision an autosave?
 * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID.'));
    }
    if (isset($post['post_type']) && 'revision' === $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post = _wp_post_revision_data($post, $autosave);
    $post = wp_slash($post);
    // Since data is from DB.
    $revision_id = wp_insert_post($post, true);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         *
         * @param int $revision_id Post revision ID.
         */
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}

WordPress Version: 5.5

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @param int|WP_Post|array|null $post     Post ID, post object OR post array.
 * @param bool                   $autosave Optional. Is the revision an autosave?
 * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID.'));
    }
    if (isset($post['post_type']) && 'revision' === $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post = _wp_post_revision_data($post, $autosave);
    $post = wp_slash($post);
    // Since data is from DB.
    $revision_id = wp_insert_post($post);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         *
         * @param int $revision_id Post revision ID.
         */
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}

WordPress Version: 5.4

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @param int|WP_Post|array|null $post     Post ID, post object OR post array.
 * @param bool                   $autosave Optional. Is the revision an autosave?
 * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID.'));
    }
    if (isset($post['post_type']) && 'revision' == $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post = _wp_post_revision_data($post, $autosave);
    $post = wp_slash($post);
    // Since data is from DB.
    $revision_id = wp_insert_post($post);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         *
         * @param int $revision_id Post revision ID.
         */
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}

WordPress Version: 4.5

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @param int|WP_Post|array|null $post     Post ID, post object OR post array.
 * @param bool                   $autosave Optional. Is the revision an autosave?
 * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID.'));
    }
    if (isset($post['post_type']) && 'revision' == $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post = _wp_post_revision_data($post, $autosave);
    $post = wp_slash($post);
    //since data is from db
    $revision_id = wp_insert_post($post);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         *
         * @param int $revision_id Post revision ID.
         */
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}

WordPress Version: 4.3

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @param int|WP_Post|array|null $post     Post ID, post object OR post array.
 * @param bool                   $autosave Optional. Is the revision an autosave?
 * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID.'));
    }
    if (isset($post['post_type']) && 'revision' == $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post = _wp_post_revision_fields($post, $autosave);
    $post = wp_slash($post);
    //since data is from db
    $revision_id = wp_insert_post($post);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         *
         * @param int $revision_id Post revision ID.
         */
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}

WordPress Version: 4.1

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @param int|object|array $post Post ID, post object OR post array.
 * @param bool $autosave Optional. Is the revision an autosave?
 * @return mixed WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID'));
    }
    if (isset($post['post_type']) && 'revision' == $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post = _wp_post_revision_fields($post, $autosave);
    $post = wp_slash($post);
    //since data is from db
    $revision_id = wp_insert_post($post);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         *
         * @param int $revision_id Post revision ID.
         */
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}

WordPress Version: 4.0

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @uses wp_insert_post()
 *
 * @param int|object|array $post Post ID, post object OR post array.
 * @param bool $autosave Optional. Is the revision an autosave?
 * @return mixed WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID'));
    }
    if (isset($post['post_type']) && 'revision' == $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post = _wp_post_revision_fields($post, $autosave);
    $post = wp_slash($post);
    //since data is from db
    $revision_id = wp_insert_post($post);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         *
         * @param int $revision_id Post revision ID.
         */
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}

WordPress Version: 3.9

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @uses wp_insert_post()
 *
 * @param int|object|array $post Post ID, post object OR post array.
 * @param bool $autosave Optional. Is the revision an autosave?
 * @return mixed WP_Error or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return new WP_Error('invalid_post', __('Invalid post ID'));
    }
    if (isset($post['post_type']) && 'revision' == $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post_id = $post['ID'];
    $post = _wp_post_revision_fields($post, $autosave);
    $post = wp_slash($post);
    //since data is from db
    $revision_id = wp_insert_post($post);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        /**
         * Fires once a revision has been saved.
         *
         * @since 2.6.0
         *
         * @param int $revision_id Post revision ID.
         */
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}

WordPress Version: 3.7

/**
 * Inserts post data into the posts table as a post revision.
 *
 * @since 2.6.0
 * @access private
 *
 * @uses wp_insert_post()
 *
 * @param int|object|array $post Post ID, post object OR post array.
 * @param bool $autosave Optional. Is the revision an autosave?
 * @return mixed Null or 0 if error, new revision ID if success.
 */
function _wp_put_post_revision($post = null, $autosave = false)
{
    if (is_object($post)) {
        $post = get_object_vars($post);
    } elseif (!is_array($post)) {
        $post = get_post($post, ARRAY_A);
    }
    if (!$post || empty($post['ID'])) {
        return;
    }
    if (isset($post['post_type']) && 'revision' == $post['post_type']) {
        return new WP_Error('post_type', __('Cannot create a revision of a revision'));
    }
    $post_id = $post['ID'];
    $post = _wp_post_revision_fields($post, $autosave);
    $post = wp_slash($post);
    //since data is from db
    $revision_id = wp_insert_post($post);
    if (is_wp_error($revision_id)) {
        return $revision_id;
    }
    if ($revision_id) {
        do_action('_wp_put_post_revision', $revision_id);
    }
    return $revision_id;
}