Description
The action hook is executed at the end of “update published content” of a page. This typically happens when you are signing off the revised post at the end of the workflow.
Use this hook to copy over data from the revised post to the already published post.
Usage
add_action('owf_update_published_post', 'update_post_meta_info', 10, 2);
Parameters
- $original_page_id – ID of the published/original page
- $revised_page- revised page to copy the data from
Example
add_action('owf_update_published_post', 'update_post_meta_info', 10, 2); function update_post_meta_info($original_post_id, $revised_post) { $post_meta_keys = get_post_custom_keys($revised_post->ID); if (empty($post_meta_keys)) return; foreach ($post_meta_keys as $meta_key) { $meta_key_trim = trim($meta_key); if ( '_' == $meta_key_trim{0} || strpos($meta_key_trim,'oasis') !== false ) //ignore keys like _edit_last, _edit_lock, oasis continue; $revised_meta_values = get_post_custom_values($meta_key, $revised_post->ID); $original_meta_values = get_post_custom_values($meta_key, $original_post_id); // find the bigger array of the two $meta_values_count = count($revised_meta_values) > count($original_meta_values) ? count($revised_meta_values) : count($original_meta_values); // loop through the meta values to find what's added, modified and deleted. for($i = 0; $i < $meta_values_count; $i++) { $new_meta_value = ""; // delete if the revised post doesn't have that key if (count($revised_meta_values) > $i+1) { $new_meta_value = maybe_unserialize($revised_meta_values[$i]); } else { $old_meta_value = maybe_unserialize($original_meta_values[$i]); delete_post_meta($original_post_id, $meta_key, $old_meta_value); continue; } // old meta values got updated, so simply update it if (count($original_meta_values) > $i+1) { $old_meta_value = maybe_unserialize($original_meta_values[$i]); update_post_meta($original_post_id, $meta_key, $new_meta_value, $old_meta_value); } // new meta values got added, so add it if (count($original_meta_values) < $i+1) { add_post_meta($original_post_id, $meta_key, $new_meta_value); } } } }
Source Code
The action hook is located in class-ow-revision-service.php