-
Notifications
You must be signed in to change notification settings - Fork 0
/
page-preview.php
102 lines (82 loc) · 2.65 KB
/
page-preview.php
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
<?php
/**
* Plugin Name: Page Preview
* Description: Adds screenshots to WordPress post listings, allowing you to quickly visualize and manage your pages directly from the admin panel.
* Version: 1.0.1
* Requires at least: 5.0
* Requires PHP: 7.4
* Author: HandyPlugins
* Author URI: https://handyplugins.co/
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: page-preview
* Domain Path: /languages
*
* @package PagePreview
*/
namespace PagePreview;
// Useful global constants.
define( 'PAGE_PREVIEW_VERSION', '1.0.1' );
define( 'PAGE_PREVIEW_DB_VERSION', '1.0' );
define( 'PAGE_PREVIEW_PLUGIN_FILE', __FILE__ );
define( 'PAGE_PREVIEW_URL', plugin_dir_url( __FILE__ ) );
define( 'PAGE_PREVIEW_PATH', plugin_dir_path( __FILE__ ) );
define( 'PAGE_PREVIEW_INC', PAGE_PREVIEW_PATH . 'includes/' );
// Require Composer autoloader if it exists.
if ( file_exists( PAGE_PREVIEW_PATH . '/vendor/autoload.php' ) ) {
require_once PAGE_PREVIEW_PATH . 'vendor/autoload.php';
}
// load deps
require_once PAGE_PREVIEW_INC . 'package/deliciousbrains/wp-background-processing/classes/wp-async-request.php';
require_once PAGE_PREVIEW_INC . 'package/deliciousbrains/wp-background-processing/classes/wp-background-process.php';
/**
* PSR-4-ish autoload
*
* @since 1.0
*/
spl_autoload_register(
function ( $class ) {
// project-specific namespace prefix.
$prefix = 'PagePreview\\';
// base directory for the namespace prefix.
$base_dir = __DIR__ . '/includes/classes/';
// does the class use the namespace prefix?
$len = strlen( $prefix );
if ( strncmp( $prefix, $class, $len ) !== 0 ) {
return;
}
$relative_class = substr( $class, $len );
$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
// if the file exists, require it.
if ( file_exists( $file ) ) {
require $file;
}
}
);
// Include files.
require_once PAGE_PREVIEW_INC . 'constants.php';
require_once PAGE_PREVIEW_INC . 'utils.php';
require_once PAGE_PREVIEW_INC . 'settings.php';
$network_activated = Utils\is_network_wide( PAGE_PREVIEW_PLUGIN_FILE );
if ( ! defined( 'PAGE_PREVIEW_IS_NETWORK' ) ) {
define( 'PAGE_PREVIEW_IS_NETWORK', $network_activated );
}
/**
* WP CLI Commands
*/
if ( defined( 'WP_CLI' ) && WP_CLI ) {
\WP_CLI::add_command( 'page-preview', '\PagePreview\Command' );
}
/**
* Setup routine
*
* @return void
* @since 1.0 bootstrapping with plugins_loaded hook
*/
function setup() {
// Bootstrap.
Settings\setup();
Install::setup();
PagePreviewer::factory();
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\\setup' );