-
Notifications
You must be signed in to change notification settings - Fork 0
/
faaastpress.php
211 lines (177 loc) · 7.02 KB
/
faaastpress.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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
/**
* Plugin Name: FaaastPress
* Plugin URI: https://github.com/QuentinLD
* Description: Speed up and secure your WordPress site with just a few clicks.
* Version: 1.0.0
* Author: Quentin LD
* Author URI: https://github.com/QuentinLD
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: faaastpress
* Domain Path: /languages
*
* FaaastPress is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* FaaastPress is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FaaastPress. If not, see https://www.gnu.org/licenses/gpl-2.0.html.
*
* @package FaaastPress
*/
defined('ABSPATH') || exit;
if (!class_exists('FaaastPress_plugin')) {
/**
* Main FaaastPress_plugin class
*/
class FaaastPress_plugin
{
/**
* Class constructor
*/
public function __construct()
{
// Load plugin text domain
add_action('init', array($this, 'faaastpress_load_textdomain'));
// Load plugin styles & scripts
add_action('admin_print_styles', array($this, 'faaastpress_enqueue_styles'));
add_action('admin_enqueue_scripts', array($this, 'faaastpress_enqueue_scripts'));
// Add plugin settings page
add_action('admin_menu', array($this, 'faaastpress_add_settings_page'));
// Save plugin settings
add_action('admin_post', array($this, 'faaastpress_save_options'));
// Handle plugin settings updated message
add_action('admin_notices', array($this, 'faaastpress_settings_updated_notice'));
// Enable plugin settings
add_action('init', array($this, 'faaastpress_enable_options'));
include_once('inc/bloat.php');
include_once('inc/enhancement.php');
include_once('inc/security.php');
include_once('inc/woocommerce.php');
}
/**
* Load plugin text domain
*
* @since 1.0.0
*/
public function faaastpress_load_textdomain()
{
load_plugin_textdomain('faaastpress', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
/**
* Load styles & scripts
*
* @since 1.0.0
*/
public function faaastpress_enqueue_styles()
{
wp_enqueue_style('faaastpress-styles', plugin_dir_url(__FILE__) . 'assets/faaastpress.css');
}
public function faaastpress_enqueue_scripts()
{
wp_enqueue_script('faaastpress-scripts', plugin_dir_url(__FILE__) . 'assets/faaastpress.js');
}
/**
* Add plugin settings page
*
* @since 1.0.0
*/
public function faaastpress_add_settings_page()
{
add_options_page(
__('FaaastPress Settings', 'faaastpress'),
__('FaaastPress', 'faaastpress'),
'manage_options',
'faaastpress',
array($this, 'render_settings_page')
);
}
/**
* Render plugin settings page
*
* @since 1.0.0
*/
public function render_settings_page()
{
include_once('views/settings.php');
}
/**
* Save plugin settings
*
* @since 1.0.0
*/
public function faaastpress_save_options()
{
if (!current_user_can('manage_options')) {
return;
}
if (!isset($_POST['faaastpress_options_nonce']) || !wp_verify_nonce(sanitize_key($_POST['faaastpress_options_nonce']), 'faaastpress_options')) {
return;
}
// Save bloat options
$bloat_options = isset($_POST['bloat_options']) && is_array($_POST['bloat_options']) ? array_map('sanitize_key', wp_unslash($_POST['bloat_options'])) : array();
update_option('faaastpress_bloat_options', $bloat_options);
// Save security options
$security_options = isset($_POST['security_options']) && is_array($_POST['security_options']) ? array_map('sanitize_key', wp_unslash($_POST['security_options'])) : array();
update_option('faaastpress_security_options', $security_options);
// Save enhancement options
$enhancement_options = isset($_POST['enhancement_options']) && is_array($_POST['enhancement_options']) ? array_map('sanitize_key', wp_unslash($_POST['enhancement_options'])) : array();
update_option('faaastpress_enhancement_options', $enhancement_options);
// Save WooCommerce options
$woocommerce_options = isset($_POST['woocommerce_options']) && is_array($_POST['woocommerce_options']) ? array_map('sanitize_key', wp_unslash($_POST['woocommerce_options'])) : array();
update_option('faaastpress_woocommerce_options', $woocommerce_options);
// Redirect to settings page
wp_safe_redirect(add_query_arg(array('page' => 'faaastpress', 'settings-updated' => true), admin_url('options-general.php')));
exit;
}
/**
* Handle plugin settings updated message
*
* @since 1.0.0
*/
public function faaastpress_settings_updated_notice()
{
if (!isset($_GET['settings-updated']) || !filter_var(wp_unslash($_GET['settings-updated']), FILTER_VALIDATE_BOOLEAN)) {
return;
}
echo '<div class="notice notice-success is-dismissible"><p><strong>' . esc_html('Settings saved.', 'faaastpress') . '</strong></p></div>';
}
/**
* Enable plugin options
*
* @since 1.0.0
*/
public function faaastpress_enable_options()
{
// Get bloat options
$bloat_options = get_option('faaastpress_bloat_options', array());
faaastpress_remove_bloat($bloat_options);
// Get security options
$security_options = get_option('faaastpress_security_options', array());
// Get enhancement options
$enhancement_options = get_option('faaastpress_enhancement_options', array());
// Get woocommerce options
$woocommerce_options = get_option('faaastpress_woocommerce_options', array());
}
}
if (!function_exists('faaastpress')) {
/**
* Returns the main instance of FaaastPress.
*
* @since 1.0.0
* @return FaaastPress_plugin
*/
function faaastpress()
{
return new FaaastPress_plugin();
}
}
faaastpress();
}