-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix undefined array key #86
Conversation
Warning Rate Limit Exceeded@efuller has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 15 minutes and 37 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, convert this PR to a draft and then mark it as ready for review again to re-trigger the review. Alternatively, you can push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per repository. WalkthroughThe version 1.4.0 update for Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- CHANGELOG.md (1 hunks)
- src/class-plugin-curated-posts.php (1 hunks)
- wp-curate.php (1 hunks)
Files skipped from review due to trivial changes (2)
- CHANGELOG.md
- wp-curate.php
Additional comments: 1
src/class-plugin-curated-posts.php (1)
- 62-62: The change here is a good one. It adds an additional check to ensure that the 'termRelations' key exists in the
$attributes
array before attempting to access its value. This will prevent potential "undefined array key" errors. The logic is sound and the code is more robust with this change.- 'operator' => is_array( $attributes['termRelations'] ) ? $attributes['termRelations'][ $taxonomy ] ?? 'AND' : 'AND', + 'operator' => array_key_exists( 'termRelations', $attributes ) && is_array( $attributes['termRelations'] ) ? $attributes['termRelations'][ $taxonomy ] ?? 'AND' : 'AND',
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/class-plugin-curated-posts.php
Outdated
@@ -59,7 +59,7 @@ public function with_query_context( array $context, array $attributes, WP_Block_ | |||
$args['tax_query'][] = [ | |||
'taxonomy' => $taxonomy, | |||
'terms' => array_column( $terms, 'id' ), | |||
'operator' => is_array( $attributes['termRelations'] ) ? $attributes['termRelations'][ $taxonomy ] ?? 'AND' : 'AND', | |||
'operator' => array_key_exists( 'termRelations', $attributes ) && is_array( $attributes['termRelations'] ) ? $attributes['termRelations'][ $taxonomy ] ?? 'AND' : 'AND', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new code adds an additional check to ensure that the 'termRelations' key exists in the $attributes
array before attempting to access its value. This is a good practice as it prevents potential "undefined index" errors. However, the check for is_array( $attributes['termRelations'] )
is redundant because if 'termRelations' exists in $attributes
and is not an array, it would not pass the array_key_exists
check. Therefore, the is_array
check can be removed to simplify the code.
- 'operator' => array_key_exists( 'termRelations', $attributes ) && is_array( $attributes['termRelations'] ) ? $attributes['termRelations'][ $taxonomy ] ?? 'AND' : 'AND',
+ 'operator' => array_key_exists( 'termRelations', $attributes ) ? $attributes['termRelations'][ $taxonomy ] ?? 'AND' : 'AND',
Commitable suggestion (Beta)
'operator' => array_key_exists( 'termRelations', $attributes ) && is_array( $attributes['termRelations'] ) ? $attributes['termRelations'][ $taxonomy ] ?? 'AND' : 'AND', | |
'operator' => array_key_exists('termRelations', $attributes) ? $attributes['termRelations'][$taxonomy] ?? 'AND' : 'AND', |
Add in a check to prevent this error.
Summary by CodeRabbit
Release Notes for WP Curate Version 1.4.0
These changes aim to improve the reliability of the WP Curate plugin, providing a more seamless and error-free experience for users.