
关于WordPress文件及其使用方法的综合指南
_wp_put_post_revision ( $post = null, $autosave = false )
_wp_put_post_revision: 这个函数将一个文章的修订版保存到数据库中: 当一个文章被更新或发布时,它被调用,并创建一个新的文章修订版,可以被访问并与以前的修订版进行比较。
将文章数据作为文章修订版插入到文章表中。
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; }