This repository was archived by the owner on Nov 29, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathdocsync.php
More file actions
182 lines (160 loc) · 5 KB
/
Copy pathdocsync.php
File metadata and controls
182 lines (160 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/**
* Plugin Name: DocSync
* Plugin URI: https://github.com/chubes4/docsync
* Description: GitHub-to-WordPress documentation sync system with REST API, WP-CLI, and hierarchical project organization.
* Version: 1.2.1
* Author: Chris Huber
* Author URI: https://chubes.net
* License: GPL v2 or later
* Text Domain: docsync
* Requires at least: 6.9
* Requires PHP: 8.0
*/
// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'DOCSYNC_VERSION', '1.2.1' );
define( 'DOCSYNC_PATH', plugin_dir_path( __FILE__ ) );
define( 'DOCSYNC_URL', plugin_dir_url( __FILE__ ) );
require_once DOCSYNC_PATH . 'vendor/autoload.php';
use DocSync\Api\Routes;
use DocSync\Abilities\Abilities;
use DocSync\Blocks\NavigationBlock;
use DocSync\Core\Assets;
use DocSync\Core\Documentation;
use DocSync\Core\Project;
use DocSync\Core\RewriteRules;
use DocSync\Core\Breadcrumbs;
use DocSync\Fields\RepositoryFields;
use DocSync\Fields\InstallTracker;
use DocSync\Templates\DocumentationLayout;
use DocSync\Templates\RelatedPosts;
use DocSync\Templates\Archive;
use DocSync\Templates\ProjectCard;
use DocSync\Templates\Homepage;
use DocSync\Templates\SearchBar;
use DocSync\Templates\TableOfContents;
use DocSync\Sync\CronSync;
use DocSync\Sync\SyncNotifier;
use DocSync\Admin\SettingsPage;
use DocSync\Admin\ProjectColumns;
use DocSync\Admin\DocumentationColumns;
Documentation::init();
Project::init();
RewriteRules::init();
Assets::init();
add_action( 'docsync_project_registered', function() {
RepositoryFields::init();
InstallTracker::init();
ProjectColumns::init();
} );
CronSync::init();
SyncNotifier::init();
SettingsPage::init();
DocumentationColumns::init();
/**
* Block registration — always available regardless of theme support.
*
* The docsync/navigation block is a standalone Gutenberg block that can
* be used in any context. Theme templates use do_blocks() to render it
* in the sidebar, and editors can drop it into any page.
*/
NavigationBlock::init();
/**
* Template layer — only loads when the active theme declares support.
*
* Themes opt in with: add_theme_support( 'docsync-templates' );
*
* Without theme support, DocSync registers the CPT, taxonomy, sync engine,
* REST API, WP-CLI, Abilities, and admin — but produces zero frontend output.
* The theme handles all rendering via standard WordPress template hierarchy.
*/
add_action( 'after_setup_theme', function() {
if ( ! current_theme_supports( 'docsync-templates' ) ) {
return;
}
add_action( 'init', function() {
DocumentationLayout::init();
RelatedPosts::init();
Breadcrumbs::init();
Archive::init();
Homepage::init();
SearchBar::init();
TableOfContents::init();
} );
}, 20 );
Abilities::init();
add_action( 'rest_api_init', function() {
Routes::register();
} );
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once DOCSYNC_PATH . 'inc/WPCLI/CLI.php';
\DocSync\WPCLI\CLI::register();
}
add_filter( 'html_to_blocks_supported_post_types', function( $post_types ) {
$post_types[] = 'documentation';
return $post_types;
} );
add_filter( 'docsync_search_post_types', function( $post_types ) {
$post_types[] = 'documentation';
return $post_types;
} );
register_activation_hook( __FILE__, function() {
docsync_maybe_migrate_options();
flush_rewrite_rules();
} );
/**
* Migrate options from the old chubes_docs_ prefix to docsync_ prefix.
*
* Runs on activation. Safe to call multiple times — only migrates
* if old options exist and new ones don't.
*
* @since 0.1.0
*/
function docsync_maybe_migrate_options() {
$migrations = [
'chubes_docs_github_pat' => 'docsync_github_pat',
'chubes_docs_sync_interval' => 'docsync_sync_interval',
];
foreach ( $migrations as $old_key => $new_key ) {
$old_value = get_option( $old_key );
if ( $old_value !== false && get_option( $new_key ) === false ) {
update_option( $new_key, $old_value );
delete_option( $old_key );
}
}
// Migrate cron hook.
$old_hook = 'chubes_docs_github_sync';
$new_hook = 'docsync_github_sync';
$old_next = wp_next_scheduled( $old_hook );
if ( $old_next ) {
wp_unschedule_event( $old_next, $old_hook );
}
}
register_deactivation_hook( __FILE__, function() {
flush_rewrite_rules();
} );
/**
* Global wrapper for Project::get_repository_info()
*
* Provides theme templates with access to repository metadata (GitHub URL, WP.org URL, installs)
* for a given project term without requiring direct class access.
*
* @param WP_Term|array $term_or_terms Single term object or array of term objects
* @return array Repository info with github_url, wp_url, and installs keys
*/
function docsync_get_repository_info( $term_or_terms ) {
return Project::get_repository_info( $term_or_terms );
}
/**
* Generate URL for viewing content of specific type for a project
*
* @param string $post_type The post type
* @param WP_Term $term The project term
* @return string The URL to view this content type for this project
*/
function docsync_generate_content_type_url( $post_type, $term ) {
return ProjectCard::generate_content_type_url( $post_type, $term );
}