function wp_restore_post_revision($post_id, $revision_id) { // copy postmeta from revision to post (restore from revision) acf_copy_postmeta($revision_id, $post_id); // Make sure the latest revision is also updated to match the new $post data // get latest revision $revision = acf_get_post_latest_revision($post_id); // save if ($revision) { // copy postmeta from revision to latest revision (potentialy may be the same, but most likely are different) acf_copy_postmeta($revision_id, $revision->ID); } }
function acf_get_valid_post_id($post_id = 0) { // if not $post_id, load queried object if (!$post_id) { // try for global post (needed for setup_postdata) $post_id = (int) get_the_ID(); // try for current screen if (!$post_id) { $post_id = get_queried_object(); } } // $post_id may be an object if (is_object($post_id)) { // post if (isset($post_id->post_type, $post_id->ID)) { $post_id = $post_id->ID; // user } elseif (isset($post_id->roles, $post_id->ID)) { $post_id = 'user_' . $post_id->ID; // term } elseif (isset($post_id->taxonomy, $post_id->term_id)) { $post_id = $post_id->taxonomy . '_' . $post_id->term_id; // comment } elseif (isset($post_id->comment_ID)) { $post_id = 'comment_' . $post_id->comment_ID; // default } else { $post_id = 0; } } // allow for option == options if ($post_id === 'option') { $post_id = 'options'; } // append language code if ($post_id == 'options') { $dl = acf_get_setting('default_language'); $cl = acf_get_setting('current_language'); if ($cl && $cl !== $dl) { $post_id .= '_' . $cl; } } /* * Override for preview * * If the $_GET['preview_id'] is set, then the user wants to see the preview data. * There is also the case of previewing a page with post_id = 1, but using get_field * to load data from another post_id. * In this case, we need to make sure that the autosave revision is actually related * to the $post_id variable. If they match, then the autosave data will be used, otherwise, * the user wants to load data from a completely different post_id */ if (isset($_GET['preview_id'])) { $autosave = wp_get_post_autosave($_GET['preview_id']); if ($autosave && $autosave->post_parent == $post_id) { $post_id = (int) $autosave->ID; } } elseif (isset($_GET['p']) && isset($_GET['preview'])) { $revision = acf_get_post_latest_revision($_GET['p']); // save if ($revision && $revision->post_parent == $post_id) { $post_id = (int) $revision->ID; } } // return return $post_id; }