PluginProbe
Linguise – AI Automatic Multilingual Translation / trunk
Linguise – AI Automatic Multilingual Translation vtrunk
2.2.64 2.2.63 2.2.62 2.2.61 2.2.60 2.2.59 2.2.58 2.2.57 2.2.56 2.2.55 2.2.54 2.2.53 2.2.52 2.2.51 2.2.50 2.2.49 2.2.47 2.2.48 2.2.46 2.2.45 2.2.44 2.2.43 2.2.42 1.9.7 1.9.8 All 255 releases
linguise / src / debug.php

debug.php in Linguise – AI Automatic Multilingual Translation trunk, at src/debug.php

78 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || die('');
3
4 add_action('wp_ajax_linguise_download_debug', function () {
5 // check user capabilities
6 if (!current_user_can('manage_options')) {
7 return;
8 }
9
10 $debug_file = LINGUISE_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'linguise' . DIRECTORY_SEPARATOR . 'script-php' . DIRECTORY_SEPARATOR . 'debug.php';
11 if (!file_exists($debug_file)) {
12 wp_die('No debug file found');
13 }
14
15 if (file_exists($debug_file)) {
16 // @codeCoverageIgnoreStart
17 header('Content-Description: File Transfer');
18 header('Content-Type: application/octet-stream');
19 header('Content-Disposition: attachment; filename="debug.txt"');
20 header('Content-Transfer-Encoding: binary');
21 header('Expires: 0');
22 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
23 header('Pragma: public');
24 header('Content-Length: ' . filesize($debug_file));
25 ob_clean();
26 ob_end_flush();
27 $handle = fopen($debug_file, 'rb');
28 while (! feof($handle)) {
29 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
30 echo fread($handle, 1000);
31 }
32 die();
33 // @codeCoverageIgnoreEnd
34 }
35 });
36
37 add_action('wp_ajax_linguise_truncate_debug', function () {
38 // check user capabilities
39 if (!current_user_can('manage_options')) {
40 return;
41 }
42
43 check_admin_referer('_linguise_nonce_');
44
45 $log_path = LINGUISE_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'linguise' . DIRECTORY_SEPARATOR . 'script-php' . DIRECTORY_SEPARATOR;
46 $full_debug_file = $log_path . 'debug.php';
47 $last_errors_file = $log_path . 'errors.php';
48
49 if (file_exists($full_debug_file)) {
50 file_put_contents($full_debug_file, '<?php die(); ?>' . PHP_EOL);
51 }
52
53 if (file_exists($last_errors_file)) {
54 file_put_contents($last_errors_file, '<?php die(); ?>' . PHP_EOL);
55 }
56
57 wp_send_json_success('Log truncated!');
58 });
59
60 add_action('wp_ajax_linguise_disable_debug', function () {
61 if (!current_user_can('manage_options')) {
62 // @codeCoverageIgnoreStart
63 header('Content-Type: application/json; charset=UTF-8');
64 echo wp_json_encode(['success' => false]);
65 die();
66 // @codeCoverageIgnoreEnd
67 }
68
69 check_admin_referer('_linguise_nonce_');
70
71 linguiseSwitchMainSite();
72 $options = linguiseGetOptions();
73 $options['debug'] = false;
74 update_option('linguise_options', $options);
75 linguiseRestoreMultisite();
76 wp_send_json_success('Debug disabled!');
77 });
78