尽管如此,我发现更新一些关于优秀的post.保存自定义字段:
add_action( \'_wp_put_post_revision\', \'save_cmb2\' );
function save_cmb2( $post, true ) {
// save the custom field
}
请注意,第二个参数是
true
如果您喜欢自动保存。
File: wp-includes/revision.php
275: /**
276: * Inserts post data into the posts table as a post revision.
277: *
278: * @since 2.6.0
279: * @access private
280: *
281: * @param int|WP_Post|array|null $post Post ID, post object OR post array.
282: * @param bool $autosave Optional. Is the revision an autosave?
283: * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
284: */
285: function _wp_put_post_revision( $post = null, $autosave = false ) {
如果使用
wp_restore_post_revision
作用
/**
* Restores a post to the specified revision.
*
* Can restore a past revision using all fields of the post revision, or only selected fields.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @param array $fields Optional. What fields to restore from. Defaults to all.
* @return int|false|null Null if error, false if no fields to restore, (int) post ID if success.
*/
function wp_restore_post_revision( $revision_id, $fields = null ) {
。。。在您应该使用的函数中定义了一个挂钩:
File: wp-includes/revision.php
392: /**
393: * Fires after a post revision has been restored.
394: *
395: * @since 2.6.0
396: *
397: * @param int $post_id Post ID.
398: * @param int $revision_id Post revision ID.
399: */
400: do_action( \'wp_restore_post_revision\', $post_id, $revision[\'ID\'] );
这将引导您找到如下代码:
add_action( \'wp_restore_post_revision\', \'restore_cmb2\' );
function restore_cmb2( $post ) {
// restore the custom field
}