This document provides a high-level overview of the Documentate WordPress plugin's architecture, data flow, and key components. It serves as a guide for AI agents and new developers to understand how the system is built and where to find specific functionality.
Documentate is a WordPress plugin designed to generate official resolutions and structured documents. It uses a custom post type (documentate_document) to store document data, which is categorized by a custom taxonomy (documentate_doc_type).
The core functionality involves taking structured data entered by users in WordPress, merging it into an .odt (OpenDocument Text) template using OpenTBS, and then optionally converting that document into .docx or .pdf formats using external conversion engines like Collabora Online or LibreOffice WASM (ZetaJS).
documentate_document(CPT): Represents an individual document. The content of the document is stored using the classic editor (Gutenberg is explicitly disabled). Field values are typically stored in thepost_contentusing HTML comments as separators to allow for version diffing.documentate_doc_type(Taxonomy): Represents a "Template" or "Document Type". Each document belongs to a specific type. The type defines which.odtand.docxtemplates should be used when generating the final file.
- Location:
includes/class-documentate-document-generator.phpandincludes/class-documentate-opentbs.php. - Flow:
- User triggers a document generation (e.g., clicking "Preview" or "Export" in the admin UI).
- The system fetches the attached
.odttemplate for the selecteddocumentate_doc_type. - The
Documentate_OpenTBSwrapper uses thetbs_classandtbs_plugin_opentbslibraries to merge WordPress post data (title, content, author, custom fields) into the.odttemplate placeholders. - The result is a generated
.odtfile.
- Location:
includes/class-documentate-conversion-manager.php,includes/class-documentate-collabora-converter.php,includes/class-documentate-zetajs-converter.php. - Flow:
- Once the
.odtis generated, it often needs to be converted to.pdf(for preview) or.docx. - The
Documentate_Conversion_Managerchecks the plugin settings to determine the selected engine:- Collabora Online: Makes a remote API call to a Collabora server to perform the conversion.
- WASM (ZetaJS): Uses an experimental in-browser LibreOffice WebAssembly port to perform conversions locally in the client's browser.
- Once the
- Location:
includes/class-documentate-user-scope.php,includes/class-documentate-scope-filter.php,includes/class-documentate-document-access-protection.php. - Logic:
- Template Management: Only Administrators can create or edit
documentate_doc_typeterms. - Scope Filtering: Documents are filtered based on a "Scope category" assigned to the user's profile.
- Administrators see everything.
- Standard users only see documents assigned to their scope category or its subcategories.
- Frontend / REST Protection:
Documentate_Document_Access_Protectionaggressively blocks frontend access (template_redirect), REST API access, and comments queries for thedocumentate_documentCPT if the user lacks theedit_postscapability.
- Template Management: Only Administrators can create or edit
admin/: Classes and assets for the WordPress admin dashboard (Settings page, Meta boxes, custom UI).includes/: Core plugin logic.custom-post-types/&documents/: CPT registration and meta handling.doc-type/: Taxonomy registration and schema extraction logic.opentbs/: Embedded TinyButStrong and OpenTBS libraries.
fixtures/: Sample.odttemplates and generated files used for testing and demos.tests/: PHPUnit tests (unit and e2e) following WordPress standard practices.
While analyzing the codebase, a few areas stand out for future refinement:
- REST API Comment Protection Granularity:
- In
class-documentate-rest-comment-protection.php, the checks currently rely heavily onis_user_logged_in(). This means any logged-in user (even a Subscriber) might bypass the REST restriction block, although other core WordPress capability checks might eventually stop them. It is generally safer to check for a specific capability likecurrent_user_can('edit_posts'), similar to howclass-documentate-document-access-protection.phpdoes it.
- In
- Settings Validation Capabilities:
class-documentate-admin-settings.phphandles sanitization well, but ensure that any endpoint saving these settings explicitly verifiescurrent_user_can('manage_options')if done outside the standard Options API flow.
- Hardcoded Post Types in Protection:
class-documentate-rest-comment-protection.phpdefaults to protectingdocumentate_taskin its filter. It should probably dynamically read the registered CPTs or default todocumentate_document.
- The project uses
wp-envfor local development. - Code must adhere to WordPress Coding Standards (validated via
phpcs). - Run
make upto start the environment andmake testto run tests. - Always read
AGENTS.mdandCONVENTIONS.mdfor specific coding rules.