PluginProbe
LWS Tools / 2.4
LWS Tools v2.4
trunk 1.0 1.0.1 2.0 2.1 2.1.5 2.2 2.2.1 2.3 2.3.1 2.4 2.4.1 2.4.2 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.6 2.6.1 2.6.1.5 2.6.2 2.6.3 2.6.4
lws-tools / lws-tools.php

lws-tools.php in LWS Tools 2.4, at lws-tools.php

1,231 lines 46.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: LWS Tools
5 * Plugin URI: https://www.lws.fr/
6 * Description: Optimize and modify your website's parameters
7 * Version: 2.4
8 * Author: LWS
9 * Author URI: https://www.lws.fr
10 * Tested up to: 6.2
11 * Domain Path: /languages
12 * Requires PHP : 7.3
13 *
14
15 * @since 1.0
16 * @package lwstools
17 */
18
19 if (! defined('ABSPATH')) {
20 exit;
21 }
22
23 define('LWS_TK_URL', plugin_dir_url(__FILE__));
24 define('LWS_TK_DIR', plugin_dir_path(__FILE__));
25 require_once(ABSPATH . '/wp-admin/includes/class-wp-upgrader.php');
26 require_once(ABSPATH . '/wp-admin/includes/class-core-upgrader.php');
27 require_once(ABSPATH . '/wp-admin/includes/class-theme-upgrader.php');
28 require_once(ABSPATH . '/wp-admin/includes/class-plugin-upgrader.php');
29 require_once(ABSPATH . '/wp-admin/includes/class-language-pack-upgrader.php');
30
31 if (! function_exists('get_plugin_data')) {
32 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
33 }
34
35 /**
36 * Load translations
37 */
38 add_action('init', 'lws_tk_traduction');
39 function lws_tk_traduction()
40 {
41 load_plugin_textdomain('lws-tools', false, dirname(plugin_basename(__FILE__)) . '/languages');
42 }
43
44 register_activation_hook(__FILE__, 'lws_tk_on_activation');
45 function lws_tk_on_activation()
46 {
47 set_transient('lwstk_remind_me', 2592000);
48 }
49
50 register_uninstall_hook(__FILE__, 'lws_tk_uninstalling_plugin');
51 function lws_tk_uninstalling_plugin()
52 {
53 if (!get_option('lws_tk_keep_data_on_delete')) {
54 $delete_all = array(
55 'err_co',
56 'sanitize_media',
57 'hide_gen',
58 'delete_live_writer',
59 'less_revision',
60 'no_h1_mce',
61 'no_emote_wp',
62 'no_apirest',
63 'medium_large',
64 'page_author_link',
65 'no_rss',
66 'remove_feeds_links',
67 'no_comment_rss',
68 'no_user_sitemap',
69 'no_user_ep_rest',
70 'no_self_ping',
71 'remove_shortlink'
72 );
73 foreach ($delete_all as $list) {
74 delete_option('lws_tk_' . $list);
75 }
76 delete_option('lws_tk_keep_data_on_delete');
77 delete_option('lws_tk_reduce_revisions_number');
78 }
79 }
80
81 /**
82 * Enqueue any CSS or JS script needed
83 */
84 add_action('admin_enqueue_scripts', 'lws_tk_scripts');
85 function lws_tk_scripts()
86 {
87 if (get_current_screen()->base == ('toplevel_page_lws-tk-config')) {
88 wp_enqueue_style('lws_tk-css', LWS_TK_URL . "css/lws_tk_style.css");
89 wp_enqueue_style('lws_tk-dt-css', LWS_TK_URL . "DataTables/datatables.min.css");
90 wp_enqueue_script('lws_tk-dt', LWS_TK_URL . "DataTables/datatables.min.js");
91 wp_enqueue_style('lws_sms-Poppins', 'https://fonts.googleapis.com/css?family=Poppins');
92 }
93 else{
94 wp_enqueue_style('lws_tk_css_out', LWS_TK_URL . "css/lws_tk_style_out.css");
95 if (!get_transient('lwstk_remind_me') && !get_option('lwstk_do_not_ask_again')){
96 add_action( 'admin_notices', 'lwstk_review_ad_plugin' );
97 }
98 }
99 }
100
101 function lwstk_review_ad_plugin(){
102 ?>
103 <script>
104 function lwstk_remind_me(){
105 var data = {
106 _ajax_nonce: '<?php echo esc_attr(wp_create_nonce('reminder_for_tk')); ?>',
107 action: "lws_tk_reminder_ajax",
108 data: true,
109 };
110 jQuery.post(ajaxurl, data, function(response){
111 jQuery("#lwstk_review_notice").addClass("animationFadeOut");
112 setTimeout(() => {
113 jQuery("#lwstk_review_notice").addClass("lws_hidden");
114 }, 800);
115 });
116
117 }
118
119 function lwstk_do_not_bother_me(){
120 var data = {
121 _ajax_nonce: '<?php echo esc_attr(wp_create_nonce('donotask_for_tk')); ?>',
122 action: "lws_tk_donotask_ajax",
123 data: true,
124 };
125 jQuery.post(ajaxurl, data, function(response){
126 jQuery("#lwstk_review_notice").addClass("animationFadeOut");
127 setTimeout(() => {
128 jQuery("#lwstk_review_notice").addClass("lws_hidden");
129 }, 800);
130 });
131 }
132 </script>
133
134 <div class="notice notice-info is-dismissible lwstk_review_block_general" id="lwstk_review_notice">
135 <div class="lwstk_circle">
136 <img class="lwstk_review_block_image" src="<?php echo esc_url(plugins_url('images/plugin_lws-tools.svg', __FILE__))?>" width="40px" height="40px">
137 </div>
138 <div style="padding:16px">
139 <h1 class="lwstk_review_block_title"> <?php esc_html_e('Thank you for using LWS Tools!', 'lws-tools'); ?></h1>
140 <p class="lwstk_review_block_desc"><?php _e('Evaluate our plugin to help others optimise and secure their WordPress website!', 'lws-tools' ); ?></p>
141 <a class="lwstk_button_rate_plugin" href="https://wordpress.org/support/plugin/lws-tools/reviews/" target="_blank" ><img style="margin-right: 8px;" src="<?php echo esc_url(plugins_url('images/noter.svg', __FILE__))?>" width="15px" height="15px"><?php esc_html_e('Rate', 'lws-tools'); ?></a>
142 <a class="lwstk_review_button_secondary" onclick="lwstk_remind_me()"><?php esc_html_e('Remind me later', 'lws-tools'); ?></a>
143 <a class="lwstk_review_button_secondary" onclick="lwstk_do_not_bother_me()"><?php esc_html_e('Do not ask again', 'lws-tools'); ?></a>
144 </div>
145 </div>
146 <?php
147 }
148
149 //AJAX Reminder//
150 add_action("wp_ajax_lws_tk_reminder_ajax", "lws_tk_remind_me_later");
151 function lws_tk_remind_me_later(){
152 check_ajax_referer('reminder_for_tk', '_ajax_nonce');
153 if (isset($_POST['data'])){
154 set_transient('lwstk_remind_me', 2592000);
155 }
156 }
157
158 //AJAX Reminder//
159 add_action("wp_ajax_lws_tk_donotask_ajax", "lws_tk_do_not_ask");
160 function lws_tk_do_not_ask(){
161 check_ajax_referer('donotask_for_tk', '_ajax_nonce');
162 if (isset($_POST['data'])){
163 update_option('lwstk_do_not_ask_again', true);
164 }
165 }
166
167
168 function lws_tk_convert($size)
169 {
170 $unit=array(__('b', 'lws-cleaner'),__('K', 'lws-cleaner'),__('M', 'lws-cleaner'),__('G', 'lws-cleaner'),__('T', 'lws-cleaner'),__('P', 'lws-cleaner'));
171 if ($size <= 0) {
172 return '0 ' . $unit[1];
173 }
174 return @round($size/pow(1024, ($i=floor(log($size, 1024)))), 2).''.$unit[$i];
175 }
176
177
178 /**
179 * Create plugin menu in wp-admin
180 */
181 add_action('admin_menu', 'lws_tk_menu_admin');
182 function lws_tk_menu_admin()
183 {
184 $menu_slug = 'lws-tk-config';
185 add_menu_page(__('LWS Tools - Overview', 'lws-tools'), 'LWS Tools', 'manage_options', $menu_slug, 'lws_tk_create_page', LWS_TK_URL . 'images/plugin_lws_tools.svg');
186 }
187
188 /**
189 * Generate the setting page in admin
190 */
191 function lws_tk_create_page()
192 {
193 global $wpdb;
194 include_once __DIR__ . '/view/change_htaccess.php';
195
196
197 //NOTIF//
198 $plugins_update = array();
199 $themes_update = array();
200 $unused_plugins = array();
201 $unused_themes = array();
202
203 $actual_version = get_bloginfo('version');
204 $up_to_date = true;
205 $translations_ready = false;
206 $cert_invalid = false;
207
208 $all_plugins = get_plugins();
209 $all_themes = wp_get_themes();
210 $my_theme = wp_get_theme();
211
212
213 //Number of themes/plugins
214 $count_themes = count($all_themes);
215 $count_inactive_themes = $count_themes - 1;
216 $count_plugins = count($all_plugins);
217
218 //SSL Expiration & Issuer @sameer|Reading SSL certificates in PHP
219 if (!$lws_tk_ssl_cert = get_transient('lws_tk_ssl_cert')) {
220 $errno = 0;
221 $errstr = '';
222 $timeout = 30;
223 $ssl_info = stream_context_create(array("ssl" => array("capture_peer_cert" => true)));
224
225 $stream = stream_socket_client("ssl://" . parse_url(site_url(), PHP_URL_HOST) . ":443", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $ssl_info);
226
227 if ($stream) {
228 $cert_resource = stream_context_get_params($stream);
229 $certificate = $cert_resource['options']['ssl']['peer_certificate'];
230 $certinfo = openssl_x509_parse($certificate);
231 fclose($stream);
232 $lws_tk_ssl_cert = $certinfo;
233 set_transient('lws_tk_ssl_cert', $certinfo, 24 * HOUR_IN_SECONDS);
234 }
235 }
236
237 if ($lws_tk_ssl_cert['validTo_time_t'] - time() < 0) {
238 $cert_invalid = true;
239 }
240 $expiration_ssl = date("m/j/Y", $lws_tk_ssl_cert['validTo_time_t']);
241 $issued_by = $lws_tk_ssl_cert['issuer']['CN'];
242 $up_to_date = (wp_get_update_data()['counts']['wordpress']);
243
244
245 if (!empty(wp_get_translation_updates())) {
246 $translations_ready = true;
247 }
248
249 //Check if DB prefix is different from default
250 $db_prefix = $wpdb->prefix == "wp_" ? true /* Default */ : false /* Not Default */ ;
251
252 if (isset($_POST['lws_tk_update_prefix'])) {
253 if ( ! isset( $_POST['nonce_updating_prefix_nonce'] ) || ! wp_verify_nonce( $_POST['nonce_updating_prefix_nonce'], 'lws_tk_update_prefix' ) ) {
254 wp_die();
255 }
256 $config = ABSPATH . 'wp-config.php';
257 $lines = file($config);//file in to an array
258 $config_file = '';
259 $new_prefix = 'wp';
260
261 //Create new prefix
262 $characters = array_merge(range('a', 'z'), range('0', '9'));
263 $length = rand(2, 4);
264 for ($i = 0; $i < $length; $i++) {
265 $rand = mt_rand(0, count($characters)-1);
266 $new_prefix .= $characters[$rand];
267 }
268 $new_prefix .='_';
269
270 //Modify wp-config to change said prefix
271 foreach ($lines as $line) {
272 if (strpos($line, '$table_prefix') === 0) {
273 $line = '$table_prefix = ' . '"' . $new_prefix . '";' . "\n\r";
274 }
275 $config_file .= $line;
276 }
277
278 //Update each table to reflect new prefix
279 foreach ($wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "%'", ARRAY_N) as $table) {
280 $new_name = substr_replace($table[0], $new_prefix, 0, strlen($wpdb->prefix));
281 $wpdb->query("RENAME TABLE `{$table[0]}` TO `{$new_name}`");
282 }
283
284 //Update specific options with new prefix
285 $wpdb->query("UPDATE {$new_prefix}options SET option_name='{$new_prefix}user_roles' WHERE option_name='{$wpdb->prefix}user_roles';");
286
287 $wpdb->query("UPDATE {$new_prefix}usermeta SET meta_key =
288 CONCAT(
289 REPLACE(LEFT(meta_key, " . strlen($wpdb->prefix) . "), '{$wpdb->prefix}', '{$new_prefix}'),
290 SUBSTR(meta_key, " . (strlen($wpdb->prefix) + 1) . ")
291 ) WHERE
292 meta_key in (
293 '{$wpdb->prefix}capabilities', '{$wpdb->prefix}user_level',
294 '{$wpdb->prefix}user-settings', '{$wpdb->prefix}user-settings-time',
295 '{$wpdb->prefix}dashboard_quick_press_last_post_id'
296 )");
297
298 //Save the new wp-config
299 if (! empty($config_file)) {
300 file_put_contents($config, $config_file);
301 }
302
303 //Check if DB prefix is different from default
304 $db_prefix = $new_prefix == "wp_" ? true /* Default */ : false /* Not Default */ ;
305 }
306
307
308 //Get every plugins in need of an update
309 foreach (get_site_transient('update_plugins')->response as $plugin) {
310 $plugin_data = get_plugin_data($dir = plugin_dir_path(__DIR__). "/" . $plugin->plugin);
311 $plugins_update[] = array('name' => $plugin_data['Name'], 'version' => $plugin_data['Version'], 'new_version' => $plugin->new_version, 'package' => $plugin->plugin, 'slug' => $plugin->slug);
312 }
313
314 //Get every themes in need of an update
315 foreach (get_site_transient('update_themes')->response as $theme) {
316 $theme_data = wp_get_theme($theme['theme']);
317 $themes_update[] = array('name' => $theme_data['Name'], 'version' => $theme_data['Version'], 'new_version' => $theme['new_version'], 'package' => $theme['package'], 'slug' => $theme['theme']);
318 }
319
320 //Get every unused plugins and the number of used plugins
321 $active_plugins = 0;
322 $inactive_plugins = 0;
323 foreach ($all_plugins as $slug => $plugin) {
324 if (!is_plugin_active($slug) && !is_plugin_active_for_network($slug)) {
325 $unused_plugins[] = array('name' => $plugin['Name'], 'author' => $plugin['AuthorName'], 'version' => $plugin['Version'], 'slug' => $plugin['TextDomain'], 'package' => $slug);
326 $inactive_plugins += 1;
327 } else {
328 $active_plugins += 1;
329 }
330 }
331
332 //Get every unused themes
333 foreach ($all_themes as $slug => $theme) {
334 if ($theme['Name'] != $my_theme->name) {
335 $unused_themes[] = array('name' => $theme['Name'], 'author' => $theme['Author'], 'version' => $theme['Version'], 'slug' => $slug);
336 }
337 }
338
339 //SERVER
340
341 $environment = sanitize_text_field($_SERVER['SERVER_SOFTWARE']);
342 $user_ip = sanitize_text_field($_SERVER['HTTP_X_REAL_IP']);
343 $server_port =sanitize_text_field($_SERVER['SERVER_PORT']);
344
345 if (sanitize_text_field($_SERVER['HTTPS']) == 'on') {
346 $is_https = __('Yes', 'lws-tools');
347 } else {
348 $is_https = __('No', 'lws-tools');
349 }
350
351 $server_name = sanitize_text_field($_SERVER['SERVER_NAME']);
352 $server_ip = sanitize_text_field($_SERVER['SERVER_ADDR']);
353 $server_protocol = sanitize_text_field($_SERVER['SERVER_PROTOCOL']);
354
355 $php_ver = phpversion();
356 $is_debug = WP_DEBUG;
357 if ($is_debug) {
358 $is_debug = __('Yes', 'lws-tools');
359 } else {
360 $is_debug = __('No', 'lws-tools');
361 }
362
363 $fopen = ini_get("allow_url_fopen");
364 if ($fopen) {
365 $fopen = __('Yes', 'lws-tools');
366 } else {
367 $fopen = __('No', 'lws-tools');
368 }
369
370 $timezone = ini_get("date.timezone");
371 $charset = ini_get("default_charset");
372 $can_file_upload = ini_get("file_uploads");
373
374 if ($can_file_upload) {
375 $can_file_upload = __('Yes', 'lws-tools');
376 } else {
377 $can_file_upload = __('No', 'lws-tools');
378 }
379
380 $max_exec_time = ini_get("max_execution_time");
381 $max_file_upload = ini_get("max_file_uploads");
382 $max_input_vars = ini_get("max_input_vars");
383 $memory_limit = ini_get("memory_limit");
384 $post_max_size = ini_get("post_max_size");
385 $upload_max_filesize = ini_get("upload_max_filesize");
386 $php_memory_usage = lws_tk_convert(memory_get_usage());
387
388 //OPTIMISATION
389 $opti_list = array(
390 'delete_live_writer' =>
391 array(__('Delete Windows Live Writer manifest', 'lws-tools'), __('Delete the line WordPress add in the header of your website. Useless if you do not use Windows Live Writer.', 'lws-tools'), true),
392 'less_revision' =>
393 array(__('Reduce the amount of available revisions to ', 'lws-tools'), __('WordPress automatically save posts and pages every 2 minutes. Do not completely deactivate those, you should reduce the maximum amount of revisions so as to not obstruct the database uselessly.', 'lws-tools'), true),
394 'page_author_link' =>
395 array(__('Remove author\'s pages and their links', 'lws-tools'), __('If you do not wish to possess individual pages for authors, delete those here. It also help hiding their login informations.', 'lws-tools'), true),
396 'no_self_ping' =>
397 array(__('Prevent WordPress from pingbacking yourself in your posts', 'lws-tools'), __('A Pingback is a link created automatically between two contents. It generally helps with SEO but also generate for contents on the same website, which can be bothersome.', 'lws-tools'), false),
398 'no_emote_wp' =>
399 array(__('Use visitor\'s emotes instead of WordPress', 'lws-tools'), __('Once activated, emotes in your posts and pages will use the vistor\'s emote instead of loading WordPress, helping with performances.', 'lws-tools'), false),
400 'no_h1_mce' =>
401 array(__('Remove Heading 1 from TinyMCE', 'lws-tools'), __('By deactivating H1 tags, you remove the possibility for content creators on your website to put multiple Main Title on your website. You must only have one for good SEO.', 'lws-tools'), true),
402 'remove_shortlink' =>
403 array(__('Remove shortlinks from the page', 'lws-tools'), __('A shortlink is a shortened link of your post or page. It then exists in the source code of your page. you can gain a small performance boost by deactivating that option if you do not use it.', 'lws-tools'), true),
404 'medium_large' =>
405 array(__('Add back hidden \'Medium Large\' image size ', 'lws-tools'), __('Add a new size for images (768 pixels), already existing but hidden, when inserting medias in a post', 'lws-tools'), false),
406 'sanitize_media' =>
407 array(__('Provide a new way of sanitizing uploaded media name', 'lws-tools'), __('Medias names are cleaned even more thoroughly than normal for better names', 'lws-tools'), false),
408 'no_rss' =>
409 array(__('Remove RSS feeds', 'lws-tools'), __('RSS feeds allows visitors to subscribe to your posts and power some apps. Remove RSS if you do not use the blogging part of WordPress or do not want to manage it.', 'lws-tools'), false),
410 'remove_feeds_links' =>
411 array(__('Remove RSS feeds links', 'lws-tools'), __('Remove URLs to manage RSS feeds', 'lws-tools'), false),
412 'no_comment_rss' =>
413 array(__('Remove comments RSS feeds', 'lws-tools'), __('Remove feeds related to comments', 'lws-tools'), false),
414 );
415
416 $secu_list = array(
417 'err_co' =>
418 array(__('Hide connexion errors on wp-login', 'lws-tools'), __('Hide errors when a person try to connect to your WordPress (notably, hide your username)', 'lws-tools'), true),
419 'hide_gen' =>
420 array(__('Hide "WordPress Version" meta on pages', 'lws-tools'), __('WordPress version is shown in multiple places. Security breachs from older versions can be used by hackers to hack your website. You should hide your version.', 'lws-tools'), true),
421 'no_apirest' =>
422 array(__('Deactivate REST API', 'lws-tools'), __('WordPress latest breachs focus on REST API, deactivate-it if you have no use for it.', 'lws-tools'), false),
423 'no_user_sitemap' =>
424 array(__('Hide users pages from WordPress sitemap', 'lws-tools'), __('Hide users pages of your WordPress from the plan of your site.', 'lws-tools'), false),
425 'no_user_ep_rest' =>
426 array(__('Hide users endpoints from REST API', 'lws-tools'), __('Deactivate users endpoints, hiding the users list from disconnected users.', 'lws-tools'), false),
427 );
428
429 $wp_manager = array(
430 'autoindex' =>
431 //Vous pouvez activer cette option pour sécuriser vos données sensibles (fichiers personnels, listing d'adresses mail, mots de passe, sauvegarde de bases de données,...). Cela empêchera l'accès à vos fichiers dans un dossier sans fichier index.
432 array(__('Deactivate files listing for directories with no index', 'lws-tools'), __('You can activate this option to secure your sensible datas (personnal files, email addresses listing, password, database backups,...). It will prevent acces to files in a directory with no index file.', 'lws-tools'), true),
433 'authorid' =>
434 //En cachant votre identifiant, un pirate aura plus de difficulté à se connecter à votre wordpress.
435 array(__('Hide author\'s username', 'lws-tools'), __('By hiding your login, a hacker will have a harder time connection to your WordPress.', 'lws-tools'), true),
436 'comments' =>
437 // En activant cette option, vous bloquerez les tentatives de spams et les abus de commentaires envoyés par les robots et les mauvaises requêtes
438 array(__('Block access to comment pages to browser without UserAgent or Referer', 'lws-tools'), __('By activating this option, you will block spam attempts and comments abuse sent by bots and bad requests', 'lws-tools'), false),
439 'sqlfiles' =>
440 // Il est nécessaire de bloquer le téléchargement de vos fichiers .sql pour éviter toute attaque malveillante. Vos fichiers peuvent contenir des informations sensibles.
441 array(__('Block downloading of SQL files', 'lws-tools'), __('It is necessary to block downloading of your SQL files to prevent all malicious attacks. Your files can contains sensible informations.', 'lws-tools'), false),
442 'readmelicense' =>
443 // Augmentez votre sécurité en bloquant l’accès à vos fichiers situés à la racine de votre site et/ou plugin.
444 //Ces fichiers peuvent contenir des informations exploitables par les pirates pour trouver des failles.
445 array(__('Block access to readme and license files', 'lws-tools'), __('Improve security by blocking access to files situate at the root of your website/plugin. Those files can contains informations usable by hackers to find breaches.', 'lws-tools'), false),
446 'xmlrpc' =>
447 // Il est nécessaire de bloquer l’accès au fichier xml-rpc s’il n’est pas utilisé car celui-ci permet de se connecter à distance à Wordpress et peut être utilisé à des fins malveillantes.
448 array(__('Block access to xmlrpc.php', 'lws-tools'), __('It is necessary to block access to xmlrpc if it is not used as it allows to connect remotely to WordPress and could be used for malicious intent.', 'lws-tools'), false),
449 'phpuploads' =>
450 // Cette option vous permet d'interdire l'exécution de fichier PHP dans ce dossier, qui n'est pas prévu pour cela.
451 array(__('Forbid PHP execution in the uploads directory', 'lws-tools'), __('This option lets you forbid execution of PHP in files in this directory, which is not made for that.', 'lws-tools'), false),
452 );
453
454 if (isset($_POST['lws_tk_optimisations'])) {
455 if ( ! isset( $_POST['nonce_opti_listing_nonce'] ) || ! wp_verify_nonce( $_POST['nonce_opti_listing_nonce'], 'lws_tk_optimisations' ) ) {
456 wp_die();
457 }
458 //Sanitize array
459 $checkboxes = isset($_POST['lws_tk_optimisation_list']) ? (array) $_POST['lws_tk_optimisation_list'] : array();
460 $checkboxes = array_map('sanitize_text_field', $checkboxes);
461 //Update checkboxes
462 foreach ($opti_list as $key => $list) {
463 if (in_array($key, $checkboxes)) {
464 update_option('lws_tk_' . $key, 'yes');
465 if ($key == 'less_revision') {
466 $value = sanitize_text_field($_POST['less_revision_revision_number']);
467 update_option('lws_tk_reduce_revisions_number', $value);
468 }
469 } else {
470 delete_option('lws_tk_' . $key);
471 if ($key == 'less_revision') {
472 delete_option('lws_tk_reduce_revisions_number');
473 }
474 }
475 }
476
477 $change_tab = 'nav-optimisation';
478 }
479
480 if (isset($_POST['lws_tk_security'])) {
481 if ( ! isset( $_POST['nonce_security_listing_nonce'] ) || ! wp_verify_nonce( $_POST['nonce_security_listing_nonce'], 'lws_tk_security' ) ) {
482 wp_die();
483 }
484 //Sanitize array
485 $checkboxes = isset($_POST['lws_tk_security_list']) ? (array) $_POST['lws_tk_security_list'] : array();
486 $checkboxes = array_map('sanitize_text_field', $checkboxes);
487 //Update checkboxes
488 foreach ($secu_list as $key => $list) {
489 if (in_array($key, $checkboxes)) {
490 update_option('lws_tk_' . $key, 'yes');
491 } else {
492 delete_option('lws_tk_' . $key);
493 }
494 }
495 if (isset($_SERVER['lwsapitoken']) && explode('/', getcwd())[1] == 'htdocs') {
496 $wp_manager_checkboxes = isset($_POST['lws_tk_wpmanager_list']) ? (array) $_POST['lws_tk_wpmanager_list'] : array();
497 $wp_manager_checkboxes = array_map('sanitize_text_field', $wp_manager_checkboxes);
498 foreach ($wp_manager as $key => $list) {
499 if (in_array($key, $wp_manager_checkboxes)) {
500 $opts[$key] = true;
501 } else {
502 $opts[$key] = false;
503 }
504 }
505 include_once __DIR__ . '/view/update_htaccess.php';
506 }
507
508 $change_tab = 'nav-security';
509 }
510
511 $results = $wpdb->get_results("SHOW TABLE STATUS");
512 $db_size = 0;
513 $list_tables = array();
514 foreach ($results as $size) {
515 $db_size += $size->Data_length + $size->Index_length;
516 $list_tables[] = array('name' => $size->Name, 'size' => lws_tk_convert($size->Data_length + $size->Index_length), 'charset' => $size->Collation, 'created' => $size->Create_time, 'engine' => $size->Engine);
517 }
518
519 $table_number = count($list_tables);
520 $db_size = (lws_tk_convert($db_size));
521
522 //TOOLS
523 $revisions_amount = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "posts` WHERE post_type='revision'");
524 $revisions_amount = count($revisions_amount);
525
526 $trashed_comments = count($wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "comments` WHERE comment_approved='trash'"));
527 $spam_comments = count($wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "comments` WHERE comment_approved='spam'"));
528
529 if (isset($_POST['lws_tk_reset_plugin'])) {
530 if ( ! isset( $_POST['nonce_security_reset_nonce'] ) || ! wp_verify_nonce( $_POST['nonce_security_reset_nonce'], 'lws_tk_reset_plugin' ) ) {
531 wp_die();
532 }
533 $delete_all = array(
534 'err_co',
535 'sanitize_media',
536 'hide_gen',
537 'delete_live_writer',
538 'less_revision',
539 'no_h1_mce',
540 'no_emote_wp',
541 'no_apirest',
542 'medium_large',
543 'page_author_link',
544 'no_rss',
545 'remove_feeds_links',
546 'no_comment_rss',
547 'no_user_sitemap',
548 'no_user_ep_rest',
549 'no_self_ping',
550 'remove_shortlink'
551 );
552 foreach ($delete_all as $key => $list) {
553 delete_option('lws_tk_' . $list);
554 }
555 }
556 include __DIR__ . '/view/tabs.php';
557 }
558
559 ///OPTIMISATIONS///
560
561 add_action('init', 'lws_tk_optimisations');
562 function lws_tk_optimisations()
563 {
564 /**
565 * Sanitize more the name of media uploaded
566 */
567 if (get_option('lws_tk_sanitize_media')) {
568 add_filter('sanitize_file_name', 'lws_tk_sanitize_file_name');
569 }
570
571 /**
572 * Deactivate Windows Live Writer Manifest Link
573 */
574 if (get_option('lws_tk_delete_live_writer')) {
575 remove_action('wp_head', 'wlwmanifest_link');
576 }
577
578 /**
579 * Remove any errors shown in the login page
580 */
581 if (get_option('lws_tk_err_co')) {
582 add_filter('login_errors', function ($error) {
583 return $error = esc_html__('Failed to connect', 'lws-tools');
584 });
585 }
586
587 /**
588 * Remove the element indicating the use of WordPress
589 */
590 if (get_option('lws_tk_hide_gen')) {
591 remove_action('wp_head', 'wp_generator');
592 }
593
594 /**
595 * Reduce number of revisions [Based on option _number - 1]
596 */
597 if (get_option('lws_tk_less_revision')) {
598 add_filter('wp_revisions_to_keep', 'lws_tk_reduce_revisions', 10, 2);
599 function lws_tk_reduce_revisions($num, $post)
600 {
601 return $num = get_option('lws_tk_reduce_revisions_number');
602 }
603 }
604
605 /**
606 * Remove heading1 for TMCE
607 */
608 if (get_option('lws_tk_no_h1_mce')) {
609 add_filter('tiny_mce_before_init', 'lws_tk_remove_h1_tmce');
610 function lws_tk_remove_h1_tmce($block)
611 {
612 $block['block_formats'] = "Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;Preformatted=pre";
613 return $block;
614 }
615 }
616
617 /**
618 * Disable the emoji's
619 */
620 if (get_option('lws_tk_no_emote_wp')) {
621 remove_action('wp_head', 'print_emoji_detection_script', 7);
622 remove_action('admin_print_scripts', 'print_emoji_detection_script');
623 remove_action('wp_print_styles', 'print_emoji_styles');
624 remove_action('admin_print_styles', 'print_emoji_styles');
625 remove_filter('the_content_feed', 'wp_staticize_emoji');
626 remove_filter('comment_text_rss', 'wp_staticize_emoji');
627 remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
628 add_filter('tiny_mce_plugins', 'lws_tk_disable_emojis_tinymce');
629 add_filter('wp_resource_hints', 'lws_tk_disable_emojis_remove_dns_prefetch', 10, 2);
630 }
631
632 /**
633 * Remove Author Page and its link
634 */
635 if (get_option('lws_tk_page_author_link')) {
636 add_action('template_redirect', function () {
637 if (is_author()) {
638 global $wp_query;
639 $wp_query->set_404();
640 status_header(404);
641 }
642 });
643 add_filter('author_link', function () {
644 return get_option('home');
645 });
646 }
647
648 /**
649 * Add one more size type for images
650 */
651 if (get_option('lws_tk_medium_large')) {
652 add_filter('image_size_names_choose', function ($size_names) {
653 $new_sizes = array(
654 'medium_large' => esc_html__('Medium-Large', 'lws-tools'),
655 );
656 return array_merge($size_names, $new_sizes);
657 });
658 }
659
660 /**
661 * Disable REST API in its entirety
662 */
663 if (get_option('lws_tk_no_apirest')) {
664 add_filter('rest_authentication_errors', function ($access) {
665 return new WP_Error(
666 'rest_disabled',
667 esc_html__('The WordPress REST API has been disabled.', 'lws-tools'),
668 array( 'status' => rest_authorization_required_code() )
669 );
670 });
671 }
672
673 /**
674 * Disable only the endpoints for users and users/id when disconnected
675 */
676 if (get_option('lws_tk_no_user_ep_rest')) {
677 if (!is_user_logged_in()) {
678 add_filter('rest_endpoints', 'lws_tk_disable_custom_rest_endpoints');
679 }
680 }
681
682 /**
683 * Disable all RSS Feeds
684 */
685 if (get_option('lws_tk_no_rss')) {
686 add_action('do_feed', function () {
687 wp_die(esc_html__('No feed available', 'lws-tools'));
688 }, 1);
689 add_action('do_feed_rdf', function () {
690 wp_die(esc_html__('No feed available', 'lws-tools'));
691 }, 1);
692 add_action('do_feed_rss', function () {
693 wp_die(esc_html__('No feed available', 'lws-tools'));
694 }, 1);
695 add_action('do_feed_rss2', function () {
696 wp_die(esc_html__('No feed available', 'lws-tools'));
697 }, 1);
698 add_action('do_feed_atom', function () {
699 wp_die(esc_html__('No feed available', 'lws-tools'));
700 }, 1);
701 add_action('do_feed_rss2_comments', function () {
702 wp_die(esc_html__('No feed available', 'lws-tools'));
703 }, 1);
704 add_action('do_feed_atom_comments', function () {
705 wp_die(esc_html__('No feed available', 'lws-tools'));
706 }, 1);
707 }
708
709 /**
710 * Disable only Comments RSS Feed
711 */
712 if (get_option('lws_tk_no_comment_rss')) {
713 add_action('do_feed', function ($comments) {
714 if ($comments) {
715 wp_die(esc_html__('No feed available', 'lws-tools'));
716 }
717 }, 1);
718 add_action('do_feed_rdf', function ($comments) {
719 if ($comments) {
720 wp_die(esc_html__('No feed available', 'lws-tools'));
721 }
722 }, 1);
723 add_action('do_feed_rss', function ($comments) {
724 if ($comments) {
725 wp_die(esc_html__('No feed available', 'lws-tools'));
726 }
727 }, 1);
728 add_action('do_feed_rss2', function ($comments) {
729 if ($comments) {
730 wp_die(esc_html__('No feed available', 'lws-tools'));
731 }
732 }, 1);
733 add_action('do_feed_atom', function ($comments) {
734 if ($comments) {
735 wp_die(esc_html__('No feed available', 'lws-tools'));
736 }
737 }, 1);
738 add_action('do_feed_rss2_comments', function ($comments) {
739 if ($comments) {
740 wp_die(esc_html__('No feed available', 'lws-tools'));
741 }
742 }, 1);
743 add_action('do_feed_atom_comments', function ($comments) {
744 if ($comments) {
745 wp_die(esc_html__('No feed available', 'lws-tools'));
746 }
747 }, 1);
748 }
749 }
750
751 /**
752 * Remove links to users in the sitemap
753 */
754 if (get_option('lws_tk_no_user_sitemap')) {
755 add_filter('wp_sitemaps_add_provider', function ($provider, $name) {
756 return ($name == 'users') ? false : $provider;
757 }, 10, 2);
758 }
759
760 /**
761 * Remove password strength check.
762 */
763 if (get_option('lws_tk_remove_password_strength_meter')) {
764 add_action('admin_enqueue_scripts', 'lws_tk_remove_password_strength_meter');
765 }
766 function lws_tk_remove_password_strength_meter($hook)
767 {
768 if ($hook != "user-new.php") {
769 return;
770 }
771 wp_dequeue_script('wc-password-strength-meter');
772 wp_dequeue_script('user-profile');
773 wp_dequeue_script('password-strength-meter');
774 wp_deregister_script('user-profile');
775 $suffix = SCRIPT_DEBUG ? '' : '.min';
776 $admin = explode('/', admin_url('', 'relative'));
777 end($admin);
778 $admin = prev($admin);
779 wp_enqueue_script('user-profile', '/' . $admin . "/js/user-profile$suffix.js", array( 'jquery', 'wp-util' ), false, 1);
780 }
781
782 /**
783 * Remove self-pingbacks in posts
784 */
785 if (get_option('kws_tk_no_self_ping')) {
786 add_action('pre_ping', 'lws_tk_no_self_ping');
787 }
788 function lws_tk_no_self_ping(&$links)
789 {
790 $home = get_option('home');
791 foreach ($links as $l => $link) {
792 if (0 === strpos($link, $home)) {
793 unset($links[$l]);
794 }
795 }
796 }
797
798 /**
799 * Remove shorlink from head
800 */
801 if (get_option('lws_tk_remove_shortlink')) {
802 add_filter('after_setup_theme', 'lws_tk_remove_shortlink');
803 }
804 function lws_tk_remove_shortlink()
805 {
806 remove_action('wp_head', 'wp_shortlink_wp_head', 10);
807 remove_action('template_redirect', 'wp_shortlink_header', 11);
808 }
809
810 if (get_option('lws_tk_remove_feeds_links')) {
811 remove_action('wp_head', 'feed_links_extra', 3);
812 remove_action('wp_head', 'feed_links', 2);
813 }
814
815
816 /**
817 * Produces cleaner filenames for uploads
818 * @wpartisan
819 */
820 function lws_tk_sanitize_file_name($filename)
821 {
822 $sanitized_filename = remove_accents($filename);
823
824 // Standard replacements
825 $invalid = array(
826 ' ' => '-',
827 '%20' => '-',
828 '_' => '-',
829 );
830
831 //Replace invalid characters defined above in the name by '-'
832 $sanitized_filename = str_replace(array_keys($invalid), array_values($invalid), $sanitized_filename);
833
834 $sanitized_filename = preg_replace('/[^A-Za-z0-9-\. ]/', '', $sanitized_filename); // Remove all non-alphanumeric except '.'
835 $sanitized_filename = preg_replace('/\.(?=.*\.)/', '', $sanitized_filename); // Remove all but last '.'
836 $sanitized_filename = preg_replace('/-+/', '-', $sanitized_filename); // Replace any more than one - in a row
837 $sanitized_filename = str_replace('-.', '.', $sanitized_filename); // Remove last - if at the end
838 $sanitized_filename = strtolower($sanitized_filename); // Lowercase
839
840 return $sanitized_filename;
841 }
842
843 /**
844 * Filter function used to remove the tinymce emoji plugin.
845 */
846 function lws_tk_disable_emojis_tinymce($plugins)
847 {
848 if (is_array($plugins)) {
849 return array_diff($plugins, array( 'wpemoji' ));
850 } else {
851 return array();
852 }
853 }
854
855 /**
856 * Remove emoji CDN hostname from DNS prefetching hints.
857 */
858 function lws_tk_disable_emojis_remove_dns_prefetch($urls, $relation_type)
859 {
860 if ('dns-prefetch' == $relation_type) {
861 /** This filter is documented in wp-includes/formatting.php */
862 $emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/');
863
864 $urls = array_diff($urls, array( $emoji_svg_url ));
865 }
866
867 return $urls;
868 }
869
870 /**
871 * Disable access to the users and users/id endpoints of RESTAPI
872 */
873 function lws_tk_disable_custom_rest_endpoints($endpoints)
874 {
875 $routes = array( '/wp/v2/users', '/wp/v2/users/(?P<id>[\d]+)' );
876 foreach ($routes as $route) {
877 if (!empty($endpoints[ $route ])) {
878 foreach ($endpoints[ $route ] as $i => $handlers) {
879 if (is_array($handlers) && isset($handlers['methods']) &&
880 'GET' === $handlers['methods']) {
881 unset($endpoints[ $route ][ $i ]);
882 }
883 }
884 }
885 }
886
887 return $endpoints;
888 }
889
890 ///END OPTIMISATIONS///
891
892 ////AJAX////
893
894 // AJAX PART FOR THE DOWNLOAD //
895 /*AJAX DOWNLOAD AND ACTIVATE PLUGINS*/
896
897 //AJAX DL Plugin//
898 add_action("wp_ajax_lws_tk_downloadPlugin", "wp_ajax_install_plugin");
899 //
900
901 //AJAX Activate Plugin//
902 add_action("wp_ajax_lws_tk_activatePlugin", "lws_tools_activate_plugin");
903 function lws_tools_activate_plugin()
904 {
905 if (isset($_POST['ajax_slug'])) {
906 switch (sanitize_textarea_field($_POST['ajax_slug'])) {
907 case 'lws-hide-login':
908 activate_plugin('lws-hide-login/lws-hide-login.php');
909 break;
910 case 'lws-sms':
911 activate_plugin('lws-sms/lws-sms.php');
912 break;
913 case 'lws-tools':
914 activate_plugin('lws-tools/lws-tools.php');
915 break;
916 case 'lws-affiliation':
917 activate_plugin('lws-affiliation/lws-affiliation.php');
918 break;
919 case 'lws-cleaner':
920 activate_plugin('lws-cleaner/lws-cleaner.php');
921 break;
922 case 'lwscache':
923 activate_plugin('lwscache/lwscache.php');
924 break;
925 case 'lws-optimize':
926 activate_plugin('lws-optimize/lws-optimize.php');
927 break;
928 }
929 }
930 wp_die();
931 }
932 //
933
934 /*END AJAX*/
935
936 //AJAX Plugins//
937 add_action("wp_ajax_lwstools_updateAllPlugin", "lws_tk_update_all_plugin");
938 function lws_tk_update_all_plugin()
939 {
940 $pu = new Plugin_Upgrader();
941 $update_all = array();
942 foreach (get_site_transient('update_plugins')->response as $plugin) {
943 $update_all[] = $plugin->plugin;
944 }
945 $pu->bulk_upgrade($update_all);
946 wp_die();
947 }
948
949 add_action("wp_ajax_lwstools_updatePlugin", "lws_tk_update_plugin");
950 function lws_tk_update_plugin()
951 {
952 $pu = new Plugin_Upgrader();
953 $plugin_package = sanitize_text_field($_POST['lws_tk_update_plugin_specific']);
954 $pu->upgrade($plugin_package);
955 $pu->plugin_info();
956 wp_die();
957 }
958 //
959
960 //AJAX Themes//
961 add_action("wp_ajax_lwstools_updateAllTheme", "lws_tk_update_all_theme");
962 function lws_tk_update_all_theme()
963 {
964 $tu = new Theme_Upgrader();
965 $update_all = array();
966 foreach (get_site_transient('update_themes')->response as $theme) {
967 $update_all[] = $theme['theme'];
968 }
969 $tu->bulk_upgrade($update_all);
970 wp_die();
971 }
972
973 add_action("wp_ajax_lwstools_updateTheme", "lws_tk_update_theme");
974 function lws_tk_update_theme()
975 {
976 $tu = new Theme_Upgrader();
977 $theme_package = sanitize_text_field($_POST['lws_tk_update_theme_specific']);
978 $tu->upgrade($theme_package);
979 wp_die();
980 }
981 //
982
983 //AJAX Unused Plugins//
984 add_action("wp_ajax_lwstools_deleteAllPlugin", "lws_tk_delete_all_plugin");
985 function lws_tk_delete_all_plugin()
986 {
987 $to_delete = array();
988 foreach (get_plugins() as $slug => $plugin) {
989 if (!is_plugin_active($slug) && !is_plugin_active_for_network($slug)) {
990 $to_delete[] = $slug;
991 }
992 }
993 delete_plugins($to_delete);
994 wp_die();
995 }
996
997 add_action("wp_ajax_lwstools_deletePlugin", "lws_tk_delete_plugin");
998 function lws_tk_delete_plugin()
999 {
1000 $plugin_package = sanitize_text_field($_POST['lws_tk_delete_plugin_specific']);
1001 delete_plugins([$plugin_package]);
1002 wp_die();
1003 }
1004 //
1005
1006 //AJAX Unused Themes//
1007 add_action("wp_ajax_lwstools_deleteAllTheme", "lws_tk_delete_all_theme");
1008 function lws_tk_delete_all_theme()
1009 {
1010 foreach (wp_get_themes() as $slug => $theme) {
1011 if ($theme['Name'] != wp_get_theme()->name) {
1012 delete_theme($slug);
1013 }
1014 }
1015 wp_die();
1016 }
1017
1018 add_action("wp_ajax_lwstools_deleteTheme", "lws_tk_delete_theme");
1019 function lws_tk_delete_theme()
1020 {
1021 $theme_package = sanitize_text_field($_POST['lws_tk_delete_theme_specific']);
1022 delete_theme($theme_package);
1023 wp_die();
1024 }
1025 //
1026
1027 //AJAX DL Plugin//
1028 add_action("wp_ajax_lwstools_downloadPlugin", "wp_ajax_install_plugin");
1029 //
1030
1031 //AJAX Activate Plugin//
1032 add_action("wp_ajax_lwstools_activatePlugin", "lws_tk_activate_plugin");
1033 function lws_tk_activate_plugin()
1034 {
1035 if (isset($_POST['ajax_slug'])) {
1036 switch (sanitize_textarea_field($_POST['ajax_slug'])) {
1037 case 'lws-hide-login':
1038 activate_plugin('lws-hide-login/lws-hide-login.php');
1039 break;
1040 case 'lws-sms':
1041 activate_plugin('lws-sms/lws-sms.php');
1042 break;
1043 case 'lws-tools':
1044 activate_plugin('lws-tools/lws-tools.php');
1045 break;
1046 case 'lws-affiliation':
1047 activate_plugin('lws-affiliation/lws-affiliation.php');
1048 break;
1049 case 'lws-cleaner':
1050 activate_plugin('lws-cleaner/lws-cleaner.php');
1051 break;
1052 case 'lwscache':
1053 activate_plugin('lwscache/lwscache.php');
1054 break;
1055 case 'lws-optimize':
1056 activate_plugin('lws-optimize/lws-optimize.php');
1057 break;
1058 }
1059 }
1060 wp_die();
1061 }
1062 //
1063
1064 //AJAX Update Trads//
1065 add_action("wp_ajax_lwstools_updateTrads", "lws_tk_update_trads");
1066 function lws_tk_update_trads()
1067 {
1068 $lp = new Language_Pack_Upgrader();
1069 $lp->bulk_upgrade();
1070 wp_die();
1071 }
1072 //
1073
1074 //AJAX Repair DB//
1075 add_action("wp_ajax_lwstools_repairdb", "lws_tk_repairdb");
1076 function lws_tk_repairdb()
1077 {
1078 $config_page = ABSPATH . 'wp-config.php';
1079 $config_page_content = file($config_page);
1080 foreach ($config_page_content as $content) {
1081 if (preg_match('/^define\(\s*\'([A-Z_]+)\',(.*)\)/', $content, $match)) {
1082 if ('WP_ALLOW_REPAIR' === $match[1]) {
1083 echo esc_url(get_site_url() . "/wp-admin/maint/repair.php?repair=1");
1084 wp_die();
1085 }
1086 }
1087 }
1088 array_shift($config_page_content);
1089 array_unshift($config_page_content, "<?php\r\ndefine('WP_ALLOW_REPAIR', true);\r\n");
1090 $file = @fopen($config_page, 'w');
1091 foreach ($config_page_content as $line) {
1092 @fwrite($file, $line);
1093 }
1094 @fclose($file);
1095 echo esc_url(get_site_url() . "/wp-admin/maint/repair.php?repair=1");
1096 wp_die();
1097 /*@exec("wp config set WP_ALLOW_REPAIR true --raw");
1098 echo esc_url(get_site_url() . "/wp-admin/maint/repair.php?repair=1");
1099 wp_die();*/
1100 }
1101 //
1102
1103 //AJAX Opti DB//
1104 add_action("wp_ajax_lwstools_optidb", "lws_tk_optidb");
1105 function lws_tk_optidb()
1106 {
1107 $config_page = ABSPATH . 'wp-config.php';
1108 $config_page_content = file($config_page);
1109 foreach ($config_page_content as $content) {
1110 if (preg_match('/^define\(\s*\'([A-Z_]+)\',(.*)\)/', $content, $match)) {
1111 if ('WP_ALLOW_REPAIR' === $match[1]) {
1112 echo esc_url(get_site_url() . "/wp-admin/maint/repair.php?repair=2");
1113 wp_die();
1114 }
1115 }
1116 }
1117 array_shift($config_page_content);
1118 array_unshift($config_page_content, "<?php\r\ndefine('WP_ALLOW_REPAIR', true);\r\n");
1119 $file = @fopen($config_page, 'w');
1120 foreach ($config_page_content as $line) {
1121 @fwrite($file, $line);
1122 }
1123 @fclose($file);
1124 echo esc_url(get_site_url() . "/wp-admin/maint/repair.php?repair=2");
1125 wp_die();
1126 /*@exec("wp config set WP_ALLOW_REPAIR true --raw");
1127 echo esc_url(get_site_url() . "/wp-admin/maint/repair.php?repair=2");
1128 wp_die();*/
1129 }
1130 //
1131
1132 //AJAX Deactivate Repair DB//
1133 add_action("wp_ajax_lwstools_deactivate_repair", "lws_tk_deactivate_repairdb");
1134 function lws_tk_deactivate_repairdb()
1135 {
1136 $config_page = ABSPATH . 'wp-config.php';
1137 $config_page_content = file($config_page);
1138 foreach ($config_page_content as $key => $content) {
1139 if (preg_match('/^define\(\s*\'([A-Z_]+)\',(.*)\)/', $content, $match)) {
1140 if ('WP_ALLOW_REPAIR' === $match[1]) {
1141 $config_page_content[$key] = "";
1142 $file = @fopen($config_page, 'w');
1143 foreach ($config_page_content as $line) {
1144 @fwrite($file, $line);
1145 }
1146 @fclose($file);
1147 wp_die();
1148 }
1149 }
1150 }
1151 wp_die();
1152 /*@exec("wp config delete WP_ALLOW_REPAIR");
1153 wp_die();*/
1154 }
1155 //
1156
1157 //AJAX Disconnect everyone but user//
1158 add_action("wp_ajax_lwstools_disconnectall", "lws_tk_disconnect_all");
1159 function lws_tk_disconnect_all()
1160 {
1161 check_ajax_referer('disconnect_all_and_everyone', '_ajax_nonce');
1162 foreach (get_users(array( 'fields' => array( 'ID' ))) as $user) {
1163 if ($user->ID == get_current_user_id()) {
1164 $sessions = WP_Session_Tokens::get_instance(get_current_user_id());
1165 $sessions->destroy_others(wp_get_session_token());
1166 } else {
1167 $sessions = WP_Session_Tokens::get_instance($user->ID);
1168 $sessions->destroy_all();
1169 }
1170 }
1171 wp_die();
1172 }
1173 //
1174
1175 //AJAX Delete revisions older than $days//
1176 add_action("wp_ajax_lwstools_delete_revisions", "lws_tk_delete_revision");
1177 function lws_tk_delete_revision()
1178 {
1179 check_ajax_referer('delete_all_revisions', '_ajax_nonce');
1180 global $wpdb;
1181 $days = sanitize_text_field($_POST['lws_tk_days_revisions']);
1182 $wpdb->get_results("DELETE FROM `" . $wpdb->prefix . "posts` WHERE post_type='revision' AND post_modified < '" . date("Y-m-d H:i:s", time() - (24*60*60*$days)) . "';");
1183 wp_die();
1184 }
1185 //
1186
1187 //AJAX Delete Trashed comments//
1188 add_action("wp_ajax_lwstools_delete_trash_comments", "lws_tk_delete_trash_comments");
1189 function lws_tk_delete_trash_comments()
1190 {
1191 check_ajax_referer('delete_all_trash_comments', '_ajax_nonce');
1192 global $wpdb;
1193 $wpdb->get_results("DELETE FROM `" . $wpdb->prefix . "comments` WHERE comment_approved='trash'");
1194 wp_die();
1195 }
1196 //
1197
1198 //AJAX Delete Trashed comments//
1199 add_action("wp_ajax_lwstools_delete_spam_comments", "lws_tk_delete_spam_comments");
1200 function lws_tk_delete_spam_comments()
1201 {
1202 check_ajax_referer('delete_all_spam_comms', '_ajax_nonce');
1203 global $wpdb;
1204 $wpdb->get_results("DELETE FROM `" . $wpdb->prefix . "comments` WHERE comment_approved='spam'");
1205 wp_die();
1206 }
1207 //
1208
1209 //AJAX Delete old transients//
1210 add_action("wp_ajax_lwstools_delete_transients", "lws_tk_delete_old_transients");
1211 function lws_tk_delete_old_transients()
1212 {
1213 check_ajax_referer('delete_all_transients', '_ajax_nonce');
1214 delete_expired_transients();
1215 wp_die();
1216 }
1217 //
1218
1219 //AJAX Keep Config even after delete//
1220 add_action("wp_ajax_lwstools_keep_changes", "lws_tk_keep_changes");
1221 function lws_tk_keep_changes()
1222 {
1223 check_ajax_referer('keep_on_delete_change', '_ajax_nonce');
1224 $is_checked = sanitize_text_field($_POST['state']);
1225 $is_checked == 'true' ? update_option('lws_tk_keep_data_on_delete', true) : delete_option('lws_tk_keep_data_on_delete');
1226 wp_die();
1227 }
1228 //
1229
1230 ///END AJAX///
1231