Skip to content

Commit

Permalink
Add File Exists and readable or writable checks
Browse files Browse the repository at this point in the history
Add File Exists and readable or writable checks
  • Loading branch information
namithj committed Jan 4, 2025
1 parent 4752f27 commit 2ef8540
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions includes/class-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public static function read( $limit = 1000 ) {
$wp_filesystem = self::init_filesystem();
$file_path = self::get_file_path();

if ( ! $wp_filesystem->exists( $file_path ) || ! $wp_filesystem->is_readable( $file_path ) ) {
return new \WP_Error( 'not_readable', __( 'Error: Unable to read the log file.', 'aspireupdate' ) );
}

$file_content = $wp_filesystem->get_contents_array( $file_path, $limit, true );

if ( ( false === $file_content ) || ( 0 === count( $file_content ) ) ) {
Expand All @@ -80,6 +84,10 @@ public static function clear() {
$wp_filesystem = self::init_filesystem();
$file_path = self::get_file_path();

if ( ! $wp_filesystem->exists( $file_path ) || ! $wp_filesystem->is_writable( $file_path ) ) {
return new \WP_Error( 'not_accessible', __( 'Error: Unable to access the log file.', 'aspireupdate' ) );
}

$wp_filesystem->put_contents(
$file_path,
'',
Expand Down

0 comments on commit 2ef8540

Please sign in to comment.