| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die('Access denied.'); |
| 4 |
|
| 5 |
if (!class_exists('WP_Optimize_Utils')) : |
| 6 |
|
| 7 |
class WP_Optimize_Utils { |
| 8 |
|
| 9 |
/** |
| 10 |
* Returns the folder path for log files |
| 11 |
* |
| 12 |
* @return string - Folder path for log files with trailing slash |
| 13 |
*/ |
| 14 |
public static function get_log_folder_path() { |
| 15 |
$upload_dir = wp_upload_dir(); |
| 16 |
$upload_base = trailingslashit($upload_dir['basedir']); |
| 17 |
if (!is_dir($upload_base . 'wpo/logs')) { |
| 18 |
wp_mkdir_p($upload_base . 'wpo/logs'); |
| 19 |
} |
| 20 |
return $upload_base . 'wpo/logs/'; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Generates a log file name based on the given prefix. |
| 25 |
* |
| 26 |
* @param string $prefix The prefix to be added to the log file name. |
| 27 |
* @return string The generated log file name. |
| 28 |
*/ |
| 29 |
public static function get_log_file_name($prefix) { |
| 30 |
return $prefix . '-' . substr(md5(wp_salt()), 0, 20) . '.log'; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Returns the file path for the log file. |
| 35 |
* |
| 36 |
* @param string $prefix The prefix to be added to the log file name. |
| 37 |
* @return string The file path for the log file. |
| 38 |
*/ |
| 39 |
public static function get_log_file_path($prefix) { |
| 40 |
return self::get_log_folder_path() . self::get_log_file_name($prefix); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
endif; |
| 45 |
|