| 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 |
* Returns WordPress GMT offset in seconds. |
| 45 |
* |
| 46 |
* @return int |
| 47 |
*/ |
| 48 |
public static function get_gmt_offset() { |
| 49 |
$timezone_string = get_option('timezone_string'); |
| 50 |
|
| 51 |
if (!empty($timezone_string)) { |
| 52 |
$timezone = new DateTimeZone($timezone_string); |
| 53 |
$gmt_offset = $timezone->getOffset(new DateTime()); |
| 54 |
} else { |
| 55 |
$gmt_offset_option = get_option('gmt_offset'); |
| 56 |
$gmt_offset = (int) (3600 * $gmt_offset_option); |
| 57 |
} |
| 58 |
|
| 59 |
return $gmt_offset; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
endif; |
| 64 |
|