$actor_id, 'event' => $event_id, 'time' => time(), 'data' => $data, ); if (update_post_meta($post_id, '_anno_audit_item_'.($num_items + 1), $audit_item)) { update_post_meta($post_id, '_anno_audit_count', $num_items + 1); return true; } return false; } /** * Displays an audit log of events for a given post. * * @param int $post_id The ID of the post to display the log for. * @return void */ function annowf_audit_log($post) { $post_id = $post->ID; $html = ''; $num_items = get_post_meta($post_id, '_anno_audit_count', true); $items = array(); for ($i = 1; $i <= $num_items; $i++) { $items[] = get_post_meta($post_id, '_anno_audit_item_'.$i, true); } if (empty($items)) { return $html; } // Indices start at 1 to prevent empty() check failures $event_array = array( 0 => '', 1 => _x('Created a revision', 'article audit event', 'anno'), 2 => _x('Transitioned post state from %s to %s', 'article audit event', 'anno'), 3 => _x('Added a reviewer comment', 'article audit event', 'anno'), 4 => _x('Added a review of %s', 'article audit event', 'anno'), 5 => _x('Added an internal comment', 'article audit event', 'anno'), 6 => _x('Added %s as a co-author', 'article audit event', 'anno'), 7 => _x('Removed %s as a co-author', 'article audit event', 'anno'), 8 => _x('Added %s as a reviewer', 'article audit event', 'anno'), 9 => _x('Removed %s as a reviewer', 'article audit event', 'anno'), ); echo ''; } /** * Hooks into cf-revision-manager plugin. Defines post meta to be saved with revisions. */ function annowf_registered_post_meta_items() { if (function_exists('cfr_register_metadata')) { $workflow_meta_keys = array( '_anno_acknowledgements', '_anno_funding', '_anno_subtitle', '_anno_appendices', '_anno_doi', '_anno_author_snapshot', '_anno_references', ); foreach ($workflow_meta_keys as $meta_key) { cfr_register_metadata($meta_key, 'annowf_meta_revision_display'); } } } add_action('init', 'annowf_registered_post_meta_items'); /** * Display callback for post meta in revisions * @param string $meta_value * @return string HTML markup */ function annowf_meta_revision_display($meta_value) { $html = ''; if (is_array($meta_value)) { $html = annowf_meta_array_walk_display($meta_value, 0); } else { $html = '
'.esc_html($meta_value).'
'; } return $html; } /** * Walk an array for display in revisions. * * @param array $array Array to be walked * @param int $margin amount to indent by * @return string HTML markup */ function annowf_meta_array_walk_display($array, $margin) { $html = ''; foreach ($array as $key => $value) { $html = '
'.$key.' => '; if (is_array($value)) { $html .= annowf_meta_array_walk_display($value, $margin + 30); } else { $html .= esc_html($value); } } return $html.'
'; } /** * Styling for post-meta in revisions */ function annowf_revisions_css() { ?>