PluginProbe
WP Document Revisions / 5.4.2
WP Document Revisions v5.4.2
5.4.2 5.4.1 5.4.0 5.2.0 5.3.0 5.1.3 5.1.2 5.1.1 5.1.0 5.0.0 4.0.7 4.0.5 4.0.6 4.0.4 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 2.0.0 2.2.0 3.0.0 3.0.1 3.1.0 All 63 releases
wp-document-revisions / wp-document-revisions.php

wp-document-revisions.php in WP Document Revisions 5.4.2, at wp-document-revisions.php

171 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 Plugin Name: WP Document Revisions
4 Plugin URI: http://ben.balter.com/2011/08/29/wp-document-revisions-document-management-version-control-wordpress/
5 Description: A document management and version control plugin for WordPress that allows teams of any size to collaboratively edit files and manage their workflow.
6 Version: 5.4.2
7 Requires at least: 5.9
8 Requires PHP: 8.0
9 Author: Ben Balter
10 Author URI: https://ben.balter.com
11 License: GPL-3.0-or-later
12 License URI: https://www.gnu.org/licenses/gpl-3.0.html
13 Text Domain: wp-document-revisions
14 Domain Path: /languages
15 *
16 @package wp-document-revisions
17 */
18
19 // direct file access protection.
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
24 /**
25 * WP Document Revisions
26 *
27 * A document management and version control plugin for WordPress that allows
28 * teams of any size to collaboratively edit files and manage their workflow.
29 *
30 * Copyright (C) 2011-2026 Ben Balter ( ben@balter.com -- http://ben.balter.com )
31 *
32 * This program is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, either version 3 of the License, or
35 * (at your option) any later version.
36 *
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
41 *
42 * You should have received a copy of the GNU General Public License
43 * along with this program. If not, see <http://www.gnu.org/licenses/>.
44 *
45 * @copyright 2011-2026
46 * @license GPL-3.0-or-later
47 * @version 5.4.2
48 * @package WP_Document_Revisions
49 * @author Ben Balter <ben@balter.com>
50 */
51 // Single source of truth for the plugin version. The "Version:" header above is
52 // parsed by WordPress from the file header itself and must remain literal; this
53 // constant is the canonical value for runtime PHP code (cache busters, etc.).
54 if ( ! defined( 'WPDR_VERSION' ) ) {
55 define( 'WPDR_VERSION', '5.4.2' );
56 }
57
58 // Composer autoloader for production dependencies.
59 //
60 // Today smalot/pdfparser ships unscoped from `vendor/` — both dev and
61 // release. The `vendor-prefixed/` branches below stay as defensive code so
62 // that the future scoper-on-the-release-path switch (when the Composer-
63 // autoload bootstrap edge cases are worked out — see scoper.inc.php) needs
64 // no further changes here. php-scoper writes `scoper-autoload.php` from
65 // 0.19 onward and a plain `autoload.php` in 0.18, hence the two paths.
66 //
67 // In every shipping configuration today the `vendor/autoload.php` branch
68 // is the one that runs; the spl_autoload_register shim then registers an
69 // alias so plugin code referencing `WP_Document_Revisions\Vendor\*` keeps
70 // working if a downstream user opts into scoping locally.
71 if ( file_exists( __DIR__ . '/vendor-prefixed/scoper-autoload.php' ) ) {
72 require_once __DIR__ . '/vendor-prefixed/scoper-autoload.php';
73 } elseif ( file_exists( __DIR__ . '/vendor-prefixed/autoload.php' ) ) {
74 require_once __DIR__ . '/vendor-prefixed/autoload.php';
75 } elseif ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
76 require_once __DIR__ . '/vendor/autoload.php';
77
78 spl_autoload_register(
79 static function ( $class_name ) {
80 $prefix = 'WP_Document_Revisions\\Vendor\\';
81 if ( 0 !== strpos( $class_name, $prefix ) ) {
82 return;
83 }
84 $unscoped = substr( $class_name, strlen( $prefix ) );
85 if ( class_exists( $unscoped ) || interface_exists( $unscoped ) || trait_exists( $unscoped ) ) {
86 class_alias( $unscoped, $class_name );
87 }
88 }
89 );
90 }
91
92 require_once __DIR__ . '/includes/trait-wp-document-revisions-rewrites.php';
93 require_once __DIR__ . '/includes/trait-wp-document-revisions-file-handler.php';
94 require_once __DIR__ . '/includes/trait-wp-document-revisions-revisions.php';
95 require_once __DIR__ . '/includes/trait-wp-document-revisions-query.php';
96 require_once __DIR__ . '/includes/interface-wp-document-revisions-text-extractor.php';
97 require_once __DIR__ . '/includes/class-wp-document-revisions-text-extraction-exception.php';
98 require_once __DIR__ . '/includes/class-wp-document-revisions-text-extractor-registry.php';
99 require_once __DIR__ . '/includes/class-wp-document-revisions-text-extractor-cache.php';
100 require_once __DIR__ . '/includes/class-wp-document-revisions-text-extractor-scheduler.php';
101 require_once __DIR__ . '/includes/class-wp-document-revisions-text-extraction-opt-out.php';
102 require_once __DIR__ . '/includes/class-wp-document-revisions-text-diff.php';
103 require_once __DIR__ . '/includes/class-wp-document-revisions-ai-summary.php';
104 require_once __DIR__ . '/includes/class-wp-document-revisions-ai-summary-rest.php';
105 require_once __DIR__ . '/includes/class-wp-document-revisions-ai-summary-prefill.php';
106 require_once __DIR__ . '/includes/class-wp-document-revisions-pdf-text-extractor.php';
107 require_once __DIR__ . '/includes/class-wp-document-revisions-docx-text-extractor.php';
108 require_once __DIR__ . '/includes/class-wp-document-revisions.php';
109
110 // Register the built-in text extractors. Lazy construction inside the filter
111 // callbacks avoids paying allocation cost on requests that never extract
112 // anything. Third parties can prepend their own extractors at a higher
113 // filter priority to override these defaults.
114 add_filter(
115 'wpdr_text_extractors',
116 static function ( array $extractors ): array {
117 $extractors[] = new WP_Document_Revisions_PDF_Text_Extractor();
118 return $extractors;
119 }
120 );
121 add_filter(
122 'wpdr_text_extractors',
123 static function ( array $extractors ): array {
124 $extractors[] = new WP_Document_Revisions_DOCX_Text_Extractor();
125 return $extractors;
126 }
127 );
128
129 // Wire up async extraction: schedule a wp-cron event on each revision
130 // attachment insert, and register the worker that runs extraction off the
131 // request thread.
132 WP_Document_Revisions_Text_Extractor_Scheduler::init();
133
134 // Register the per-document opt-out meta box and save handler (admin only).
135 WP_Document_Revisions_Text_Extraction_Opt_Out::init();
136
137 // Register the AI summary cron handler (hooks wpdr_text_extracted →
138 // queues a single cron event to generate the summary off the request
139 // thread). Generation skips silently when the WP 7.0 AI Client is not
140 // available; the cron event is still scheduled so a future site
141 // upgrade does not require re-extracting historical content.
142 WP_Document_Revisions_AI_Summary::init();
143
144 // Register the read + review REST endpoints. Generation is intentionally
145 // NOT exposed over REST — cron drives it after extraction completes.
146 WP_Document_Revisions_AI_Summary_REST::init();
147
148 // Register the admin-editor JS enqueue for the AI revision-log pre-fill.
149 // Only fires on the document edit screen; gated on the per-document and
150 // sitewide pre-fill opt-out so opted-out documents pay no enqueue cost.
151 WP_Document_Revisions_AI_Summary_Prefill::init();
152
153 // Register the WP-CLI backfill command when running under WP-CLI.
154 if ( defined( 'WP_CLI' ) && WP_CLI ) {
155 require_once __DIR__ . '/includes/class-wp-document-revisions-text-extraction-cli-command.php';
156 WP_CLI::add_command(
157 'document-revisions extract-text',
158 array( 'WP_Document_Revisions_Text_Extraction_CLI_Command', 'extract_text' )
159 );
160 }
161
162 // $wpdr is a global reference to the class.
163 global $wpdr;
164 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
165 $wpdr = new WP_Document_Revisions();
166 require_once __DIR__ . '/includes/template-functions.php';
167
168 // Activation and deactivation hooks must be relative to the main plugin file.
169 register_activation_hook( __FILE__, array( $wpdr, 'activation_hook' ) );
170 register_deactivation_hook( __FILE__, array( $wpdr, 'deactivation_hook' ) );
171