-
Notifications
You must be signed in to change notification settings - Fork 5
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 CL by-author on frontend #5624
Conversation
WalkthroughIn Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 3
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- core/class-maxi-dynamic-content.php (3 hunks)
Additional comments not posted (1)
core/class-maxi-dynamic-content.php (1)
257-257
: Ensure the WP_Query instance is properly utilized.The instantiation of
WP_Query
here is standard and follows WordPress best practices for custom queries.
@@ -1120,7 +1121,7 @@ public function get_post($attributes) | |||
|
|||
$query = new WP_Query($args); | |||
|
|||
if (empty($query->posts) && !$is_current_archive) { | |||
if (empty($query->posts) && !$is_current_archive && $dc_relation !== 'by-author') { |
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.
Check for potential infinite recursion.
- return $this->get_post(array_replace($attributes, $validated_attributes));
+ // Ensure there is a condition to break the recursion
+ if ($someCondition) {
+ return $this->get_post(array_replace($attributes, $validated_attributes));
+ } else {
+ return null;
+ }
This recursive call to get_post
could potentially lead to infinite recursion if the conditions are always met. Consider adding a termination condition or a maximum recursion depth.
Committable suggestion was skipped due to low confidence.
Optimize the validation logic for orderby attributes.
- $validated_attributes = self::get_validated_orderby_attributes($dc_relation, $dc_id);
- if (in_array($dc_relation, self::$order_by_relations) && $validated_attributes) {
+ $validated_attributes = $this->get_validated_orderby_attributes($dc_relation, $dc_id);
+ if ($validated_attributes) {
Refactor the method to use instance method access ($this->
) instead of static method access (self::
) since get_validated_orderby_attributes
is not a static method. Also, simplify the condition to check only if validated attributes exist.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (empty($query->posts) && !$is_current_archive && $dc_relation !== 'by-author') { | |
if (empty($query->posts) && !$is_current_archive && $dc_relation !== 'by-author') { | |
$validated_attributes = $this->get_validated_orderby_attributes($dc_relation, $dc_id); | |
if ($validated_attributes) { |
@@ -2119,6 +2120,7 @@ | |||
} | |||
} elseif($relation === 'by-author') { | |||
$args['author'] = $id; | |||
|
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.
Tip
Codebase Verification
The extraction of the switch statements shows that some types returned by get_current_archive_type_and_id
(such as custom taxonomy and not_an_archive
) are not handled in the switch statements. This indicates that the handling of dynamic archive types is incomplete.
switch ($archive_type)
is missing cases for custom taxonomy andnot_an_archive
.
Please ensure that all possible types returned by get_current_archive_type_and_id
are properly handled in the switch statements.
- Add handling for custom taxonomy.
- Add handling for
not_an_archive
.
Analysis chain
Validate dynamic archive type handling.
Ensure that all possible archive types returned by get_current_archive_type_and_id
are properly handled in the switch statement. This script checks for the presence of all necessary cases.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if all possible archive types are properly handled in the switch statement.
# Test: Search for all usages of `get_current_archive_type_and_id` and ensure all types are handled.
rg --type php $'get_current_archive_type_and_id' | rg --type php $'switch'
Length of output: 70
Script:
#!/bin/bash
# Search for the definition of the function `get_current_archive_type_and_id` in the codebase.
ast-grep --lang php --pattern 'function get_current_archive_type_and_id() { $$$ }'
Length of output: 191
Script:
#!/bin/bash
# Search for the definition of the function `get_current_archive_type_and_id` in the codebase.
rg --type php 'function get_current_archive_type_and_id'
Length of output: 148
Script:
#!/bin/bash
# Extract the implementation of the function `get_current_archive_type_and_id` from the file.
rg --type php -A 50 'function get_current_archive_type_and_id' core/class-maxi-dynamic-content.php
Length of output: 2179
Script:
#!/bin/bash
# Search for switch statements handling the return value of `get_current_archive_type_and_id`.
rg --type php -A 10 'switch.*get_current_archive_type_and_id' core/class-maxi-dynamic-content.php
Length of output: 99
Script:
#!/bin/bash
# Search for all switch statements in the file `core/class-maxi-dynamic-content.php`.
rg --type php 'switch' core/class-maxi-dynamic-content.php
Length of output: 299
Script:
#!/bin/bash
# Extract the code for the switch statements handling $archive_info['type'] and $archive_type.
rg --type php -A 20 'switch \(\$archive_info\[\'type\'\]\)' core/class-maxi-dynamic-content.php
rg --type php -A 20 'switch \(\$archive_type\)' core/class-maxi-dynamic-content.php
Length of output: 93
Script:
#!/bin/bash
# Extract the code for the switch statements handling $archive_info['type'] and $archive_type.
rg --type php -A 20 'switch \(\$archive_info\['type'\]\)' core/class-maxi-dynamic-content.php
rg --type php -A 20 'switch \(\$archive_type\)' core/class-maxi-dynamic-content.php
Length of output: 1073
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.
yes, local is ok now
Great, tx, going to try to fix backend in another PR. |
Description
Fixes CL / DC by author on frontend for pagination (or when we have fewer posts that we need for one page).
Fixes #5623
How Has This Been Tested?
Basically, test CL by author.
Test checklist
_ Front/Back Testing _
_ Pre-Code Testing _
Checklist
Summary by CodeRabbit