navasena/wp-content/plugins/mailchimp-for-wp/includes/admin/migrations/4.0.7-rename-debug-log-file...

34 lines
960 B
PHP
Raw Permalink Normal View History

2024-07-31 13:12:38 +07:00
<?php
defined('ABSPATH') or exit;
// get old log filename
$upload_dir = wp_upload_dir(null, false);
$old_filename = trailingslashit($upload_dir['basedir']) . 'mc4wp-debug.log';
$new_filename = trailingslashit($upload_dir['basedir']) . 'mc4wp-debug-log.php';
// check if old default log file exists
if (! file_exists($old_filename)) {
return;
}
// rename to new file.
@rename($old_filename, $new_filename);
// if success, insert php exit tag as first line
if (file_exists($new_filename)) {
$handle = fopen($new_filename, 'r+');
if (is_resource($handle)) {
// make sure first line of log file is a PHP tag + exit statement (to prevent direct file access)
$line = fgets($handle);
$php_exit_string = '<?php exit; ?>';
if (strpos($line, $php_exit_string) !== 0) {
rewind($handle);
fwrite($handle, $php_exit_string . PHP_EOL . $line);
}
fclose($handle);
}
}