PluginProbe
LWS Tools / 2.3
LWS Tools v2.3
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.3, at lws-tools.php

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