-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathsimply-static.php
More file actions
executable file
·166 lines (140 loc) · 6.31 KB
/
simply-static.php
File metadata and controls
executable file
·166 lines (140 loc) · 6.31 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
<?php
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Plugin Name: Simply Static
* Plugin URI: https://simplystatic.com
* Description: A static site generator to create fast and secure static versions of your WordPress website.
* Version: 3.6.8
* Author: Patrick Posner
* Author URI: https://patrickposner.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: simply-static
* Domain Path: /languages
*/
define( 'SIMPLY_STATIC_PATH', plugin_dir_path( __FILE__ ) );
define( 'SIMPLY_STATIC_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
define( 'SIMPLY_STATIC_VERSION', '3.6.8' );
// Check PHP version.
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( esc_html__( 'Simply Static requires PHP 7.4 or higher.', 'simply-static' ), 'Plugin dependency check', array( 'back_link' => true ) );
}
// Check WordPress version.
if ( version_compare( get_bloginfo( 'version' ), '6.2', '<' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( esc_html__( 'Simply Static requires WordPress 6.2 or higher.', 'simply-static' ), 'Plugin dependency check', array( 'back_link' => true ) );
}
// Run autoloader.
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) && ! class_exists( 'Simply_Static\Plugin' ) ) {
require __DIR__ . '/vendor/autoload.php';
}
// Boot Simply Static.
if ( ! function_exists( 'simply_static_run_plugin' ) ) {
add_action( 'plugins_loaded', 'simply_static_run_plugin' );
/**
* Run plugin
*
* @return void
*/
function simply_static_run_plugin() {
require_once SIMPLY_STATIC_PATH . 'src/class-ss-plugin.php';
Simply_Static\Plugin::instance();
$options = get_option( 'simply-static' );
if ( ! is_array( $options ) ) {
$options = [];
}
// Server-side cron?
if ( isset( $options['server_cron'] ) && true === $options['server_cron'] ) {
define( 'SS_CRON', true );
}
// Generate a secure unique key.
if ( ! isset( $options['encryption_key'] ) ) {
$options['encryption_key'] = bin2hex( random_bytes( 16 ) );
update_option( 'simply-static', $options );
}
}
// Enforce Pro compatibility for Simply Static >= 3.5.2.
// When Simply Static is >= 3.5.2, we require Simply Static Pro >= 2.0.1.
add_action( 'plugins_loaded', function () {
if ( ! defined( 'SIMPLY_STATIC_VERSION' ) || version_compare( SIMPLY_STATIC_VERSION, '3.5.2', '<' ) ) {
return;
}
// Bail if Pro isn't active at all.
if ( ! function_exists( 'deactivate_plugins' ) || ! function_exists( 'is_plugin_active' ) || ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$pro_basename = 'simply-static-pro/simply-static-pro.php';
$pro_active = function_exists( 'is_plugin_active' ) && is_plugin_active( $pro_basename );
$pro_netactive = function_exists( 'is_plugin_active_for_network' ) && is_plugin_active_for_network( $pro_basename );
if ( ! $pro_active && ! $pro_netactive ) {
return; // Pro not active; nothing to enforce.
}
// If Pro is active but version is missing or too low, deactivate and notify.
if ( ! defined( 'SIMPLY_STATIC_PRO_VERSION' ) || version_compare( SIMPLY_STATIC_PRO_VERSION, '2.0.1', '<' ) ) {
$network_wide = $pro_netactive;
deactivate_plugins( $pro_basename, false, $network_wide );
// Prevent Pro boot during current request if it already hooked into plugins_loaded.
if ( function_exists( 'ssp_run_plugin' ) ) {
remove_action( 'plugins_loaded', 'ssp_run_plugin' );
}
// Site admin notice.
add_action(
'admin_notices',
function () {
$message = sprintf(
/* translators: 1: required Simply Static Pro version */
esc_html__( 'Simply Static Pro has been deactivated because it is not compatible with this version of Simply Static. Please update Simply Static Pro to at least version %1$s and then reactivate it.', 'simply-static' ),
'2.0.1'
);
echo wp_kses_post( '<div class="notice notice-error"><p>' . $message . '</p></div>' );
}
);
// Network admin notice (multisite).
add_action(
'network_admin_notices',
function () {
$message = sprintf(
/* translators: 1: required Simply Static Pro version */
esc_html__( 'Simply Static Pro has been deactivated network-wide because it is not compatible with this version of Simply Static. Please update Simply Static Pro to at least version %1$s and then reactivate it.', 'simply-static' ),
'2.0.1'
);
echo wp_kses_post( '<div class="notice notice-error"><p>' . $message . '</p></div>' );
}
);
}
}, 1 );
}
register_deactivation_hook( __FILE__, 'simply_static_plugin_deactivate' );
/**
* Clean up on deactivation.
*/
function simply_static_plugin_deactivate() {
// Ensure Util, Query, Model and Page classes are available.
if ( ! class_exists( 'Simply_Static\\Util' ) ) {
require_once SIMPLY_STATIC_PATH . 'src/class-ss-util.php';
}
if ( ! class_exists( 'Simply_Static\\Query' ) && file_exists( SIMPLY_STATIC_PATH . 'src/class-ss-query.php' ) ) {
require_once SIMPLY_STATIC_PATH . 'src/class-ss-query.php';
}
if ( ! class_exists( 'Simply_Static\\Model' ) && file_exists( SIMPLY_STATIC_PATH . 'src/models/class-ss-model.php' ) ) {
require_once SIMPLY_STATIC_PATH . 'src/models/class-ss-model.php';
}
// Load Page model to access its table
if ( ! class_exists( 'Simply_Static\\Page' ) && file_exists( SIMPLY_STATIC_PATH . 'src/models/class-ss-page.php' ) ) {
require_once SIMPLY_STATIC_PATH . 'src/models/class-ss-page.php';
}
// Clear temp dir.
$temp_dir = \Simply_Static\Util::get_temp_dir();
\Simply_Static\Util::delete_dir_contents( $temp_dir );
// Clear DB table.
\Simply_Static\Page::query()->delete_all();
// Remove debug log file.
$debug_file = \Simply_Static\Util::get_debug_log_filename();
if ( ( file_exists( $debug_file ) || is_link( $debug_file ) ) && is_writable( $debug_file ) ) {
unlink( $debug_file );
}
}