@khelmar,
I have been thinking further about youe issue and can see that the workflow is a reasonable one if you have a publishing process and subsequent revisioning process.
I have therefore created an issue on the plugin GtHub page and have created a pull request to simplify your potential coding by creating an action point and filter where you can link your processing.
Since these are not currently available, I’ll give the code that you will need to include in Version 3.3.1 that hopefully will be in Version 3.4 of the plugin when it is released.
1. Action document_saved
This is actioned after all save processing for the document is done.
Code to insert after line 1265 of includes/class-wp-document-revisions-admin.php
which reads wp_set_post_terms( $doc_id, array( $ws ), 'workflow_state' )
// find the attachment id.
$attach_id = get_post_field( 'post_content', $doc_id );
/**
* Fires once a document has been saved.
*
* @since 3.4.0
*
* @param int $doc_id id of Document post.
* @param int $attach_id id of Attachment post.
*/
do_action( 'document_saved', $doc_id, $attach_id );
Using this action you create/update the postmeta data when the status is final.
2. Filter document_serve_attachment
The attachment corresponding to the document (or revision) post is retrieved. This is then filtered.
Code to insert after line 1036 of includes/class-wp-document-revisions.php
which reads $attach = get_post( get_post_field( 'post_content', $rev_id ) )
/*
* Filter the attachment post to serve.
*
* @param WP_Post $attach Attachment Post corresponding to document / revisions selected.
* @param int $rev_id Id of document / revision selected.
*/
$attach = apply_filters( 'document_serve_attachment', $attach, $rev_id );
This is where you determine whether the user is logged on or not If not to return the Attachment Post corresponding to the value stored in the postmeta field.
You will need to check that the $rev_id is pointing to a document and not a revision. Also the various cases of not Final documents that don’t have the meta data.
If you do not wish to display the document you will need to manage this yourself. In the future, you will be able to return false and it will die gracefully.
Regards,
Neil James