-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-code-mirror.php
More file actions
60 lines (49 loc) · 1.75 KB
/
wp-code-mirror.php
File metadata and controls
60 lines (49 loc) · 1.75 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
<?php
/**
* Plugin Name: WP Code Mirror
* Plugin URI: https://github.com/georgeolaru/wp-code-mirror
* Description: Mirror in-development theme and plugin code across multiple WordPress test sites.
* Version: 0.1.0
* Author: George Olaru
* Author URI: https://github.com/georgeolaru
* Requires at least: 6.0
* Tested up to: 7.0
* Requires PHP: 7.4
* Text Domain: wp-code-mirror
* License: MIT
* License URI: https://opensource.org/licenses/MIT
*/
declare(strict_types=1);
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require_once __DIR__ . '/includes/class-wp-code-mirror-config-repository.php';
require_once __DIR__ . '/includes/class-wp-code-mirror-host-bridge.php';
require_once __DIR__ . '/includes/class-wp-code-mirror-admin-page.php';
require_once __DIR__ . '/includes/class-wp-code-mirror-paths.php';
function wp_code_mirror_maybe_migrate_legacy_config( WP_Code_Mirror_Paths $paths ): void {
if ( file_exists( $paths->config_path() ) || ! file_exists( $paths->legacy_config_path() ) ) {
return;
}
if ( ! is_dir( $paths->config_dir() ) ) {
wp_mkdir_p( $paths->config_dir() );
}
copy( $paths->legacy_config_path(), $paths->config_path() );
}
function wp_code_mirror_bootstrap(): void {
if ( ! is_admin() ) {
return;
}
$paths = new WP_Code_Mirror_Paths( __DIR__ );
wp_code_mirror_maybe_migrate_legacy_config( $paths );
$repository = new WP_Code_Mirror_Config_Repository( $paths->config_path() );
$bridge = new WP_Code_Mirror_Host_Bridge(
$paths->scripts_dir() . '/wp-code-sync.sh',
$paths->scripts_dir() . '/wp-code-sync-service.sh',
$paths->config_path(),
$paths->tmp_dir()
);
$page = new WP_Code_Mirror_Admin_Page( $repository, $bridge, __FILE__ );
$page->register();
}
add_action( 'plugins_loaded', 'wp_code_mirror_bootstrap' );