is_dir(self::$log_dir)) { if (!$wp_filesystem->mkdir(self::$log_dir, FS_CHMOD_DIR)) { return false; } } // Ensure proper permissions and add index.php for security $wp_filesystem->chmod(self::$log_dir, FS_CHMOD_DIR); // Add security files to prevent directory listing and direct access $security_files = array( 'index.php' => ' 'deny from all' ); foreach ($security_files as $file => $content) { if (!$wp_filesystem->exists(self::$log_dir . '/' . $file)) { $wp_filesystem->put_contents( self::$log_dir . '/' . $file, $content ); } } return self::$log_dir.'/'.$file_name; } /** * Checks a log file created for the history entry for current day * @param int $history_id id of history entry * @return string/bool if file found returns file name otherwise false */ public static function check_log_exists_for_entry($history_id) { $log_dir=self::get_file_path(); $exp='~^'.$history_id.'.*\.log$~'; $files = preg_grep($exp, scandir($log_dir)); if(count($files)>0) /* file exists */ { foreach($files as $key => $value) { $file_name=pathinfo($value, PATHINFO_FILENAME); $file_name_arr=explode('_', $file_name); $file_date_time=end($file_name_arr); $file_date_time_arr=explode(' ', $file_date_time); $file_time=strtotime($file_date_time_arr[0]); if($file_time) //file time exists { $today=strtotime(gmdate('Y-m-d')); $file_time=strtotime(gmdate('Y-m-d', $file_time)); if($today==$file_time) //file exists with the current day { return $value; } } } } return false; } /** * Generate log file name * */ public static function generate_file_name($post_type='', $action_type='', $history_id='') { $arr=array($history_id, $post_type); if(defined( 'WT_IEW_CRON' )) /* this is a cron run so add a schedule prefix */ { $arr[]='schedule'; } $arr[]=$action_type; $arr[]=gmdate('Y-m-d h i s A'); /* if changing this format please consider `check_log_exists_for_entry` method */ $arr=array_filter($arr); return implode("_", $arr).'.log'; } } }