-
Notifications
You must be signed in to change notification settings - Fork 59
Fix server info base #461
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 8000 send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix server info base #461
Conversation
WalkthroughThe changes systematically refactor how the WordPress version is retrieved across multiple classes. The global Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ServerInfoBase as MainWP_Child_Server_Information_Base
participant WordPressCore
Caller->>ServerInfoBase: get_wordpress_version()
alt \wp_get_wp_version() exists
ServerInfoBase->>WordPressCore: \wp_get_wp_version()
WordPressCore-->>ServerInfoBase: WordPress version
ServerInfoBase-->>Caller: WordPress version
else
ServerInfoBase->>WordPressCore: access $wp_version global
WordPressCore-->>ServerInfoBase: WordPress version
ServerInfoBase-->>Caller: WordPress version
end
sequenceDiagram
participant MainWP_Class
participant ServerInfoBase as MainWP_Child_Server_Information_Base
MainWP_Class->>ServerInfoBase: get_wordpress_version()
ServerInfoBase-->>MainWP_Class: WordPress version
MainWP_Class->>MainWP_Class: Use version in logic (backup, diagnostics, stats, etc.)
Possibly related PRs
🪧 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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration 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: 0
🧹 Nitpick comments (2)
class/class-mainwp-child-back-up-buddy.php (1)
3047-3051
: 🔧 Qualify class reference for clarity
You’re correctly replacing direct global access withMainWP_Child_Server_Information_Base::get_wordpress_version()
. To avoid any ambiguity in namespace resolution, consider one of the following optional refinements:
- Prepend a leading backslash:
$wp_ver = \MainWP\Child\MainWP_Child_Server_Information_Base::get_wordpress_version();- Or add at the top of the file:
and then keep your existing call.use MainWP\Child\MainWP_Child_Server_Information_Base;class/class-mainwp-child-updraft-plus-backups.php (1)
2252-2252
: Consider removing the possibly redundant version.php include.Since you're now using
MainWP_Child_Server_Information_Base::get_wordpress_version()
instead of the global$wp_version
variable, the include ofversion.php
might be redundant unless it's needed elsewhere in the method.-include_once ABSPATH . WPINC . '/version.php'; // NOSONAR - WP compatible.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
class/class-mainwp-child-actions.php
(3 hunks)class/class-mainwp-child-back-up-buddy.php
(2 hunks)class/class-mainwp-child-plugins-check.php
(1 hunks)class/class-mainwp-child-server-information-base.php
(2 hunks)class/class-mainwp-child-stats.php
(3 hunks)class/class-mainwp-child-updates.php
(2 hunks)class/class-mainwp-child-updraft-plus-backups.php
(2 hunks)class/class-mainwp-child-vulnerability-checker.php
(2 hunks)class/class-mainwp-child-wordfence.php
(1 hunks)class/class-mainwp-clone.php
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
class/class-mainwp-child-wordfence.php (1)
class/class-mainwp-child-server-information-base.php (1)
get_wordpress_version
(300-314)
class/class-mainwp-child-stats.php (2)
class/class-mainwp-child-server-information-base.php (2)
MainWP_Child_Server_Information_Base
(19-795)get_wordpress_version
(300-314)class/class-mainwp-helper.php (3)
MainWP_Helper
(17-1223)is_wp_engine
(921-923)get_wp_host
(946-949)
class/class-mainwp-clone.php (1)
class/class-mainwp-child-server-information-base.php (1)
get_wordpress_version
(300-314)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (24)
class/class-mainwp-child-server-information-base.php (1)
300-314
: Good refactoring of the WordPress version retrieval method.The change from
protected static
topublic static
access modifier forget_wordpress_version()
and the added fallback mechanism improves the architecture by:
- Centralizing WordPress version retrieval in one publicly accessible method
- Using modern WordPress API function
\wp_get_wp_version()
when available- Maintaining backward compatibility with the global
$wp_version
variableThis change aligns with the PR objectives to fix static access issues and improve adherence to WordPress coding standards.
class/class-mainwp-child-plugins-check.php (2)
349-352
: Correctly replaced static method call with direct global variable access.Using a local variable
$wp_ver
assigned from the global$wp_version
is a good practice. This:
- Ensures one-time access to the global variable
- Maintains code readability with a clear local reference
- Aligns with the PR objectives to fix static access to
MainWP_Child_Server_Information_Base
classThis change is consistent with the stated goal of using the global
$wp_version
variable directly.
356-356
: Correctly updated user-agent string to use local variable.The user-agent string now properly uses the local
$wp_ver
variable, maintaining the functionality while improving the code structure.class/class-mainwp-child-back-up-buddy.php (1)
1516-1518
: ✅ Centralize WordPress version retrieval
Switching toMainWP_Child_Server_Information_Base::get_wordpress_version()
instead of using the global ensures consistency and leverages the new fallback to\wp_get_wp_version()
. Confirm thatMainWP_Child_Server_Information_Base
is autoloaded or pre‑loaded in theMainWP\Child
namespace so this call never fails.class/class-mainwp-child-stats.php (5)
107-108
: Improved WordPress version retrieval method.The code now uses
MainWP_Child_Server_Information_Base::get_wordpress_version()
instead of directly accessing the global$wp_version
variable, which is a better practice as it centralizes version retrieval logic.
588-590
: Good refactoring to use centralized version retrieval.Using the static method for getting the WordPress version makes the code more maintainable and consistent with the project's approach to accessing the WordPress version.
595-596
: Consistent use of the version retrieval method.The change ensures consistent use of
MainWP_Child_Server_Information_Base::get_wordpress_version()
throughout the code.
634-635
: Good practice: storing result in a local variable.Creating a local variable
$wp_ver
to store the WordPress version is a good practice as it:
- Avoids multiple calls to the static method
- Makes the code more readable
- Slightly improves performance by reducing function calls
641-641
: Proper usage of the local variable in condition.The version comparison now properly uses the previously stored
$wp_ver
variable instead of accessing the global, maintaining consistency with the refactoring approach.class/class-mainwp-child-updates.php (3)
1218-1220
: Improved version handling with local variable.The code now properly uses a local variable
$wp_ver
assigned from the global$wp_version
, which improves code maintainability and readability. This approach:
- Makes it clear which variable is being used in subsequent code
- Follows the pattern of storing global values in local variables for cleaner code
1226-1227
: Consistent use of the local variable.The code now correctly uses the
$wp_ver
local variable for version comparison and for storing the old version reference. This maintains consistency with the refactoring approach.
1253-1254
: Appropriate use of local variable in fallback code path.The code correctly uses the
$wp_ver
variable in this alternative code path as well, ensuring consistent behavior throughout all execution branches.class/class-mainwp-child-wordfence.php (1)
3340-3341
: Good improvement replacing global variable with centralized method.The change from using
global $wp_version
toMainWP_Child_Server_Information_Base::get_wordpress_version()
improves code quality by centralizing version retrieval. This approach adds an abstraction layer that handles version retrieval consistently across the codebase and adds forward compatibility by preferring\wp_get_wp_version()
when available.class/class-mainwp-clone.php (2)
345-348
: Good refactoring to use centralized version retrieval.The code now uses
MainWP_Child_Server_Information_Base::get_wordpress_version()
instead of accessing the global$wp_version
directly. This improves code maintainability by centralizing WordPress version retrieval logic and follows the PR objective to properly access the WordPress version.
467-467
: Consistent version retrieval implementation.Using the
MainWP_Child_Server_Information_Base::get_wordpress_version()
method here maintains consistency with the version retrieval approach used elsewhere in the file.class/class-mainwp-child-vulnerability-checker.php (4)
311-314
: Good practice: using a local variable for the global WordPress version.Using a local variable
$wp_ver
instead of directly referencing$wp_version
throughout the code is a good practice. It prevents accidental modification of the global variable and makes the code more maintainable.
317-317
: Consistent use of local WordPress version variable.The code correctly uses the local
$wp_ver
variable in constructing the API URL, maintaining consistency with the variable declaration approach.
326-327
: Consistent use of local WordPress version variable.Properly using the local
$wp_ver
variable when callingget_vuln_nvd_nist_info()
method.
331-332
: Consistent use of local WordPress version variable.Properly using the local
$wp_ver
variable when callingget_vuln_wordfence_info()
method.class/class-mainwp-child-actions.php (3)
608-618
: Improved code readability with separate global declarations.Separating the global declarations for
$pagenow
and$wp_version
improves code readability and makes it clearer which global variables are being used.
642-646
: Consistent approach to global variable declarations.Similar to the earlier change, this modification separates global declarations for improved readability.
826-826
: Simplified timestamp generation.Using PHP's native
time()
function directly instead ofMainWP_Helper::get_timestamp()
simplifies the code and reduces unnecessary method calls, which is a good practice when the helper method doesn't provide additional value.class/class-mainwp-child-updraft-plus-backups.php (2)
2247-2249
: Good refactoring to use the centralized WordPress version method.The change from using the global
$wp_version
variable to callingMainWP_Child_Server_Information_Base::get_wordpress_version()
is a positive improvement that aligns with the PR objective to address static access issues. This creates better encapsulation and makes the code more maintainable by centralizing version retrieval.
2391-2392
: Successfully updated the version comparison logic.The version comparison code has been correctly updated to use the new
$wp_ver
variable instead of the global$wp_version
, maintaining the same functionality while using the improved version retrieval method.
|
replaced #456 |
- Qualify class reference in class-mainwp-child-back-up-buddy.php - Use MainWP_Child_Server_Information_Base::get_wordpress_version() instead of global - Remove redundant version.php include in class-mainwp-child-updraft-plus-backups.php
Hi there! I wanted to let you know that we've addressed the nitpick comments from CodeRabbitAI in our PR at wpallstars#1. Specifically, we've:
These changes improve code clarity and remove unnecessary includes, making the code more maintainable and efficient. |
@coderabbitai review |
✅ Actions performedReview triggered.
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
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: 2
🔭 Outside diff range comments (1)
class/class-mainwp-child-actions.php (1)
635-646
:⚠️ Potential issueUndefined
$new_version
variable
Incallback__core_updated_successfully()
, you assign$old_version
and$auto_updated
but never set$new_version
before callingsave_actions()
. This will trigger an undefined variable notice. For example:global $wp_version; $old_version = $wp_version; $new_version = MainWP_Child_Server_Information_Base::get_wordpress_version();Ensure
$new_version
is initialized to avoid errors.
🧹 Nitpick comments (5)
class/class-mainwp-child-server-information-base.php (1)
300-314
: Improved WordPress version retrieval methodThe change to make
get_wordpress_version()
public and to add a check for the newer\wp_get_wp_version()
function is a good improvement. This creates a centralized, consistent method for retrieving the WordPress version across the codebase.Consider adding a comment explaining why this method was made public and why it checks for
\wp_get_wp_version()
first, to document the design decision for future maintainers.public static function get_wordpress_version() { /** * The installed version of WordPress. * * @global string $wp_version The installed version of WordPress. */ global $wp_version; + // Use the newer WordPress core function if available, falling back to global variable if ( function_exists( '\wp_get_wp_version' ) ) { return \wp_get_wp_version(); } return $wp_version; }
class/class-mainwp-child-plugins-check.php (1)
347-347
: Consider removing unnecessary includeThe include statement for
version.php
is no longer necessary since you're directly using the global variable that's already available in WordPress core.- include_once ABSPATH . WPINC . '/version.php'; // NOSONAR - WP compatible.
You can verify this with:
#!/bin/bash # Check if $wp_version is available without including version.php rg -A 3 "\$wp_version" wp-settings.phpclass/class-mainwp-child-vulnerability-checker.php (2)
292-294
: Remove superfluous blank lineThe extra blank line after
wp_json_encode( $plug_vuln_filter );
is purely stylistic and interrupts the flow. Consider removing it to keep the method body compact and consistent.
317-319
: URL‑encode the version parameterWhen constructing the NVD API URL, wrap the version in
rawurlencode()
to prevent malformed URLs if the version string contains unexpected characters:$url = $this->wpvulndb_nvd_api . '?virtualMatchString=cpe:2.3:a:WordPress:WordPress:' . rawurlencode( $wp_ver );class/class-mainwp-child-actions.php (1)
607-617
: Remove unused global and unify version lookup
Incallback_automatic_updates_complete()
, the$pagenow
global is declared but never used—this can be removed to clean up the code. Also, consider usingMainWP_Child_Server_Information_Base::get_wordpress_version()
instead of raw$wp_version
for consistency across the codebase.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
class/class-mainwp-child-actions.php
(3 hunks)class/class-mainwp-child-back-up-buddy.php
(2 hunks)class/class-mainwp-child-plugins-check.php
(1 hunks)class/class-mainwp-child-server-information-base.php
(2 hunks)class/class-mainwp-child-stats.php
(3 hunks)class/class-mainwp-child-updates.php
(2 hunks)class/class-mainwp-child-updraft-plus-backups.php
(2 hunks)class/class-mainwp-child-vulnerability-checker.php
(3 hunks)class/class-mainwp-child-wordfence.php
(1 hunks)class/class-mainwp-clone.php
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
class/class-mainwp-clone.php (1)
class/class-mainwp-child-server-information-base.php (1)
get_wordpress_version
(300-314)
class/class-mainwp-child-wordfence.php (1)
class/class-mainwp-child-server-information-base.php (1)
get_wordpress_version
(300-314)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (17)
class/class-mainwp-child-plugins-check.php (2)
349-352
: Replaced static method call with direct global variable accessThis change aligns with the PR's goal of fixing static access to the
MainWP_Child_Server_Information_Base
class. The approach of using a local variable for clarity while still accessing the global directly is appropriate. The comment helps explain the design decision.
356-356
: Updated user-agent to use local variableThis correctly uses the newly defined local variable instead of directly accessing the global.
class/class-mainwp-child-back-up-buddy.php (2)
1516-1518
: Replace direct$wp_version
global with static method call.Using
MainWP_Child_Server_Information_Base::get_wordpress_version()
here centralizes version retrieval and aligns with WordPress standards. Ensure that this class is loaded (via autoloader or include) before calling it to avoid runtime errors.
3047-3051
: Pass WordPress version into Live API token method.Injecting
$wp_ver
intoITXAPI_Helper2::get_access_token()
removes the old global dependency and uses the same centralized method. Double‑check that the signature ofget_access_token()
accepts this new parameter so the token exchange continues to work.class/class-mainwp-child-stats.php (5)
108-108
: Good refactoring from global variable to static methodThis change reduces direct usage of global variables by using the centralized
MainWP_Child_Server_Information_Base::get_wordpress_version()
method to retrieve the WordPress version.
589-589
: Good refactoring from global variable to static methodConsistent with the earlier change, this replaces direct global variable access with the static method call.
596-596
: Consistent 6D40 refactoring to static methodThe change maintains consistency with other changes in this file by using the static method for WordPress version retrieval in the site info array.
634-635
: Good practice using local variableStoring the WordPress version in a local variable
$wp_ver
improves code readability and efficiency by avoiding multiple static method calls.
641-641
: Correctly updated version comparisonThe version comparison now uses the local
$wp_ver
variable instead of the global, maintaining consistency with the earlier changes.class/class-mainwp-child-updates.php (2)
1226-1227
: Correctly updated version comparison to use local variableThe version comparison logic is properly updated to use the local
$wp_ver
variable rather than the global.
1253-1254
: Consistent use of local variableThis change consistently uses the local
$wp_ver
variable throughout the function, which is a good practice.class/class-mainwp-child-wordfence.php (1)
3340-3346
: Centralize WordPress version retrievalSwitching to
MainWP_Child_Server_Information_Base::get_wordpress_version()
ensures consistent version fetching (usingwp_get_wp_version()
when available, falling back to the global variable) and aligns with the PR objective of standardizing version access across classes.class/class-mainwp-clone.php (2)
345-348
: Centralize WordPress version retrieval
Good refactor to pull the current WP version viaMainWP_Child_Server_Information_Base::get_wordpress_version()
instead of relying solely on the global. This centralizes the logic and ensures consistency with the new static method’s fallback towp_get_wp_version()
.
467-468
: Pass WordPress version in remote requests
Nice addition of the'wpversion' => MainWP_Child_Server_Information_Base::get_wordpress_version()
parameter in thefetch_url()
call. This guarantees the child endpoint always knows the correct WP version context.class/class-mainwp-child-actions.php (1)
826-831
: Switch to nativetime()
for timestamps
Replacing the helper call with PHP’s built‑intime()
simplifies the code and removes an unnecessary abstraction. This change is clear and effective.class/class-mainwp-child-updraft-plus-backups.php (2)
2247-2249
: Improved code by using a central method to get WordPress versionThe code now correctly uses
MainWP_Child_Server_Information_Base::get_wordpress_version()
instead of the global$wp_version
variable, which aligns with the PR objective to fix static access issues identified by Codacy.
2391-2392
: Consistent use of WordPress version variableThe code correctly uses the locally stored
$wp_ver
variable in the version comparison, maintaining consistency with the changes made above.
// Get WordPress version using global variable instead of static method call. | ||
global $wp_version; | ||
|
||
$wp_ver = $wp_version; |
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.
💡 Verification agent
🧩 Analysis chain
Verify consistency with other files
While this approach of directly using the global $wp_version
works, it appears inconsistent with the approach in other files that use MainWP_Child_Server_Information_Base::get_wordpress_version()
. Consider whether this inconsistency is intentional based on the specific requirements of this function.
🏁 Script executed:
#!/bin/bash
# Search for instances of both approaches to see which is more common in the codebase
echo "Files using global \$wp_version:"
rg "\$wp_version" --type php
echo -e "\nFiles using MainWP_Child_Server_Information_Base::get_wordpress_version():"
rg "MainWP_Child_Server_Information_Base::get_wordpress_version" --type php
Length of output: 1620
Use the static method for WordPress version for consistency
To align with the rest of the codebase, replace the direct use of the global $wp_version
with MainWP_Child_Server_Information_Base::get_wordpress_version()
.
• File: class/class-mainwp-child-updates.php
Lines: ~1218–1220
Diff:
- // Get WordPress version using global variable instead of static method call.
- global $wp_version;
- $wp_ver = $wp_version;
+ // Get WordPress version via the shared helper method for consistency.
+ $wp_ver = MainWP_Child_Server_Information_Base::get_wordpress_version();
📝 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.
// Get WordPress version using global variable instead of static method call. | |
global $wp_version; | |
$wp_ver = $wp_version; | |
// Get WordPress version via the shared helper method for consistency. | |
$wp_ver = MainWP_Child_Server_Information_Base::get_wordpress_version(); |
$wp_vuln = get_transient( 'mainwp_vulnche_trans_wp_json' ); | ||
// Get WordPress version using global variable instead of static method call. | ||
global $wp_version; | ||
$wp_ver = $wp_version; | ||
$number_version = str_replace( '.', '', $wp_ver ); |
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.
🛠️ Refactor suggestion
Use centralized version retrieval method
Instead of pulling in the global $wp_version
, call MainWP_Child_Server_Information_Base::get_wordpress_version()
here. This aligns with the refactoring in other classes and leverages the built‑in fallback to \wp_get_wp_version()
.
- Fix undefined variable in class-mainwp-child-actions.php - Make get_wordpress_version() public and add check for wp_get_wp_version() - Remove unnecessary include in class-mainwp-child-plugins-check.php - Remove superfluous blank line in class-mainwp-child-vulnerability-checker.php - URL-encode the version parameter in class-mainwp-child-vulnerability-checker.php - Remove unused global and unify version lookup in class-mainwp-child-actions.php - Use static method for WordPress version in class-mainwp-child-updates.php - Use centralized version retrieval method in class-mainwp-child-vulnerability-checker.php
Hi there! I wanted to let you know that we've addressed all the feedback from CodeRabbitAI in our PR at wpallstars#1. Specifically, we've:
These changes improve code consistency, security, and maintainability across the codebase. |
@coderabbitai full review |
✅ Actions performedFull review triggered. |
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: 1
♻️ Duplicate comments (2)
class/class-mainwp-child-updates.php (1)
1218-1220
: 🛠️ Refactor suggestionUse the static method for WordPress version consistency.
This approach directly uses the global
$wp_version
which is inconsistent with other files in the codebase that useMainWP_Child_Server_Information_Base::get_wordpress_version()
. For better maintainability and consistency, this should be updated.- // Get WordPress version using global variable instead of static method call. - global $wp_version; - $wp_ver = $wp_version; + // Get WordPress version via the centralized helper method. + $wp_ver = MainWP_Child_Server_Information_Base::get_wordpress_version();class/class-mainwp-child-vulnerability-checker.php (1)
311-315
: Use centralized version retrieval methodInstead of pulling in the global
$wp_version
, consider callingMainWP_Child_Server_Information_Base::get_wordpress_version()
here. This would align with the refactoring in other classes and leverage the built-in fallback to\wp_get_wp_version()
.- // Get WordPress version using global variable instead of static method call. - global $wp_version; - $wp_ver = $wp_version; + $wp_ver = MainWP_Child_Server_Information_Base::get_wordpress_version();
🧹 Nitpick comments (2)
class/class-mainwp-child-wordfence.php (1)
3340-3346
: Centralize WordPress version retrieval
Swapping out direct$wp_version
access forMainWP_Child_Server_Information_Base::get_wordpress_version()
centralizes version logic and aligns with other classes updated in this PR.Consider removing the
require_once ABSPATH . 'wp-includes/version.php'
(around line 3312), as WordPress core already loadsversion.php
andget_wordpress_version()
gracefully falls back to the global$wp_version
.class/class-mainwp-child-vulnerability-checker.php (1)
318-318
: URL-encode the version parameterThe WordPress version is being used directly in a URL. Consider URL-encoding it to ensure any special characters are properly escaped.
- $url = $this->wpvulndb_nvd_api . '?virtualMatchString=cpe:2.3:a:WordPress:WordPress:' . $wp_ver; + $url = $this->wpvulndb_nvd_api . '?virtualMatchString=cpe:2.3:a:WordPress:WordPress:' . urlencode($wp_ver);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
class/class-mainwp-child-actions.php
(3 hunks)class/class-mainwp-child-back-up-buddy.php
(2 hunks)class/class-mainwp-child-plugins-check.php
(1 hunks)class/class-mainwp-child-server-information-base.php
(2 hunks)class/class-mainwp-child-stats.php
(3 hunks)class/class-mainwp-child-updates.php
(2 hunks)class/class-mainwp-child-updraft-plus-backups.php
(2 hunks)class/class-mainwp-child-vulnerability-checker.php
(3 hunks)class/class-mainwp-child-wordfence.php
(1 hunks)class/class-mainwp-clone.php
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
class/class-mainwp-clone.php (1)
class/class-mainwp-child-server-information-base.php (1)
get_wordpress_version
(300-314)
class/class-mainwp-child-wordfence.php (1)
class/class-mainwp-child-server-information-base.php (1)
get_wordpress_version
(300-314)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (17)
class/class-mainwp-child-server-information-base.php (1)
300-313
: Excellent improvement to centralize WordPress version retrieval.This change properly centralizes the WordPress version retrieval by:
- Making the method public to allow access from other classes
- Adding forward compatibility with
\wp_get_wp_version()
function- Maintaining backward compatibility with the global
$wp_version
fallbackThis standardization will make the codebase more maintainable and follows good software engineering practices.
class/class-mainwp-child-plugins-check.php (2)
349-352
: Good use of a local variable for increased readability.Using a local variable
$wp_ver
makes the code more explicit about what value is being used in the request options, which improves code readability.
356-356
: Good update to use the local variable in the user-agent string.This change properly uses the newly defined local variable
$wp_ver
in the user-agent string, maintaining consistent code style.class/class-mainwp-child-back-up-buddy.php (2)
1516-1518
: Use centralized WordPress version retrieval
Replacing the global$wp_version
withMainWP_Child_Server_Information_Base::get_wordpress_version()
ensures a single source of truth for the WordPress version and aligns with the refactoring across the codebase.
3047-3051
: Consistent version lookup in Live setup
Great refactor to fetch the WordPress version via the public staticget_wordpress_version()
method before calling the external API. This keeps version detection consistent and testable.class/class-mainwp-child-stats.php (3)
107-108
: Good implementation of centralized version retrieval.Using the static method
MainWP_Child_Server_Information_Base::get_wordpress_version()
instead of the global variable improves code maintainability and follows the centralization pattern.
589-596
: Consistent use of centralized version retrieval.The change maintains consistency by using
MainWP_Child_Server_Information_Base::get_wordpress_version()
for both the wpversion property and within the site_info array. This approach centralizes version retrieval, making future updates easier to maintain.
634-641
: Improved version comparison approach.The change now properly retrieves the WordPress version using the centralized method and stores it in a local variable
$wp_ver
for use in comparisons. This is cleaner and more maintainable than using the global variable directly in comparisons.class/class-mainwp-child-updraft-plus-backups.php (2)
2247-2250
: Good refactoring to use centralized WordPress version retrievalThe code now uses
MainWP_Child_Server_Information_Base::get_wordpress_version()
instead of directly accessing the global$wp_version
variable. This is a better approach that centralizes version information access, improving maintainability.
2391-2392
: Properly updated version comparison to use the new variableThe version comparison logic has been correctly updated to use the new
$wp_ver
variable, maintaining the same functionality while benefiting from the centralized version retrieval method.class/class-mainwp-clone.php (2)
345-348
: Improved WordPress version retrievalThe code now uses the centralized
MainWP_Child_Server_Information_Base::get_wordpress_version()
method instead of directly accessing the WordPress version from a parameter. This approach is more maintainable and consistent with the refactoring across the codebase.
467-467
: Consistent version retrieval pattern appliedThe code now consistently uses
MainWP_Child_Server_Information_Base::get_wordpress_version()
for WordPress version retrieval in the clone backup process, improving maintainability.class/class-mainwp-child-actions.php (3)
608-618
: Improved global variable declaration with clarifying commentThe global declarations have been separated with an explanatory comment, making the code more readable and documenting the reason for using the global variable instead of a static method call.
642-646
: Consistent pattern for global variable usageSimilar to the previous change, the global declarations are separated with explanatory comments, maintaining consistency throughout the file.
826-826
: Simplified timestamp generationReplaced the helper method
MainWP_Helper::get_timestamp()
with PHP's nativetime()
function for simplicity.class/class-mainwp-child-vulnerability-checker.php (2)
293-293
: Improved code formattingAdded a blank line after JSON encoding for better readability.
327-333
: Consistent handling of WordPress versionThe code now consistently uses the local
$wp_ver
variable throughout the method, which improves maintainability.
@@ -346,17 +346,14 @@ private function try_get_response_body( $plugin, $second_pass ) { //phpcs:ignore | |||
// Get the WordPress current version to be polite in the API call. | |||
include_once ABSPATH . WPINC . '/version.php'; // NOSONAR - WP compatible. |
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.
💡 Verification agent
🧩 Analysis chain
Consider if the version.php include is still necessary.
Since you're using the global $wp_version
variable directly and not the static method, you still need this include. However, according to the PR comments, a similar include was removed in another file (class-mainwp-child-updraft-plus-backups.php
) because it switched to using the static method. For consistency across the codebase, consider whether this file should also use MainWP_Child_Server_Information_Base::get_wordpress_version()
instead.
🏁 Script executed:
#!/bin/bash
# Check if other files still include version.php or if they've moved to the static method
# Look for files that include version.php
echo "Files that include version.php:"
rg "include.*version\.php" class/
# Look for files that use the static method
echo "\nFiles that use MainWP_Child_Server_Information_Base::get_wordpress_version():"
rg "MainWP_Child_Server_Information_Base::get_wordpress_version" class/
Length of output: 2151
🏁 Script executed:
#!/bin/bash
# Find the definition of get_wordpress_version in the codebase
echo "Searching for get_wordpress_version() definition:"
rg -n "function get_wordpress_version" -n .
# Also search for the method in the specific class file
echo -e "\nInspecting MainWP_Child_Server_Information_Base class:"
rg -n "class MainWP_Child_Server_Information_Base" -n -A5
rg -n "get_wordpress_version" -n -A5
Length of output: 9432
Refactor class-mainwp-child-plugins-check.php
to use the static version helper
We’ve confirmed that:
- Other classes (Wordfence, Updraft‑Plus, Themes Check) still include
version.php
even after switching toMainWP_Child_Server_Information_Base::get_wordpress_version()
. - This file currently pulls in
version.php
and uses the global$wp_version
directly.
For consistency, update this file to call the static method and keep the include:
• File: class/class-mainwp-child-plugins-check.php
– Keep the existing
php include_once ABSPATH . WPINC . '/version.php'; // NOSONAR - WP compatible.
– Replace any direct references to $wp_version
with:
diff - global $wp_version; - $current_version = $wp_version; + $current_version = MainWP_Child_Server_Information_Base::get_wordpress_version();
Hi @marcusquinn, thanks for the PR. It looks like there are some problems with this PR. It includes rollback changes for tweaks that we introduced in last update for getting the WP version number. For example, Can you please review this Pull Request? |
Hi @marcusquinn, just a quick follow-up on this PR. |
All Submissions:
Changes proposed in this Pull Request:
This PR fixes code review issues identified by Codacy in PR #456, specifically addressing the static access to the
MainWP_Child_Server_Information_Base
class. Instead of using static method calls toget_wordpress_version()
, the code now uses the global$wp_version
variable directly, which is the standard WordPress approach.Files modified:
class/class-mainwp-child-plugins-check.php
class/class-mainwp-child-updates.php
class/class-mainwp-child-vulnerability-checker.php
class/class-mainwp-child-actions.php
(two instances)These changes maintain the same functionality while following better coding practices and WordPress standards.
How to test the changes in this Pull Request:
Other information:
Changelog entry
Summary by CodeRabbit