debug_enabled ) { return $this->unavailable( 'wp_debug_disabled', '' ); } $path = $this->configured_path(); if ( '' === $path ) { return $this->unavailable( 'not_configured', '' ); } if ( ! $this->is_absolute_path( $path ) ) { return $this->unavailable( 'not_configured', $path ); } if ( ! file_exists( $path ) ) { return $this->unavailable( 'not_created', $path ); } if ( ! is_readable( $path ) ) { return $this->unavailable( 'not_readable', $path ); } return array( 'status' => 'available', 'reason' => '', 'message' => esc_html__( 'Debug log file is available and readable.', 'actionpanel-ai' ), 'path' => $path, ); } /** * Resolve the configured debug log path. */ private function configured_path(): string { if ( true === $this->debug_log_setting || 1 === $this->debug_log_setting ) { return $this->default_debug_log_path(); } if ( is_string( $this->debug_log_setting ) ) { $value = trim( $this->debug_log_setting ); if ( in_array( strtolower( $value ), array( '1', 'true' ), true ) ) { return $this->default_debug_log_path(); } return $value; } return ''; } /** * Build the default debug.log path for boolean WP_DEBUG_LOG forms. */ private function default_debug_log_path(): string { $content_dir = rtrim( $this->content_dir, '/\\' ); return '' === $content_dir ? '' : $content_dir . '/debug.log'; } /** * Return a structured unavailable result. */ private function unavailable( string $reason, string $path ): array { return array( 'status' => 'unavailable', 'reason' => $reason, 'message' => $this->message_for_reason( $reason ), 'path' => $path, ); } /** * Return administrator-facing text for an unavailable debug log. */ private function message_for_reason( string $reason ): string { if ( 'wp_debug_disabled' === $reason ) { return esc_html__( 'Log reads require WP_DEBUG to be enabled.', 'actionpanel-ai' ); } if ( 'not_configured' === $reason ) { return esc_html__( 'Set WP_DEBUG_LOG to true or an absolute file path before using log reads.', 'actionpanel-ai' ); } if ( 'not_created' === $reason ) { return esc_html__( 'The configured WP_DEBUG_LOG file does not exist yet.', 'actionpanel-ai' ); } if ( 'not_readable' === $reason ) { return esc_html__( 'The configured WP_DEBUG_LOG file is not readable by PHP.', 'actionpanel-ai' ); } return esc_html__( 'No readable WordPress debug log file is configured.', 'actionpanel-ai' ); } /** * Return whether the path is absolute on Unix or Windows. */ private function is_absolute_path( string $path ): bool { return '' !== $path && ( str_starts_with( $path, '/' ) || 1 === preg_match( '/^[A-Za-z]:[\\\\\\/]/', $path ) ); } }