chore: clean up runtime helper usage#9
Merged
Conversation
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR continues the runtime-helper cleanup by replacing discouraged PHP helpers with WordPress equivalents, reducing repeated count() calls inside loops, and consolidating ad-hoc error_log() usage through the plugin’s centralized WPVDB\Logger.
Changes:
- Replace
parse_url()/json_encode()withwp_parse_url()/wp_json_encode()in runtime/admin/core paths. - Hoist
count()calls out of loop conditions to avoid repeated evaluations. - Route direct
error_log()calls throughWPVDB\Logger(and add PHPCS ignore whereerror_log()remains as the centralized sink).
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| includes/wpvdb-runtime.php | Switch URL parsing to wp_parse_url() for WordPress-consistent behavior. |
| includes/class-wpvdb-utils.php | Hoist unit count() out of loop condition. |
| includes/class-wpvdb-settings.php | Replace direct error_log() with Logger::critical() for settings diagnostics. |
| includes/class-wpvdb-security.php | Route security debug logging through Logger. |
| includes/class-wpvdb-rest.php | Use wp_json_encode() and route debug/error logs through Logger; minor loop tweak. |
| includes/class-wpvdb-queue.php | Route debug deletion log through Logger. |
| includes/class-wpvdb-query.php | Route query-path debug/error logs through Logger and use wp_json_encode(). |
| includes/class-wpvdb-providers.php | Switch URL parsing to wp_parse_url(). |
| includes/class-wpvdb-plugin.php | Route deactivation debug log through Logger. |
| includes/class-wpvdb-logger.php | Add PHPCS ignore to the centralized error_log() sink. |
| includes/class-wpvdb-database.php | Route DB capability diagnostics through Logger. |
| includes/class-wpvdb-core.php | Use wp_json_encode() for non-string payload normalization. |
| includes/class-wpvdb-cache.php | Route cache debug logs through Logger and remove redundant WP_DEBUG nesting. |
| includes/class-wpvdb-admin.php | Route admin debug logs through Logger; use wp_json_encode(). |
| includes/class-wpvdb-activation.php | Route activation/upgrade diagnostics through Logger. |
| admin/views/status.php | Replace print_r() output with pretty JSON for display. |
| admin/views/embeddings.php | Replace error_log() with \WPVDB\Logger and use wp_json_encode() for debug serialization. |
Comments suppressed due to low confidence (5)
includes/class-wpvdb-query.php:157
- Database errors are currently logged with Logger::debug(). Since Logger routes to wpvdb_should_log_to_error_log using the provided $level, consider logging $wpdb->last_error via Logger::error() so it can be surfaced when wpvdb_log_level is set to error (and for consumers filtering by level).
if ( $wpdb->last_error ) {
Logger::debug( 'Database error in vector search: ' . $wpdb->last_error );
}
includes/class-wpvdb-query.php:170
- Exceptions in the vector search path are logged at debug level. These represent failures to execute the search and are usually better captured via Logger::error() (or at least warning()) so they aren't dropped when only error+ logs are retained.
} catch ( \Exception $e ) {
Logger::debug( 'Exception in vector search: ' . $e->getMessage() );
}
includes/class-wpvdb-query.php:212
- The catch-all 'Unhandled exception' is logged via Logger::debug(). Consider Logger::error() here so unexpected failures remain visible when the log level is configured above debug.
} catch ( \Exception $e ) {
Logger::debug( 'Unhandled exception in maybe_vector_search: ' . $e->getMessage() );
}
includes/class-wpvdb-activation.php:326
- A catch-all "Fatal error" is currently logged with Logger::debug(). This should likely be Logger::critical() or Logger::error() so it isn't filtered out by minimum log level settings.
} catch ( \Exception $e ) {
// Catch all exceptions to prevent activation failure.
Logger::debug( 'Fatal error in add_vector_index_to_existing_table: ' . $e->getMessage() );
return false;
includes/class-wpvdb-activation.php:285
- The fallback index creation path logs success/failure at debug level. For the failure branch (uses $wpdb->last_error), consider Logger::error() so operational issues are not silently dropped by minimum log level settings.
if ( false !== $result ) {
Logger::debug( 'Added vector index with simplified syntax' );
} else {
Logger::debug( 'Failed to add vector index with simplified syntax: ' . $wpdb->last_error );
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Codex <noreply@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR removes the low risk runtime helper PHPCS group from the current standards backlog. It replaces discouraged PHP helpers with WordPress equivalents, hoists loop count calls out of for conditions, and routes direct debug log calls through the central WPVDB logger.
It keeps the branch scoped to runtime helper cleanup. Escaping, database query, translator comment, and redirect safety work stay in follow up PRs.
Validation